mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 14:13:48 +01:00
rm some anys
This commit is contained in:
parent
dfadfe6eb2
commit
96654d4c0a
@ -17,7 +17,7 @@ import { TextFile } from "../../TextFile";
|
|||||||
import { calculateRamUsage, checkInfiniteLoop } from "../../Script/RamCalculations";
|
import { calculateRamUsage, checkInfiniteLoop } from "../../Script/RamCalculations";
|
||||||
import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes";
|
import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes";
|
||||||
import { numeralWrapper } from "../../ui/numeralFormat";
|
import { numeralWrapper } from "../../ui/numeralFormat";
|
||||||
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
|
import { DragDropContext, Droppable, Draggable, DropResult } from "react-beautiful-dnd";
|
||||||
import SearchIcon from "@mui/icons-material/Search";
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
|
|
||||||
import { NetscriptFunctions } from "../../NetscriptFunctions";
|
import { NetscriptFunctions } from "../../NetscriptFunctions";
|
||||||
@ -319,19 +319,29 @@ export function Root(props: IProps): React.ReactElement {
|
|||||||
// https://github.com/threehams/typescript-error-guide/blob/master/stories/components/Editor.tsx#L11-L39
|
// https://github.com/threehams/typescript-error-guide/blob/master/stories/components/Editor.tsx#L11-L39
|
||||||
// https://blog.checklyhq.com/customizing-monaco/
|
// https://blog.checklyhq.com/customizing-monaco/
|
||||||
// Before the editor is mounted
|
// Before the editor is mounted
|
||||||
function beforeMount(monaco: any): void {
|
function beforeMount(monaco: Monaco): void {
|
||||||
if (symbolsLoaded) return;
|
if (symbolsLoaded) return;
|
||||||
// Setup monaco auto completion
|
// Setup monaco auto completion for ns1
|
||||||
symbolsLoaded = true;
|
symbolsLoaded = true;
|
||||||
monaco.languages.registerCompletionItemProvider("javascript", {
|
monaco.languages.registerCompletionItemProvider("javascript", {
|
||||||
provideCompletionItems: () => {
|
provideCompletionItems: (
|
||||||
const suggestions = [];
|
model: monaco.editor.ITextModel,
|
||||||
|
position: monaco.Position,
|
||||||
|
): monaco.languages.CompletionList => {
|
||||||
|
const word = model.getWordAtPosition(position);
|
||||||
|
const suggestions: monaco.languages.CompletionItem[] = [];
|
||||||
for (const symbol of symbols) {
|
for (const symbol of symbols) {
|
||||||
suggestions.push({
|
suggestions.push({
|
||||||
label: symbol,
|
label: symbol,
|
||||||
kind: monaco.languages.CompletionItemKind.Function,
|
kind: monaco.languages.CompletionItemKind.Function,
|
||||||
insertText: symbol,
|
insertText: symbol,
|
||||||
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
||||||
|
range: {
|
||||||
|
startLineNumber: position.lineNumber,
|
||||||
|
startColumn: word?.startColumn ?? 0,
|
||||||
|
endLineNumber: position.lineNumber,
|
||||||
|
endColumn: position.column,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { suggestions: suggestions };
|
return { suggestions: suggestions };
|
||||||
@ -340,24 +350,32 @@ export function Root(props: IProps): React.ReactElement {
|
|||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
// We have to improve the default js language otherwise theme sucks
|
// We have to improve the default js language otherwise theme sucks
|
||||||
const l = await monaco.languages
|
// https://github.com/microsoft/monaco-editor/issues/1927#issuecomment-692909147
|
||||||
.getLanguages()
|
// We should make a copy of javascript with our changes and make that a new custom language.
|
||||||
.find((l: any) => l.id === "javascript")
|
const js = monaco.languages.getLanguages().find(({ id }) => id === "javascript");
|
||||||
.loader();
|
if (js === undefined) throw new Error("The javascript language isn't loaded in Monaco.");
|
||||||
|
// Define a new type in order to more properly cast what's coming out of monaco.
|
||||||
|
type ActualLanguage = monaco.languages.ILanguageExtensionPoint & {
|
||||||
|
loader: () => Promise<{ language: monaco.languages.IMonarchLanguage }>;
|
||||||
|
};
|
||||||
|
const hasLoader = (js: monaco.languages.ILanguageExtensionPoint): js is ActualLanguage =>
|
||||||
|
js.hasOwnProperty("loader");
|
||||||
|
if (!hasLoader(js)) throw new Error("js extension point has no load entrypoint.");
|
||||||
|
const { language } = await js.loader();
|
||||||
// replaced the bare tokens with regexes surrounded by \b, e.g. \b{token}\b which matches a word-break on either side
|
// replaced the bare tokens with regexes surrounded by \b, e.g. \b{token}\b which matches a word-break on either side
|
||||||
// this prevents the highlighter from highlighting pieces of variables that start with a reserved token name
|
// this prevents the highlighter from highlighting pieces of variables that start with a reserved token name
|
||||||
l.language.tokenizer.root.unshift([new RegExp("\\bns\\b"), { token: "ns" }]);
|
language.tokenizer.root.unshift([new RegExp("\\bns\\b"), { token: "ns" }]);
|
||||||
for (const symbol of symbols)
|
for (const symbol of symbols)
|
||||||
l.language.tokenizer.root.unshift([new RegExp(`\\b${symbol}\\b`), { token: "netscriptfunction" }]);
|
language.tokenizer.root.unshift([new RegExp(`\\b${symbol}\\b`), { token: "netscriptfunction" }]);
|
||||||
const otherKeywords = ["let", "const", "var", "function"];
|
const otherKeywords = ["let", "const", "var", "function"];
|
||||||
const otherKeyvars = ["true", "false", "null", "undefined"];
|
const otherKeyvars = ["true", "false", "null", "undefined"];
|
||||||
otherKeywords.forEach((k) =>
|
otherKeywords.forEach((k) =>
|
||||||
l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeywords" }]),
|
language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeywords" }]),
|
||||||
);
|
);
|
||||||
otherKeyvars.forEach((k) =>
|
otherKeyvars.forEach((k) =>
|
||||||
l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeyvars" }]),
|
language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeyvars" }]),
|
||||||
);
|
);
|
||||||
l.language.tokenizer.root.unshift([new RegExp("\\bthis\\b"), { token: "this" }]);
|
language.tokenizer.root.unshift([new RegExp("\\bthis\\b"), { token: "this" }]);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const source = (libSource + "").replace(/export /g, "");
|
const source = (libSource + "").replace(/export /g, "");
|
||||||
@ -632,7 +650,7 @@ export function Root(props: IProps): React.ReactElement {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDragEnd(result: any): void {
|
function onDragEnd(result: DropResult): void {
|
||||||
// Dropped outside of the list
|
// Dropped outside of the list
|
||||||
if (!result.destination) {
|
if (!result.destination) {
|
||||||
result;
|
result;
|
||||||
|
@ -2,17 +2,14 @@ import * as monaco from "monaco-editor";
|
|||||||
import type { Monaco } from "@monaco-editor/react";
|
import type { Monaco } from "@monaco-editor/react";
|
||||||
|
|
||||||
export interface IScriptEditorTheme {
|
export interface IScriptEditorTheme {
|
||||||
[key: string]: any;
|
|
||||||
base: "vs" | "vs-dark" | "hc-black";
|
base: "vs" | "vs-dark" | "hc-black";
|
||||||
inherit: boolean;
|
inherit: boolean;
|
||||||
common: {
|
common: {
|
||||||
[key: string]: string;
|
|
||||||
accent: string;
|
accent: string;
|
||||||
bg: string;
|
bg: string;
|
||||||
fg: string;
|
fg: string;
|
||||||
};
|
};
|
||||||
syntax: {
|
syntax: {
|
||||||
[key: string]: string;
|
|
||||||
tag: string;
|
tag: string;
|
||||||
entity: string;
|
entity: string;
|
||||||
string: string;
|
string: string;
|
||||||
@ -24,16 +21,13 @@ export interface IScriptEditorTheme {
|
|||||||
error: string;
|
error: string;
|
||||||
};
|
};
|
||||||
ui: {
|
ui: {
|
||||||
[key: string]: any;
|
|
||||||
line: string;
|
line: string;
|
||||||
panel: {
|
panel: {
|
||||||
[key: string]: string;
|
|
||||||
bg: string;
|
bg: string;
|
||||||
selected: string;
|
selected: string;
|
||||||
border: string;
|
border: string;
|
||||||
};
|
};
|
||||||
selection: {
|
selection: {
|
||||||
[key: string]: string;
|
|
||||||
bg: string;
|
bg: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user