From 7513fec5075e205b707ff0e809fb02a3f0b0dcc3 Mon Sep 17 00:00:00 2001 From: lucebac Date: Thu, 26 Sep 2024 20:36:42 +0200 Subject: [PATCH] EDITOR: import resolution in code editor (#1661) * FIX: import resolution in code editor Since I did not find any callback where we could just load imports on-demand, I opted for just loading all scripts from the server where a given script was opened from command line. This does not include scripts which are already open, only files which are not yet opened will be loaded. --- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 9390c472a..eb0b8962a 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -161,6 +161,32 @@ function Root(props: IProps): React.ReactElement { } } + function loadAllServerScripts(): void { + if (!currentScript) { + return; + } + + const server = GetServer(currentScript.hostname); + if (!server) { + return; + } + + server.scripts.forEach((s) => { + const uri = monaco.Uri.from({ + scheme: "file", + path: `${s.server}/${s.filename}`, + }); + + const model = monaco.editor.getModel(uri); + if (model !== null && !model.isDisposed()) { + // there's already a model, don't overwrite + return; + } + + makeModel(server.hostname, s.filename, s.code); + }); + } + const debouncedCodeParsing = debounce((newCode: string) => { let server; if (!currentScript || !hasScriptExtension(currentScript.path) || !(server = GetServer(currentScript.hostname))) { @@ -183,6 +209,7 @@ function Root(props: IProps): React.ReactElement { }, 300); const parseCode = (newCode: string) => { + loadAllServerScripts(); startUpdatingRAM(); debouncedCodeParsing(newCode); };