Loadsing LSP from backend blob url generation

This commit is contained in:
itdominator 2024-03-24 23:16:49 -05:00
parent 32a79032cc
commit 02ce50cb76
4 changed files with 60 additions and 50 deletions

View File

@ -73,17 +73,18 @@
<script src="resources/js/libs/ace_editor/ext-settings_menu.js"></script>
<script src="resources/js/libs/ace_editor/ext-language_tools.js"></script>
<!-- For ACE LSP... -->
<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/ajax.js"></script>
<!--<script src="resources/js/newton/post-ajax.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>
<script src="resources/js/newton/keybinding-newton.js"></script>
<script src="resources/js/newton/ui-logic.js"></script>
<script src="resources/js/newton/events.js"></script>
</body>
</html>

View File

@ -78,35 +78,8 @@ const importScriptFromNetwork = async (url) => {
}
const importScriptFromScriptStr = async (scriptStr) => {
// Create a Blob with the text content and MIME type "text/javascript".
const blob = createScriptBlob(scriptStr);
// Create an object URL from the Blob.
return createBlobURL(blob);
}
const importScriptFromBackendResponse = async (scriptName, dataStr) => {
backendResponse = atob(dataStr);
scriptBlobURLs[scriptName] = await importScriptFromScriptStr(backendResponse);
}
const importJavaScriptFileFromBlobURL = async (objectURL) => {
// Create a new script element and set its src attribute to the object URL.
const scriptElement = document.createElement("script");
scriptElement.src = objectURL;
// Add a listener to revoke the object URL when the script has loaded.
// scriptElement.addEventListener("load", () => {
// URL.revokeObjectURL(objectURL);
// });
// Append the script element to the document to execute the JavaScript code.
document.body.appendChild(scriptElement);
}
const importJavaScriptFile = async (url) => {
const objectURL = importScriptFromNetwork(url);
const objectURL = await importScriptFromNetwork(url);
// Create a new script element and set its src attribute to the object URL.
const scriptElement = document.createElement("script");
@ -119,4 +92,32 @@ const importJavaScriptFile = async (url) => {
// Append the script element to the document to execute the JavaScript code.
document.body.appendChild(scriptElement);
}
const importJavaScriptFileFromBlobURL = async (objectURL) => {
// Create a new script element and set its src attribute to the object URL.
const scriptElement = document.createElement("script");
scriptElement.src = objectURL;
// Add a listener to revoke the object URL when the script has loaded.
scriptElement.addEventListener("load", () => {
console.log("Loaded script...");
// URL.revokeObjectURL(objectURL);
});
// Append the script element to the document to execute the JavaScript code.
document.body.appendChild(scriptElement);
}
const importScriptFromScriptStr = async (scriptStr) => {
// Create a Blob with the text content and MIME type "text/javascript".
const blob = createScriptBlob(scriptStr);
// Create an object URL from the Blob.
return createBlobURL(blob);
}
const importScriptFromBackendResponse = async (scriptName, dataStr) => {
backendResponse = atob(dataStr);
scriptBlobURLs[scriptName] = await importScriptFromScriptStr(backendResponse);
}

View File

@ -16,6 +16,7 @@ const loadLSPClientJSFiles = () => {
const baseLink = `${window.location.href}resources/js/libs/ace_editor/lsp`;
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 = "");

View File

@ -67,28 +67,28 @@ const setSession = async (ftype, fhash, session) => {
if (ftype === "python") {
// const baseLink = "http://0.0.0.0:4880";
//importJavaScriptFile(baseLink + "/ace-linters.js").then(
// importScripts("${await importScriptFromNetwork(baseLink + "/service-manager.js")}");
// importScripts("${await importScriptFromNetwork(baseLink + "/python-service.js")}");
// importScripts("${await importScriptFromNetwork(baseLink + "/language-client.js")}");
// 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 but isn't websocket */
// manager.registerService("python", {
// module: () => {
// importScripts( "${ scriptBlobURLs["python-service.js"] }" );
// return {PythonService};
// },
// className: "PythonService",
// modes: "python|python3",
// });
/* Works and is websocket */
manager.registerServer("python", {
module: () => {
@ -109,12 +109,19 @@ const setSession = async (ftype, fhash, session) => {
}()
`;
let worker = new Worker(createBlobURL(createScriptBlob(workerString)));
let worker = new Worker(
createBlobURL(
createScriptBlob(workerString)
)
);
let provider = LanguageProvider.create(worker);
provider.registerEditor(editor);
}
);
).catch((e) => {
console.log(e);
});
}
}