Skip to content

Commit

Permalink
FIX: import resolution in code editor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lucebac committed Sep 21, 2024
1 parent 21ffa53 commit 92cf53e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ScriptEditor/ui/ScriptEditorRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,28 @@ function Root(props: IProps): React.ReactElement {
}
}

function loadAllServerScripts(): void {
let server;
if (!currentScript || !(server = GetServer(currentScript.hostname))) {
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))) {
Expand All @@ -183,6 +205,7 @@ function Root(props: IProps): React.ReactElement {
}, 300);

const parseCode = (newCode: string) => {
loadAllServerScripts();
startUpdatingRAM();
debouncedCodeParsing(newCode);
};
Expand Down

0 comments on commit 92cf53e

Please sign in to comment.