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.
This commit is contained in:
lucebac 2024-09-26 20:36:42 +02:00 committed by GitHub
parent 2b4410739d
commit 7513fec507
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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);
};