ok figured out how to make the javascript autocomplete.

This commit is contained in:
Olivier Gagnon 2021-08-20 17:14:20 -04:00
parent 4497143785
commit f02c6443cc
2 changed files with 28 additions and 1 deletions

@ -1,6 +1,14 @@
export const libSource = `interface NS {
args: string[];
/**
* Example documentation for scan.
* Example documentation for scan.
* Example documentation for scan.
* Example documentation for scan.
* Example documentation for scan.
* Example documentation for scan.
* Example documentation for scan.
* Example documentation for scan.
* Example documentation for scan.
*/
scan(ip: string, hostnames: boolean): string[];

@ -202,6 +202,25 @@ export function Root(props: IProps): React.ReactElement {
}
function beforeMount(monaco: any): void {
monaco.languages.registerCompletionItemProvider('javascript', {
provideCompletionItems: () => {
return { suggestions: [
{
label: 'upgradeHomeRam',
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'upgradeHomeRam()',
documentation: 'Hello javascript documentation',
},
{
label: 'connect',
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'connect(${1:server})',
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: 'Hello javascript documentation',
},
] };
}
});
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, 'netscript.d.ts');
monaco.languages.typescript.typescriptDefaults.addExtraLib(libSource, 'netscript.d.ts');
}
@ -217,7 +236,7 @@ export function Root(props: IProps): React.ReactElement {
onMount={onMount}
loading={<p>Loading script editor!</p>}
height="80%"
defaultLanguage="typescript"
defaultLanguage="javascript"
defaultValue={code}
value={code}
onChange={updateCode}