From c268a7ef1a4fd16af512cbc0ca457783b8f18154 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Tue, 26 Mar 2024 22:19:01 -0500 Subject: [PATCH] Capped const variables; loading config and socket from config --- .../usr/share/newton/context_path/index.html | 2 +- .../context_path/resources/js/newton/ajax.js | 12 ++-- .../resources/js/newton/events.js | 14 ++-- .../resources/js/newton/globals.js | 10 ++- .../resources/js/newton/lsp-manager.js | 67 ++++++------------- .../resources/js/newton/ui-logic.js | 4 +- 6 files changed, 43 insertions(+), 66 deletions(-) diff --git a/user_config/usr/share/newton/context_path/index.html b/user_config/usr/share/newton/context_path/index.html index a47b8e1..53890fc 100644 --- a/user_config/usr/share/newton/context_path/index.html +++ b/user_config/usr/share/newton/context_path/index.html @@ -105,13 +105,13 @@ - + 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 4045703..99d493e 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 @@ -31,9 +31,9 @@ const doAjax = (actionPath, data, action) => { const formatURL = (basePath) => { url = window.location.href; if ( url.endsWith('/') ) - return url + basePath; + return `${url}${basePath}`; else - return url + '/' + basePath; + return `${url}/${basePath}`; } const fetchData = async (url) => { @@ -117,6 +117,10 @@ const importScriptFromScriptStr = async (scriptStr) => { } const importScriptFromBackendResponse = async (scriptName, dataStr) => { - backendResponse = atob(dataStr); - scriptBlobURLs[scriptName] = await importScriptFromScriptStr(backendResponse); + scriptStr = atob(dataStr); + SCRIPT_BLOB_URLs[scriptName] = await importScriptFromScriptStr(scriptStr); + + if (scriptName === "lsp_servers_config.json") { + lspServersConfig = JSON.parse(scriptStr); + } } \ No newline at end of file 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 0bf366d..a5a8c9e 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 @@ -13,16 +13,14 @@ 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 = ""); - sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/language-client.js`, content = ""); + sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = LSP_SERVER_CONFG, content = ""); + sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${BASE_LINK}/ace-linters.js`, content = ""); + sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${BASE_LINK}/base-service.js`, content = ""); + sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${BASE_LINK}/service-manager.js`, content = ""); + sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${BASE_LINK}/language-client.js`, content = ""); // Note: If using builtin services tghan connecting to a socket. - // sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${baseLink}/python-service.js`, content = ""); + // sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${BASE_LINK}/python-service.js`, content = ""); } window.onerror = function(msg, url, line, col, error) { 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 85b0367..c05066c 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 @@ -2,7 +2,7 @@ const messenger = (window.webkit) ? window.webkit.messageHandlers : (message) = console.log("Message: " + message); }; -const editorOpts = { +const EDITOR_OPTS = { printMarginColumn: 80, enableBasicAutocompletion: true, enableInlineAutocompletion: true, @@ -17,9 +17,13 @@ const editorOpts = { mergeUndoDeltas: false } -const scriptBlobURLs = {}; -const baseLSPLink = "http://0.0.0.0:4880"; +const BASE_LINK = `${window.location.href}resources/js/libs/ace_editor/lsp`; +const LSP_SERVER_CONFG = `${window.location.href}../lsp_servers_config.json`; +const BASE_LSP_LINK = "http://0.0.0.0:4880"; + +const SCRIPT_BLOB_URLs = {}; let lspProvider = null; +let lspServersConfig = null; let editor = null; 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 index cc5c708..1f66d0f 100644 --- 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 @@ -1,60 +1,36 @@ /* Works but isn't websocket */ // manager.registerService("python", { // module: () => { -// importScripts( "${ scriptBlobURLs["python-service.js"] }" ); +// importScripts( "${ SCRIPT_BLOB_URLs["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( + importJavaScriptFileFromBlobURL( SCRIPT_BLOB_URLs["ace-linters.js"] ).then( async () => { let workerString = ` !function () { - importScripts( "${ scriptBlobURLs["service-manager.js"] }" ); + importScripts( "${ SCRIPT_BLOB_URLs["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" - ] + manager.registerServer( + "python", { + module: () => { + importScripts( "${ SCRIPT_BLOB_URLs["language-client.js"] }" ); + return {LanguageClient}; + }, + modes: "python|python3", + type: "socket", // "socket|worker" + socket: new WebSocket( "${ lspServersConfig['python']['socket'] }" ), + initializationOptions: ${ JSON.stringify( lspServersConfig['python']['initialization_options'] ) } } - }); + ); }() `; @@ -75,28 +51,23 @@ const loadPythonLSPFromBlobURLs = () => { const loadPythonLSPFromNetwork = () => { - importJavaScriptFile(baseLSPLink + "/ace-linters.js").then( + importJavaScriptFile(BASE_LSP_LINK + "/ace-linters.js").then( async () => { let workerString = ` !function () { - importScripts("${await importScriptFromNetwork(baseLSPLink + "/service-manager.js")}"); + importScripts("${await importScriptFromNetwork(BASE_LSP_LINK + "/service-manager.js")}"); let manager = new ServiceManager(self); /* Works and is websocket */ manager.registerServer("python", { module: () => { - importScripts("${await importScriptFromNetwork(baseLSPLink + "/language-client.js")}"); + importScripts("${await importScriptFromNetwork(BASE_LSP_LINK + "/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" - ] - } + socket: new WebSocket( "${ lspServersConfig['python']['socket'] }" ), + initializationOptions: ${ JSON.stringify( lspServersConfig['python']['initialization_options'] ) } }); }() `; 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 104366a..a25bcfb 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 @@ -3,7 +3,7 @@ const loadPreviewEditor = () => { previewEditor = ace.edit("preview-editor"); // Note: https://github.com/ajaxorg/ace/wiki/Configuring-Ace - previewEditor.setOptions(editorOpts); + previewEditor.setOptions(EDITOR_OPTS); // Note: https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts previewEditor.commands.addCommands(editorCommands); @@ -18,7 +18,7 @@ const loadEditor = () => { editor = ace.edit("editor"); // Note: https://github.com/ajaxorg/ace/wiki/Configuring-Ace - editor.setOptions(editorOpts); + editor.setOptions(EDITOR_OPTS); // Note: https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts editor.commands.addCommands(editorCommands);