WIP lsp-manager effort 3

This commit is contained in:
itdominator 2025-07-12 01:45:02 -05:00
parent f463970b6b
commit f8d9c3f31b
8 changed files with 179 additions and 82 deletions

View File

@ -8,14 +8,15 @@
"command": "lsp-ws-proxy --listen 4114 -- jdtls",
"alt-command": "lsp-ws-proxy -- jdtls",
"alt-command2": "java-language-server",
"socket": "ws://127.0.0.1:4114/?name=jdtls",
"alt-socket": "ws://127.0.0.1:3030/?name=java-language-server",
"socket": "ws://127.0.0.1:4114/java",
"socket-two": "ws://127.0.0.1:4114/?name=jdtls",
"alt-socket": "ws://127.0.0.1:9999/?name=java-language-server",
"initialization-options": {
"bundles": [
"intellicode-core.jar"
],
"workspaceFolders": [
"file://"
"file://{workspace.folder}"
],
"extendedClientCapabilities": {
"classFileContentsSupport": true,
@ -150,7 +151,8 @@
"alt-command": "pylsp",
"alt-command2": "lsp-ws-proxy --listen 4114 -- pylsp",
"alt-command3": "pylsp --ws --port 4114",
"socket": "ws://127.0.0.1:9999/?name=pylsp",
"socket": "ws://127.0.0.1:9999/python",
"socket-two": "ws://127.0.0.1:9999/?name=pylsp",
"initialization-options": {
"pyls": {
"plugins": {
@ -215,7 +217,7 @@
"extra_paths": [
"{user.home}/Portable_Apps/py-venvs/pylsp-venv/venv/lib/python3.10/site-packages"
],
"root_dir": ""
"root_dir": "file://{workspace.folder}"
}
}
}
@ -226,7 +228,8 @@
"info": "https://pypi.org/project/jedi-language-server/",
"command": "jedi-language-server",
"alt-command": "lsp-ws-proxy --listen 3030 -- jedi-language-server",
"socket": "ws://127.0.0.1:3030/?name=jedi-language-server",
"socket": "ws://127.0.0.1:9999/python",
"socket-two": "ws://127.0.0.1:9999/?name=jedi-language-server",
"initialization-options": {
"jediSettings": {
"autoImportModules": [],
@ -255,28 +258,8 @@
"info": "https://clangd.llvm.org/",
"command": "lsp-ws-proxy -- clangd",
"alt-command": "clangd",
"socket": "ws://127.0.0.1:3030/?name=clangd",
"initialization-options": {}
},
"sh": {
"info": "",
"command": "",
"alt-command": "",
"socket": "ws://127.0.0.1:3030/?name=shell",
"initialization-options": {}
},
"go": {
"info": "https://pkg.go.dev/golang.org/x/tools/gopls#section-readme",
"command": "lsp-ws-proxy -- gopls",
"alt-command": "gopls",
"socket": "ws://127.0.0.1:3030/?name=gopls",
"initialization-options": {}
},
"lua": {
"info": "https://github.com/LuaLS/lua-language-server",
"command": "lsp-ws-proxy -- lua-language-server",
"alt-command": "lua-language-server",
"socket": "ws://127.0.0.1:3030/?name=gopls",
"socket": "ws://127.0.0.1:9999/cpp",
"socket-two": "ws://127.0.0.1:9999/?name=clangd",
"initialization-options": {}
},
"c": {
@ -284,7 +267,40 @@
"info": "https://clangd.llvm.org/",
"command": "lsp-ws-proxy -- clangd",
"alt-command": "clangd",
"socket": "ws://127.0.0.1:3030/?name=clangd",
"socket": "ws://127.0.0.1:9999/c",
"socket-two": "ws://127.0.0.1:9999/?name=clangd",
"initialization-options": {}
},
"go": {
"info": "https://pkg.go.dev/golang.org/x/tools/gopls#section-readme",
"command": "lsp-ws-proxy -- gopls",
"alt-command": "gopls",
"socket": "ws://127.0.0.1:9999/go",
"socket-two": "ws://127.0.0.1:9999/?name=gopls",
"initialization-options": {}
},
"typescript": {
"info": "https://github.com/typescript-language-server/typescript-language-server",
"command": "lsp-ws-proxy -- typescript-language-server",
"alt-command": "typescript-language-server --stdio",
"socket": "ws://127.0.0.1:9999/typescript",
"socket-two": "ws://127.0.0.1:9999/?name=ts",
"initialization-options": {}
},
"sh": {
"info": "",
"command": "",
"alt-command": "",
"socket": "ws://127.0.0.1:9999/bash",
"socket-two": "ws://127.0.0.1:9999/?name=shell",
"initialization-options": {}
},
"lua": {
"info": "https://github.com/LuaLS/lua-language-server",
"command": "lsp-ws-proxy -- lua-language-server",
"alt-command": "lua-language-server",
"socket": "ws://127.0.0.1:9999/lua",
"socket-two": "ws://127.0.0.1:9999/?name=lua",
"initialization-options": {}
}
}

View File

@ -31,7 +31,7 @@ export class PaneHandleDirective {
!target.classList.contains("hr-pane-handle") &&
!target.classList.contains("vr-pane-handle")
) {
console.log("Must have 'hr-pane-handle' or 'vr-pane-handle' in classList!");
console.error("Must have 'hr-pane-handle' or 'vr-pane-handle' in classList!");
return;
}

View File

@ -14,9 +14,9 @@ import { ServiceMessage } from '../../../types/service-message.type';
export class LspManagerService {
private messageSubject: ReplaySubject<ServiceMessage> = new ReplaySubject<ServiceMessage>(1);
lspConfigData!: {};
languageProviders: {} = {};
workspaceFolder: string = "";
workspaceFolder: string = "";
lspConfigDataStr: string = "";
languageProviders: {} = {};
constructor() {
@ -25,55 +25,79 @@ export class LspManagerService {
public loadLspConfigData(): Promise<string | void> {
return this.getLspConfigData().then((lspConfigData: string) => {
this.lspConfigData = JSON.parse(lspConfigData);
if (this.lspConfigData["message"]) {
console.log(
"Warning: LSP this.lspConfigData is a 'message'",
this.lspConfigData
);
this.lspConfigData = {};
}
this.lspConfigDataStr = lspConfigData;
return lspConfigData;
});
}
public registerEditor(editor: any): void {
let modeParts = editor.session.getMode()["$Id"].split("/");
let mode = modeParts[ modeParts.length - 1 ];
public registerEditorToLSPClient(editor: any): void {
let mode = this.getMode(editor.session);
if ( !this.languageProviders[mode] ) {
this.languageProviders[mode] = this.getLanguageProviderWithClientServer(mode);
if ( this.languageProviders[mode] ) {
this.languageProviders[mode].registerEditor(editor);
return;
}
this.languageProviders[mode].registerEditor(editor);
this.languageProviders[mode]?.registerEditor(editor);
}
private getLspConfigData(): Promise<string> {
return window.fs.getLspConfigData();
}
private getLanguageProviderWithClientServer(mode: string) {
let _initializationOptions = {};
private parseAndReturnLSPConfigData() {
let configData = JSON.parse(
this.lspConfigDataStr.replaceAll("{workspace.folder}", this.workspaceFolder)
);
if ( Object.keys(this.lspConfigData).length !== 0 && this.lspConfigData[mode] ) {
_initializationOptions = this.lspConfigData[mode]["initialization-options"];
if (configData["message"]) {
console.warn(
"Warning: LSP this.lspConfigDataStr is a 'message'",
this.lspConfigDataStr
);
configData = {};
}
let servers: LanguageClientConfig[] = [
{
module: () => import("ace-linters/build/language-client"),
modes: mode,
type: "socket",
socket: new WebSocket(`ws://127.0.0.1:9999/${mode}`),
// socket: new WebSocket("ws://127.0.0.1:9999/?name=pylsp"),
initializationOptions: _initializationOptions
}
];
return configData;
}
return AceLanguageClient.for(servers);
private getInitializationOptions(mode: string, configData: {}) {
let _initializationOptions = {};
if ( Object.keys(configData).length !== 0 && configData[mode] ) {
_initializationOptions = configData[mode]["initialization-options"];
}
return _initializationOptions;
}
public createLanguageProviderWithClientServer(mode: string) {
if ( this.languageProviders[mode] ) return;
let servers: LanguageClientConfig[] = [];
try {
let configData = this.parseAndReturnLSPConfigData();
let _initializationOptions = this.getInitializationOptions(mode, configData);
servers = [
{
module: () => import("ace-linters/build/language-client"),
modes: mode,
type: "socket",
socket: new WebSocket( configData[mode]["socket"] ),
initializationOptions: _initializationOptions
}
];
} catch(error) {
console.error(
"Error: Language Server could not be loaded OR doesn't exist in Newton-LSP config setup...",
);
return;
}
this.languageProviders[mode] = AceLanguageClient.for(servers);
return this.languageProviders[mode];
}
private getLanguageProviderWithWebWorker() {
@ -81,16 +105,20 @@ export class LspManagerService {
return LanguageProvider.create(worker);
}
protected setSessionFilePath(session: any, filePath: string = "") {
public setSessionFilePath(session: any, filePath: string = "") {
if ( !session || !filePath ) return;
let mode = session.getMode()["$Id"];
let mode = this.getMode(session);
if ( !this.languageProviders[mode] ) return;
this.languageProviders[mode].setSessionFilePath(session, filePath);
}
protected closeDocument(session: any) {
public getMode(session: any) {
return session.getMode()["$id"].replace("ace/mode/", "");
}
public closeDocument(session: any) {
if ( !session ) return;
let mode = session.getMode()["$Id"];
let mode = this.getMode(session);
if ( !this.languageProviders[mode] ) return;
this.languageProviders[mode].closeDocument(session);
}

View File

@ -62,6 +62,7 @@ export class FilesService {
): Promise<NewtonFile | undefined | null> {
for (let i = 0; i < files.length; i++) {
const file = files[i];
// const path = window.fs.getPathForFile(file).replace("file://", "");
const path = window.fs.getPathForFile(file);
if (!file || !path) continue;
@ -95,7 +96,7 @@ export class FilesService {
this.files.set(file.path, file);
} catch (error) {
console.log(
console.error(
`---- Error ----\nPath: ${path}\nMessage: ${error}`
);
}

View File

@ -178,6 +178,11 @@ export class CodeViewBase {
}
public closeFile() {
let message = new ServiceMessage();
message.action = "close-file";
message.rawData = this.editor.getSession();
this.lspManagerService.sendMessage(message);
this.tabsService.closeTab(this.activeFile.path);
}

View File

@ -128,11 +128,11 @@ export class CodeViewComponent extends CodeViewBase {
this.editorsService.sendMessage(message);
this.searchReplaceService.sendMessage(message);
this.lspManagerService.sendMessage(message);
message = new ServiceMessage();
message.action = "set-active-editor";
message.rawData = this;
this.lspManagerService.sendMessage(message);
this.markdownPreviewService.sendMessage(message);
this.updateInfoBar();
@ -176,8 +176,8 @@ export class CodeViewComponent extends CodeViewBase {
this.editor.on("changeSession", (session) => {
let message = new ServiceMessage();
message.action = "set-active-editor";
message.rawData = this.editor;
message.action = "editor-update";
message.rawData = this;
this.lspManagerService.sendMessage(message);

View File

@ -2,6 +2,10 @@
<div class="row mt-2 mb-3">
<div class="col col-auto">
<button class="btn btn-sm btn-dark" (click)="createLanguageClient()">Create Language Client</button>
</div>
<div class="col clear-right-padding">
<div class="input-group-sm">
<label class="form-control" [innerText]="lspManagerService.workspaceFolder || 'Project Path...'">
@ -36,7 +40,13 @@
<div class="row mt-2 md-2">
<div class="col">
Target Editor: <label [innerText]="editor?.id || 'Editor...'"></label>
Target Editor: <label [innerText]="editor?.id || '...'"></label>
</div>
<div class="col-sm">
<button class="btn btn-sm btn-dark"
(click)="registerEditorToLanguageClient()">
Register Editor To LSP
</button>
</div>
<div class="col">
Active Editor Session:

View File

@ -34,6 +34,7 @@ export class LspManagerComponent {
lspTextEditor: any;
innerEditor: any;
editor: any;
activeFile: any;
@ -43,6 +44,16 @@ export class LspManagerComponent {
private ngAfterViewInit(): void {
this.mapEditorsAndLoadConfig();
this.loadSubscribers();
}
private ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
private mapEditorsAndLoadConfig() {
this.lspTextEditor = this.lspEditorComponent.editor;
this.innerEditor = this.sessionEditorComponent.editor;
@ -50,13 +61,6 @@ export class LspManagerComponent {
this.lspTextEditor.session.setMode("ace/mode/json");
this.lspTextEditor.session.setValue(lspConfigData);
});
this.loadSubscribers();
}
private ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
private loadSubscribers() {
@ -67,6 +71,10 @@ export class LspManagerComponent {
this.toggleLspManager(message);
} else if (message.action === "set-active-editor") {
this.setActiveEditor(message);
} else if (message.action === "editor-update") {
this.editorUpdate(message);
} else if (message.action === "close-file") {
this.closeFile(message);
}
});
}
@ -83,6 +91,19 @@ export class LspManagerComponent {
});
}
public createLanguageClient() {
let mode = this.lspManagerService.getMode(this.editor.session);
this.lspManagerService.createLanguageProviderWithClientServer(mode);
}
public registerEditorToLanguageClient() {
this.lspManagerService.registerEditorToLSPClient(this.editor);
this.lspManagerService.setSessionFilePath(
this.editor.session,
this.activeFile.path
);
}
public globalLspManagerKeyHandler(event: any) {
@ -108,10 +129,26 @@ export class LspManagerComponent {
}
private setActiveEditor(message: ServiceMessage) {
this.editor = message.rawData;
this.editor = message.rawData.editor;
this.activeFile = message.rawData.activeFile;
// TODO: figure out why this doesn't update the session consistently...
// It seems maybe bound to visible state as change detector ref didn't help either.
// this.innerEditor.setSession(this.editor.session);
}
private editorUpdate(message: ServiceMessage) {
this.editor.setSession(message.rawData.editor.getSession())
this.activeFile = message.rawData.activeFile;
this.lspManagerService.setSessionFilePath(
this.editor.session,
this.activeFile.path
);
}
private closeFile(message: ServiceMessage) {
this.lspManagerService.closeDocument(message.rawData);
}
}