mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
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:
parent
2b4410739d
commit
7513fec507
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user