microsoft/monaco-editor

How to add simple custom language support?

Closed this issue · 2 comments

For example I want to parse something like this: equals('somestring') | equals('anotherstring') | ...

  1. Syntax should be checked with error suggestions.
  2. Autocomplete.
  3. Highlighting.

Especially interested in the first. Or this isn't straightforward?

@Beyerheiser You need to use the setModelMarkers function in monaco.editor.

monaco-editor/monaco.d.ts

Lines 852 to 855 in 0e0cf00

/**
* Set the markers for a model.
*/
export function setModelMarkers(model: ITextModel, owner: string, markers: IMarkerData[]): void;

Please use the following code in the Monaco Playground to get started.

let model = monaco.editor.createModel(
    'This line is okay.\nThis line has a warning.\nThis line has an error.'
);

monaco.editor.create(document.getElementById("container"), {
	model
});

monaco.editor.setModelMarkers(model, "owner", [
    {
        startLineNumber: 2,
        startColumn: 17,
        endLineNumber: 2,
        endColumn: 24,
        message: 'Warning!',
        severity: monaco.MarkerSeverity.Warning
    },
    {
        startLineNumber: 3,
        startColumn: 18,
        endLineNumber: 3,
        endColumn: 23,
        message: 'Erorr!',
        severity: monaco.MarkerSeverity.Error
    }
]);

Thank you!