From 14100b09e31e96eee40cd603655f64b3224414ec Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Thu, 28 Mar 2024 01:06:53 -0500 Subject: [PATCH] Effort on LSP settings UI --- .../usr/share/newton/context_path/index.html | 48 ++++++++-- .../context_path/resources/js/newton/ajax.js | 4 +- .../resources/js/newton/components.js | 87 +++++++++++++++++++ .../resources/js/newton/events.js | 8 ++ .../resources/js/newton/globals.js | 7 +- .../resources/js/newton/lsp-manager.js | 70 +++++++++++++++ ...rs_config.json => lsp-servers-config.json} | 12 ++- 7 files changed, 221 insertions(+), 15 deletions(-) create mode 100644 user_config/usr/share/newton/context_path/resources/js/newton/components.js rename user_config/usr/share/newton/{lsp_servers_config.json => lsp-servers-config.json} (86%) diff --git a/user_config/usr/share/newton/context_path/index.html b/user_config/usr/share/newton/context_path/index.html index 53890fc..24c201b 100644 --- a/user_config/usr/share/newton/context_path/index.html +++ b/user_config/usr/share/newton/context_path/index.html @@ -63,21 +63,19 @@

LSPs:

- @@ -86,6 +84,41 @@ + + + + + + @@ -111,6 +144,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 99d493e..328238b 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 @@ -120,7 +120,9 @@ const importScriptFromBackendResponse = async (scriptName, dataStr) => { scriptStr = atob(dataStr); SCRIPT_BLOB_URLs[scriptName] = await importScriptFromScriptStr(scriptStr); - if (scriptName === "lsp_servers_config.json") { + // TODO: Look to move this out of here as soon as can determin how. + if (scriptName === "lsp-servers-config.json") { lspServersConfig = JSON.parse(scriptStr); + loadSettingsFileToUI(); } } \ No newline at end of file diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/components.js b/user_config/usr/share/newton/context_path/resources/js/newton/components.js new file mode 100644 index 0000000..a05c2b2 --- /dev/null +++ b/user_config/usr/share/newton/context_path/resources/js/newton/components.js @@ -0,0 +1,87 @@ +class InputListContainer extends HTMLElement { + constructor() { + super(); + } + + loadShaddowRoot(tag = "input-list-template") { + let template = document.getElementById(tag); + let templateContent = template.content; + + const shadowRoot = this.attachShadow({ mode: "open" }); + shadowRoot.appendChild( templateContent.cloneNode(true) ); + } + + setTitle(title = "[NO TITLE]") { + this.shadowRoot.getElementById("title").innerText = title; + } + + append(elm = null) { + if (!elm) return; + this.shadowRoot.getElementById("input-list").appendChild(elm); + } + + remove(elm = null) { + if (!elm) return; + this.shadowRoot.getElementById("input-list").remove(elm); + } + + serialize() { + let tags = this.shadowRoot.children; + for (var i = 0; i < tags.length; i++) { + data = tags[i].serialize(); + } + } +} + +class InputListItemContainer extends HTMLElement { + constructor() { + super(); + } + + loadShaddowRoot(tag = "input-list-item-template") { + let template = document.getElementById(tag); + let templateContent = template.content; + + const shadowRoot = this.attachShadow({ mode: "open" }); + shadowRoot.appendChild( templateContent.cloneNode(true) ); + } + + setTitle(textStr = "") { + if (Object.getPrototypeOf(textStr) !== String.prototype) return; + + this.shadowRoot.getElementById("title").innerText = textStr; + } + + getText() { + return this.shadowRoot.getElementById("input-entry").value; + } + + setText(textStr = "") { + if (Object.getPrototypeOf(textStr) !== String.prototype) return; + + this.shadowRoot.getElementById("input-entry").value = textStr; + } + + clear() { + this.shadowRoot.getElementById("input-entry").value = ""; + } + + serialize() { + return this.shadowRoot.getElementById("input-entry").value; + } +} + + +class InputList extends InputListContainer { + constructor() { + super(); + this.loadShaddowRoot(); + } +} + +class InputListItem extends InputListItemContainer { + constructor() { + super(); + this.loadShaddowRoot(); + } +} 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 a5a8c9e..14a9f9b 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 @@ -1,6 +1,9 @@ window.onload = (eve) => { console.log("Window Loaded..."); + console.log("Defining custom elements..."); + defineCustomElements(); + console.log("Loading LSP client files..."); loadLSPClientJSFiles(); @@ -12,6 +15,11 @@ window.onload = (eve) => { } +const defineCustomElements = () => { + customElements.define("input-list", InputList, { extends: 'ul' }); + customElements.define("input-list-item", InputListItem, { extends: 'li' }); +} + const loadLSPClientJSFiles = () => { sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = LSP_SERVER_CONFG, content = ""); sendMessage(topic = "load_javascript", ftype = "", fhash = "", fpath = `${BASE_LINK}/ace-linters.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 c05066c..e109bde 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,12 +18,13 @@ const EDITOR_OPTS = { } const BASE_LINK = `${window.location.href}resources/js/libs/ace_editor/lsp`; -const LSP_SERVER_CONFG = `${window.location.href}../lsp_servers_config.json`; +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 lspProvider = null; +let lspServersConfig = null; +let lspSettingsUI = document.getElementById('lsp-settings'); 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 1f66d0f..8ccf412 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 @@ -86,3 +86,73 @@ const loadPythonLSPFromNetwork = () => { }); } + + +const loadSettingsFileToUI = async () => { + let languages = Object.keys(lspServersConfig); + + for (let i = 0; i < languages.length; i++) { + let lang = languages[i]; + let elm = document.createElement("input-list"); + + elm.setTitle(lang); + lspSettingsUI.appendChild( elm ); + + generateElement(lang, elm, lspServersConfig[lang]); + } + +} + + +const saveSettingsFileFromUI = () => { + +} + + +const generateElement = (parent, elm, config) => { + const proto = Object.getPrototypeOf(config) + + switch (proto) { + case String.prototype: + let inputElm = document.createElement("input-list-item"); + inputElm.setTitle(parent); + inputElm.setText(config); + elm.append(inputElm); + + break; + case Array.prototype: + let inputListElm = document.createElement("input-list"); + for (var i = 0; i < config.length; i++) { + let inputElm = document.createElement("input-list-item"); + inputElm.setText( config[i] ); + inputListElm.append(inputElm); + } + elm.append(inputListElm); + + break; + case Boolean.prototype: + + break; + case Map.prototype: + + break; + default: + if ( isDict(config) ) { + let keys = Object.keys(config); + + for (let i = 0; i < keys.length; i++) { + let key = keys[i]; + generateElement(key, elm, config[key] ); + } + + break; + } + + console.log("No generatable HTML type...") + } + +} + +const isDict = (dict) => { + return typeof dict === "object" && !Array.isArray(dict); +}; \ No newline at end of file diff --git a/user_config/usr/share/newton/lsp_servers_config.json b/user_config/usr/share/newton/lsp-servers-config.json similarity index 86% rename from user_config/usr/share/newton/lsp_servers_config.json rename to user_config/usr/share/newton/lsp-servers-config.json index 05772c0..7935068 100644 --- a/user_config/usr/share/newton/lsp_servers_config.json +++ b/user_config/usr/share/newton/lsp-servers-config.json @@ -1,7 +1,8 @@ { "sh": { "info": "", - "command": [], + "command": "", + "socket": "ws://127.0.0.1:3030/shell", "initialization_options": {} }, "python": { @@ -46,17 +47,20 @@ }, "c": { "info": "https://clangd.llvm.org/", - "command": ["/usr/bin/clangd"], + "command": "/usr/bin/clangd", + "socket": "ws://127.0.0.1:3030/c", "initialization_options": {} }, "cpp": { "info": "https://clangd.llvm.org/", - "command": ["/usr/bin/clangd"], + "command": "/usr/bin/clangd", + "socket": "ws://127.0.0.1:3030/cpp", "initialization_options": {} }, "java": { "info": "https://download.eclipse.org/jdtls/", - "command": ["java-language-server"], + "command": "java-language-server", + "socket": "ws://127.0.0.1:3030/java", "initialization_options": {} } } \ No newline at end of file