generated from itdominator/Python-With-Gtk-Template
Capped const variables; loading config and socket from config
This commit is contained in:
parent
7bec522a31
commit
c268a7ef1a
@ -105,13 +105,13 @@
|
||||
<script src="resources/js/libs/ace_editor/ext-language_tools.js"></script>
|
||||
|
||||
<!-- For ACE LSP... -->
|
||||
<script src="resources/js/newton/lsp-manager.js"></script>
|
||||
<script src="resources/js/libs/ace_editor/lsp/ace-linters.js"></script>
|
||||
<script src="resources/js/libs/ace_editor/lsp/service-manager.js"></script>
|
||||
<script src="resources/js/libs/ace_editor/lsp/language-client.js"></script>
|
||||
|
||||
<!-- For Application... -->
|
||||
<script src="resources/js/newton/globals.js"></script>
|
||||
<script src="resources/js/newton/lsp-manager.js"></script>
|
||||
<script src="resources/js/newton/utils.js"></script>
|
||||
<script src="resources/js/newton/post-ajax.js"></script>
|
||||
<script src="resources/js/newton/ajax.js"></script>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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", {
|
||||
manager.registerServer(
|
||||
"python", {
|
||||
module: () => {
|
||||
importScripts( "${ scriptBlobURLs["language-client.js"] }" );
|
||||
importScripts( "${ SCRIPT_BLOB_URLs["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"
|
||||
]
|
||||
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'] ) }
|
||||
});
|
||||
}()
|
||||
`;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user