profile
viewpoint

Ask questionsHow to add simple custom language support?

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?

microsoft/monaco-editor

Answer questions rcjsuen

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

https://github.com/microsoft/monaco-editor/blob/0e0cf007e200ee1ee4a3ea55aa9210a54a78f7d5/monaco.d.ts#L852-L855

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
    }
]);
useful!

Related questions

Monarch: How do you add "@keywords" key to "language object"? (undocumented) hot 3
Error: Cannot find module 'monaco-editor/esm/vs/editor/contrib/gotoSymbol/goToCommands' hot 2
Removing the tooltip on the read-only editor that says 'cannot edit in read-only editor' hot 1
Monaco paste event hot 1
Registering/Providing custom Commands/CodeActions hot 1
How to get the line count including line wraps hot 1
Error: Cannot find module 'monaco-editor/esm/vs/editor/contrib/goToDefinition/goToDefinitionCommands' hot 1
TypeScript declaration preview from extra lib results in error hot 1
Editor props/extends the actual width of the parent that is a flexbox item hot 1
Problem with insane.js while using monaco-editor@0.18.0 hot 1
Change the language of an existing editor hot 1
javascript/typescript typedefs lost when webworker times out hot 1
Can't scroll in firefox hot 1
monaco-editor polute the global variables, making incompatible with other JS libraries, such as CodeMirror, RequireJS, SeaJS, etc. hot 1
Highlight merge conflicts in monaco like in VSCode hot 1
Github User Rank List