Skip to content

Commit

Permalink
7. Add a little secret
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Azpillaga Aldalur committed Dec 13, 2023
1 parent ee79df8 commit f9aad98
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ editor.onDidChangeModelContent(() => {
visualizeIssues(parsingResult.issues);

colorizeMembers(parsingResult.data);

applyMonacoConfiguration(parsingResult.data);
});

function visualizeIssues(issues: Issue[]) {
Expand Down Expand Up @@ -65,4 +67,45 @@ function colorizeMembers(root?: Node) {
}
}
decorations = editor.deltaDecorations(decorations, newDecorations);
}

function applyMonacoConfiguration(root?: Node) {
let diagnostics: monaco.editor.IMarkerData[] = [];

const configuration = {
applyMonacoConfiguration: JSONBoolean,
fontSize: JSONNumber,
theme: JSONString,
lineNumbers: JSONBoolean
};

if (((root as JSONObject)?.members?.find(x => x.name === "applyMonacoConfiguration")?.value as JSONBoolean)?.value) {
for (const member of (root as JSONObject).members) {
if (!(member.name in configuration)) {
diagnostics.push({
severity: monaco.MarkerSeverity.Error,
message: "Unexpected configuration member",
startLineNumber: member.position!.start.line,
startColumn: member.position!.start.column + 2,
endLineNumber: member.position!.start.line,
endColumn: member.position!.start.column + 2 + member.name.length
});
}
else if (!(member.value instanceof configuration[member.name])) {
diagnostics.push({
severity: monaco.MarkerSeverity.Error,
message: "Unexpected member type",
startLineNumber: member.value.position!.start.line,
startColumn: member.value.position!.start.column + 2,
endLineNumber: member.value.position!.start.line,
endColumn: member.value.position!.start.column + 2 + member.name.length
});
}
}
monaco.editor.setModelMarkers(editor.getModel()!, "json", diagnostics);

if (!diagnostics.length) {
editor.updateOptions(JSON.parse(editor.getValue()));
}
}
}

0 comments on commit f9aad98

Please sign in to comment.