From 7bec522a3131ed623aef9f50056a4e2b4b12b8a5 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 25 Mar 2024 21:45:44 -0500 Subject: [PATCH] Added lsp-manager js file; updated lsp config --- .../usr/share/newton/context_path/index.html | 32 +++++ .../context_path/resources/js/newton/ajax.js | 3 +- .../resources/js/newton/events.js | 1 + .../resources/js/newton/globals.js | 5 +- .../resources/js/newton/keybinding-newton.js | 8 ++ .../resources/js/newton/lsp-manager.js | 117 ++++++++++++++++++ .../resources/js/newton/ui-logic.js | 62 +--------- .../usr/share/newton/lsp_servers_config.json | 20 ++- 8 files changed, 180 insertions(+), 68 deletions(-) create mode 100644 user_config/usr/share/newton/context_path/resources/js/newton/lsp-manager.js diff --git a/user_config/usr/share/newton/context_path/index.html b/user_config/usr/share/newton/context_path/index.html index 3b42269..a47b8e1 100644 --- a/user_config/usr/share/newton/context_path/index.html +++ b/user_config/usr/share/newton/context_path/index.html @@ -55,6 +55,37 @@ + + + + + + @@ -74,6 +105,7 @@ + diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js b/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js index 0bbf39b..4045703 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/ajax.js @@ -101,8 +101,7 @@ const importJavaScriptFileFromBlobURL = async (objectURL) => { // Add a listener to revoke the object URL when the script has loaded. scriptElement.addEventListener("load", () => { - console.log("Loaded script..."); - // URL.revokeObjectURL(objectURL); + URL.revokeObjectURL(objectURL); }); // Append the script element to the document to execute the JavaScript code. diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/events.js b/user_config/usr/share/newton/context_path/resources/js/newton/events.js index 9c8b057..0bf366d 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/events.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/events.js @@ -15,6 +15,7 @@ window.onload = (eve) => { const loadLSPClientJSFiles = () => { const baseLink = `${window.location.href}resources/js/libs/ace_editor/lsp`; + sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/../lsp_servers_config.json`, content = ""); sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/ace-linters.js`, content = ""); sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/base-service.js`, content = ""); sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/service-manager.js`, content = ""); diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/globals.js b/user_config/usr/share/newton/context_path/resources/js/newton/globals.js index f4c6e4d..85b0367 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/globals.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/globals.js @@ -18,6 +18,9 @@ const editorOpts = { } const scriptBlobURLs = {}; +const baseLSPLink = "http://0.0.0.0:4880"; +let lspProvider = null; + let editor = null; let previewEditor = null; @@ -27,4 +30,4 @@ let previewSel = null; let fontSize = 12; let highlightLine = true; let isControlDown = false; -let queryMarkers = []; \ No newline at end of file +let queryMarkers = []; diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js b/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js index 2e72570..e7f571a 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/keybinding-newton.js @@ -17,6 +17,14 @@ const editorCommands = [ editor.showKeyboardShortcuts(); }) } + + + }, { + name: "showLSPManager", + bindKey: {win: "ctrl-m", mac: "command-m"}, + exec: function(editor) { + $('#lsp-modal').modal("toggle"); + } }, { name: "search", bindKey: {win: "ctrl-f", mac: "ctrl-f"}, diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/lsp-manager.js b/user_config/usr/share/newton/context_path/resources/js/newton/lsp-manager.js new file mode 100644 index 0000000..cc5c708 --- /dev/null +++ b/user_config/usr/share/newton/context_path/resources/js/newton/lsp-manager.js @@ -0,0 +1,117 @@ +/* Works but isn't websocket */ +// manager.registerService("python", { +// module: () => { +// importScripts( "${ scriptBlobURLs["python-service.js"] }" ); +// return {PythonService}; +// }, +// className: "PythonService", +// modes: "python|python3", +// }); + +// importScripts("${await importScriptFromNetwork(baseLink + "/service-manager.js")}"); +// importScripts("${await importScriptFromNetwork(baseLink + "/python-service.js")}"); +// importScripts("${await importScriptFromNetwork(baseLink + "/language-client.js")}"); + + + +// initializationOptions: { +// "pylsp.plugins.rope_autoimport.enabled": true, +// "pylsp.plugins.rope_completion.enabled": true, +// "pylsp.plugins.rope_completion.eager": true, +// "pylsp.plugins.jedi_completion.fuzzy": true, +// "pylsp.plugins.jedi.extra_paths": [ +// "/home/abaddon/Portable_Apps/py-venvs/flask-apps-venv/venv/lib/python3.10/site-packages", +// "/home/abaddon/Portable_Apps/py-venvs/gtk-apps-venv/venv/lib/python3.10/site-packages/gi" +// ] +// } + +// "/home/abaddon/Portable_Apps/py-venvs/flask-apps-venv/venv/lib/python3.10/site-packages" + + +const loadPythonLSPFromBlobURLs = () => { + importJavaScriptFileFromBlobURL( scriptBlobURLs["ace-linters.js"] ).then( + async () => { + let workerString = ` + !function () { + importScripts( "${ scriptBlobURLs["service-manager.js"] }" ); + let manager = new ServiceManager(self); + + /* Works and is websocket */ + manager.registerServer("python", { + module: () => { + importScripts( "${ scriptBlobURLs["language-client.js"] }" ); + return {LanguageClient}; + }, + modes: "python|python3", + type: "socket", // "socket|worker" + socket: new WebSocket("ws://127.0.0.1:3030/python"), + initializationOptions: { + "pylsp.plugins.rope_autoimport.enabled": true, + "pylsp.plugins.rope_completion.enabled": true, + "pylsp.plugins.rope_completion.eager": true, + "pylsp.plugins.jedi_completion.fuzzy": true, + "pylsp.plugins.jedi.extra_paths": [ + "/home/abaddon/Portable_Apps/py-venvs/lsp_bridge-venv/venv/lib/python3.10/site-packages/gi-stubs" + ] + } + }); + }() + `; + + let worker = new Worker( + createBlobURL( + createScriptBlob(workerString) + ) + ); + + lspProvider = LanguageProvider.create(worker); + lspProvider.registerEditor(editor); + } + ).catch((e) => { + console.log(e); + }); + +} + + +const loadPythonLSPFromNetwork = () => { + importJavaScriptFile(baseLSPLink + "/ace-linters.js").then( + async () => { + let workerString = ` + !function () { + importScripts("${await importScriptFromNetwork(baseLSPLink + "/service-manager.js")}"); + let manager = new ServiceManager(self); + + /* Works and is websocket */ + manager.registerServer("python", { + module: () => { + importScripts("${await importScriptFromNetwork(baseLSPLink + "/language-client.js")}"); + return {LanguageClient}; + }, + modes: "python|python3", + type: "socket", // "socket|worker" + socket: new WebSocket("ws://127.0.0.1:3030/python"), + initializationOptions: { + "pylsp.plugins.jedi.extra_paths": [ + "/home/abaddon/Portable_Apps/py-venvs/flask-apps-venv/venv/lib/python3.10/site-packages", + "/home/abaddon/Portable_Apps/py-venvs/gtk-apps-venv/venv/lib/python3.10/site-packages/gi" + ] + } + }); + }() + `; + + let worker = new Worker( + createBlobURL( + createScriptBlob(workerString) + ) + ); + + lspProvider = LanguageProvider.create(worker); + lspProvider.registerEditor(editor); + } + ).catch((e) => { + console.log(e); + }); + +} diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js index 814e508..104366a 100644 --- a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js +++ b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js @@ -28,6 +28,7 @@ const loadEditor = () => { editor.addEventListener("click", (eve) => { setLabels(); }); + } const loadInitialSession = () => { @@ -64,66 +65,6 @@ const setSession = async (ftype, fhash, session) => { if (ftype !== "buffer") { editor.session.setMode("ace/mode/" + ftype); - - if (ftype === "python") { - // const baseLink = "http://0.0.0.0:4880"; - - // importJavaScriptFile(baseLink + "/ace-linters.js").then( - importJavaScriptFileFromBlobURL( scriptBlobURLs["ace-linters.js"] ).then( - async () => { - /* Works but isn't websocket */ - // manager.registerService("python", { - // module: () => { - // importScripts( "${ scriptBlobURLs["python-service.js"] }" ); - // return {PythonService}; - // }, - // className: "PythonService", - // modes: "python|python3", - // }); - - // importScripts("${await importScriptFromNetwork(baseLink + "/service-manager.js")}"); - // importScripts("${await importScriptFromNetwork(baseLink + "/python-service.js")}"); - // importScripts("${await importScriptFromNetwork(baseLink + "/language-client.js")}"); - let workerString = ` - !function () { - importScripts( "${ scriptBlobURLs["service-manager.js"] }" ); - let manager = new ServiceManager(self); - - /* Works and is websocket */ - manager.registerServer("python", { - module: () => { - importScripts( "${ scriptBlobURLs["language-client.js"] }" ); - return {LanguageClient}; - }, - modes: "python|python3", - type: "socket", // "socket|worker" - socket: new WebSocket("ws://127.0.0.1:3030/python"), - initializationOptions: { - "pylsp.plugins.jedi.extra_paths": [ - "/home/abaddon/Portable_Apps/py-venvs/flask-apps-venv/venv/lib/python3.10/site-packages", - "/home/abaddon/Portable_Apps/py-venvs/gtk-apps-venv/venv/lib/python3.10/site-packages/gi" - ] - } - }); - - }() - `; - - let worker = new Worker( - createBlobURL( - createScriptBlob(workerString) - ) - ); - - let provider = LanguageProvider.create(worker); - provider.registerEditor(editor); - - } - ).catch((e) => { - console.log(e); - }); - - } } setLabels(); @@ -168,6 +109,7 @@ const loadFile = (ftype, fname, fpath, content, line = 0) => { aceSessions[fhash] = {"ftype": ftype, "fname": fname, "fpath": fpath, "session": session}; setSession(ftype, fhash, session); + sendMessage("load_file", ftype, fhash, fpath, fname); } diff --git a/user_config/usr/share/newton/lsp_servers_config.json b/user_config/usr/share/newton/lsp_servers_config.json index 7badb9a..05772c0 100644 --- a/user_config/usr/share/newton/lsp_servers_config.json +++ b/user_config/usr/share/newton/lsp_servers_config.json @@ -6,12 +6,22 @@ }, "python": { "info": "https://github.com/python-lsp/python-lsp-server", - "command": ["pylsp"], - "initialization_options": {} + "command": "pylsp --ws --port 3030", + "socket": "ws://127.0.0.1:3030/python", + "initialization_options": { + "pylsp.plugins.rope_autoimport.enabled": true, + "pylsp.plugins.rope_completion.enabled": true, + "pylsp.plugins.rope_completion.eager": true, + "pylsp.plugins.jedi_completion.fuzzy": true, + "pylsp.plugins.jedi.extra_paths": [ + "/home/abaddon/Portable_Apps/py-venvs/lsp_bridge-venv/venv/lib/python3.10/site-packages/gi-stubs" + ] + } }, "python3": { "info": "https://pypi.org/project/jedi-language-server/", - "command": ["jedi-language-server"], + "command": "jedi-language-server", + "socket": "ws://127.0.0.1:3030/python", "initialization_options": { "jediSettings": { "autoImportModules": [], @@ -25,8 +35,8 @@ }, "markupKindPreferred": "markdown", "workspace": { - "extraPaths": [], - "environmentPath": "/path/to/venv/bin/python", + "extraPaths": ["/home/abaddon/Portable_Apps/py-venvs/gtk-apps-venv/venv/lib/python3.10/site-packages/gi"], + "environmentPath": "/home/abaddon/Portable_Apps/py-venvs/gtk-apps-venv/venv/bin/python", "symbols": { "ignoreFolders": [".nox", ".tox", ".venv", "__pycache__", "venv"], "maxSymbols": 20