diff --git a/public/lsp-servers-config.json b/public/lsp-servers-config.json index 6f1506b..868a487 100644 --- a/public/lsp-servers-config.json +++ b/public/lsp-servers-config.json @@ -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": {} } } \ No newline at end of file diff --git a/src/app/common/directives/pane-handle.directive.ts b/src/app/common/directives/pane-handle.directive.ts index 39c9b0d..dcc4865 100644 --- a/src/app/common/directives/pane-handle.directive.ts +++ b/src/app/common/directives/pane-handle.directive.ts @@ -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; } diff --git a/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts b/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts index 97b41e3..7f61459 100644 --- a/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts +++ b/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts @@ -14,9 +14,9 @@ import { ServiceMessage } from '../../../types/service-message.type'; export class LspManagerService { private messageSubject: ReplaySubject = new ReplaySubject(1); - lspConfigData!: {}; - languageProviders: {} = {}; - workspaceFolder: string = ""; + workspaceFolder: string = ""; + lspConfigDataStr: string = ""; + languageProviders: {} = {}; constructor() { @@ -25,55 +25,79 @@ export class LspManagerService { public loadLspConfigData(): Promise { 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 { 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); } diff --git a/src/app/common/services/files.service.ts b/src/app/common/services/files.service.ts index ea2997e..ba05b60 100644 --- a/src/app/common/services/files.service.ts +++ b/src/app/common/services/files.service.ts @@ -62,6 +62,7 @@ export class FilesService { ): Promise { 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}` ); } diff --git a/src/app/editor/code-view/view.base.ts b/src/app/editor/code-view/view.base.ts index 4b41fc6..7968d19 100644 --- a/src/app/editor/code-view/view.base.ts +++ b/src/app/editor/code-view/view.base.ts @@ -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); } diff --git a/src/app/editor/code-view/view.component.ts b/src/app/editor/code-view/view.component.ts index 77e08a6..8f00c35 100644 --- a/src/app/editor/code-view/view.component.ts +++ b/src/app/editor/code-view/view.component.ts @@ -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); diff --git a/src/app/editor/lsp-manager/lsp-manager.component.html b/src/app/editor/lsp-manager/lsp-manager.component.html index 0bc2aaa..a71df26 100644 --- a/src/app/editor/lsp-manager/lsp-manager.component.html +++ b/src/app/editor/lsp-manager/lsp-manager.component.html @@ -2,6 +2,10 @@
+
+ +
+