mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 09:13:07 +02:00
BUGFIX: Editor shows "+1 overload" with all NS APIs (#1883)
This commit is contained in:
@@ -2,6 +2,15 @@ import React, { useEffect, useRef } from "react";
|
||||
|
||||
import * as monaco from "monaco-editor";
|
||||
|
||||
import netscriptDefinitions from "../NetscriptDefinitions.d.ts?raw";
|
||||
/**
|
||||
* We use relative paths here to:
|
||||
* - Bypass exports in @types/react's package.json
|
||||
* - Prevent TypeScript from complaining about importing a declaration file.
|
||||
*/
|
||||
import reactTypes from "../../../node_modules/@types/react/index.d.ts?raw";
|
||||
import reactDomTypes from "../../../node_modules/@types/react-dom/index.d.ts?raw";
|
||||
|
||||
import { useScriptEditorContext } from "./ScriptEditorContext";
|
||||
import { scriptEditor } from "../ScriptEditor";
|
||||
|
||||
@@ -26,6 +35,20 @@ export function Editor({ onMount, onChange, onUnmount }: EditorProps) {
|
||||
// Before initializing monaco editor
|
||||
scriptEditor.initialize();
|
||||
|
||||
/**
|
||||
* Create models for NS API, React, and ReactDOM to make them work as extra libraries being available in the global
|
||||
* scope. We can do this by calling languageDefaults.addExtraLib in src\ScriptEditor\ScriptEditor.ts. However,
|
||||
* monaco editor has a bug that makes function definitions appear as duplicate ones. For more information, please
|
||||
* check: https://github.com/microsoft/monaco-editor/issues/3580 and https://github.com/microsoft/monaco-editor/pull/4544.
|
||||
*/
|
||||
monaco.editor.createModel(
|
||||
netscriptDefinitions.replace(/export /g, ""),
|
||||
"typescript",
|
||||
monaco.Uri.file("netscript.d.ts"),
|
||||
);
|
||||
monaco.editor.createModel(reactTypes, "typescript", monaco.Uri.file("react.d.ts"));
|
||||
monaco.editor.createModel(reactDomTypes, "typescript", monaco.Uri.file("react-dom.d.ts"));
|
||||
|
||||
// Initialize monaco editor
|
||||
editorRef.current = monaco.editor.create(containerDiv.current, {
|
||||
value: "",
|
||||
|
||||
Reference in New Issue
Block a user