final changes for monac

This commit is contained in:
Olivier Gagnon
2021-08-21 00:17:26 -04:00
parent f02c6443cc
commit 5aa24f22c4
13 changed files with 134 additions and 5745 deletions
+1
View File
@@ -1,3 +1,4 @@
export interface Options {
theme: string;
insertSpaces: boolean;
+21 -17
View File
@@ -10,26 +10,30 @@ interface IProps {
}
export function OptionsPopup(props: IProps): React.ReactElement {
const [options, setOptions] = useState<Options>(props.options);
const [theme, setTheme] = useState(props.options.theme);
const [insertSpaces, setInsertSpaces] = useState(props.options.insertSpaces);
function save() {
props.save(options);
props.save({
theme: theme,
insertSpaces: insertSpaces,
});
removePopup(props.id);
}
function setTheme(event: React.ChangeEvent<HTMLSelectElement>): void {
setOptions(old => {
old.theme = event.target.value;
return old;
});
}
return (<>
<p>Theme</p>
<select className="dropdown" onChange={setTheme} defaultValue={options.theme}>
<option value="vs-dark">vs-dark</option>
<option value="light">light</option>
</select>
return (<div className="editor-options-container noselect">
<div className="editor-options-line">
<p>Theme: </p>
<select className="dropdown" onChange={event => setTheme(event.target.value)} defaultValue={theme}>
<option value="vs-dark">vs-dark</option>
<option value="light">light</option>
</select>
</div>
<div className="editor-options-line">
<p>Use whitespace over tabs: </p>
<input type="checkbox" onChange={event => setInsertSpaces(event.target.checked)} checked={insertSpaces} />
</div>
<br />
<StdButton text={"Save"} onClick={save} />
</>);
<StdButton style={{width: '50px'}} text={"Save"} onClick={save} />
</div>);
}
+49 -20
View File
@@ -20,6 +20,30 @@ import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes";
import { numeralWrapper } from "../../ui/numeralFormat";
import { CursorPositions } from "../../ScriptEditor/CursorPositions";
import { libSource } from "../NetscriptDefinitions";
import { NetscriptFunctions } from "../../NetscriptFunctions";
import { WorkerScript } from "../../Netscript/WorkerScript";
import { Settings } from "../../Settings/Settings";
let symbols: string[] = [];
(function() {
const ns = NetscriptFunctions(({} as WorkerScript));
function populate(ns: any): string[] {
let symbols: string[] = [];
const keys = Object.keys(ns);
for(const key of keys) {
if(typeof ns[key] === 'object') {
symbols.push(key);
symbols = symbols.concat(populate(ns[key]));
}
if(typeof ns[key] === 'function') {
symbols.push(key);
}
}
return symbols;
}
symbols = populate(ns);
})();
interface IProps {
filename: string;
@@ -40,7 +64,10 @@ export function Root(props: IProps): React.ReactElement {
const [filename, setFilename] = useState(props.filename);
const [code, setCode] = useState<string>(props.code);
const [ram, setRAM] = useState('');
const [options, setOptions] = useState<Options>({theme: 'vs-dark', insertSpaces: false});
const [options, setOptions] = useState<Options>({
theme: Settings.MonacoTheme,
insertSpaces: Settings.MonacoInsertSpaces,
});
function save(): void {
if(editorRef.current !== null) {
@@ -148,13 +175,19 @@ export function Root(props: IProps): React.ReactElement {
function openOptions(): void {
const id="script-editor-options-popup";
const newOptions = {
theme: '',
insertSpaces: false,
};
Object.assign(newOptions, options);
createPopup(id, OptionsPopup, {
id: id,
options: {
theme: options.theme,
insertSpaces: options.insertSpaces,
},
save: (options: Options) => setOptions(options),
options: newOptions,
save: (options: Options) => {
setOptions(options);
Settings.MonacoTheme = options.theme;
Settings.MonacoInsertSpaces = options.insertSpaces;
}
});
}
@@ -204,27 +237,23 @@ export function Root(props: IProps): React.ReactElement {
function beforeMount(monaco: any): void {
monaco.languages.registerCompletionItemProvider('javascript', {
provideCompletionItems: () => {
return { suggestions: [
{
label: 'upgradeHomeRam',
const suggestions = [];
for(const symbol of symbols) {
suggestions.push({
label: symbol,
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'upgradeHomeRam()',
documentation: 'Hello javascript documentation',
},
{
label: 'connect',
kind: monaco.languages.CompletionItemKind.Function,
insertText: 'connect(${1:server})',
insertText: symbol,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: 'Hello javascript documentation',
},
] };
});
}
return { suggestions: suggestions };
}
});
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, 'netscript.d.ts');
monaco.languages.typescript.typescriptDefaults.addExtraLib(libSource, 'netscript.d.ts');
}
console.log(options);
return (<div id="script-editor-wrapper">
<div id="script-editor-filename-wrapper">
<p id="script-editor-filename-tag" className="noselect"> <strong style={{backgroundColor:'#555'}}>Script name: </strong></p>
@@ -240,7 +269,7 @@ export function Root(props: IProps): React.ReactElement {
defaultValue={code}
value={code}
onChange={updateCode}
theme="vs-dark"
theme={options.theme}
options={options}
/>
<div id="script-editor-buttons-wrapper">