Skip to content

Commit 6e58060

Browse files
committed
feat: add type hint to monaco editor
1 parent fc84cf2 commit 6e58060

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

packages/northstar/src/blocks/special/FuncBlockBase.r.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { currentGraph } from "../../store";
2626
import { PropData, PropsData } from "../../utils/props";
2727
import { multiOutSocketToOutput } from "../../utils/toOutpus";
2828
import { SpecialBlock } from "./base";
29+
import { setExtraLib } from "../../utils";
2930

3031
export abstract class FuncBlockBase extends RectBlock implements SpecialBlock {
3132
cloneTo(target: this): this {
@@ -100,6 +101,7 @@ export abstract class FuncBlockBase extends RectBlock implements SpecialBlock {
100101
})
101102
) {
102103
this.inputValue.value = _.$ev;
104+
setExtraLib(this.slots.map(slot => `/** param */ declare const $${slot}: any;`).join("\n"));
103105
}
104106
},
105107
);

packages/northstar/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from "./align";
22
export * from "./duplicateBlocks";
33
export * from "./file";
4-
export * from "./initMonaco";
4+
export * from "./monaco";
55
export * from "./removeBlocks";

packages/northstar/src/utils/initMonaco.ts renamed to packages/northstar/src/utils/monaco.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ export function initMonaco() {
3434
formatProvider,
3535
);
3636
}
37+
38+
let currentExtraLib = "";
39+
export function setExtraLib(code: string) {
40+
if (currentExtraLib === code) return;
41+
monaco.languages.typescript.javascriptDefaults.addExtraLib(code, "context.d.ts");
42+
currentExtraLib = code;
43+
}

0 commit comments

Comments
 (0)