Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[support] How to mark errors in a new language? #284

Closed
krzychukula opened this issue Dec 6, 2016 · 4 comments
Closed

[support] How to mark errors in a new language? #284

krzychukula opened this issue Dec 6, 2016 · 4 comments
Assignees
Milestone

Comments

@krzychukula
Copy link

I'm working on on my own language support in monaco-editor and while adding tokenizer was pretty easy I'm not sure how can I show errors.

        const TokensProvider = {
            tokenize: (line) => {
                const tokens = tokenize(line)
                return {
                    tokens
                };
            }
        };

        monaco.languages.setTokensProvider('myLanguage', TokensProvider);

I was going throgh api and code and so far found info about Markers and Diagnostics.

For now I'm going to go with something like:

  const TokensProvider = {
            tokenize: (line) => {
                const tokens = tokenize(line)
                const markers = tokens.map(({startIndex, scopes, text}) => {
                    if (scopes === 'error') {
                        return {
                            severity: monaco.Severity.Error,
                            startLineNumber: 1,
                            startColumn: startIndex + 1,
                            endLineNumber: 1,
                            endColumn: startIndex + 1 + text.length,
                            message: 'Error \n'
                        };
                    }
                }).filter(exist => exist);

                monaco.editor.getModels()
                   .forEach(model => monaco.editor.setModelMarkers(model, '', markers));

                return {
                    tokens
                };
            }
        };

        monaco.languages.setTokensProvider('myLanguage', TokensProvider);

But I'm sure if it's the best place, on the other hand I would like to run tokenize only once.

Any suggestions?

@krzychukula
Copy link
Author

krzychukula commented Dec 6, 2016

  1. I have realized that I don't have startLineNumber or endLineNumber in there so it's probably wrong place. Still I'm not sure how to reuse tokenization if I put it in some other place.

@krzychukula krzychukula changed the title How to mark errors in a new language? [support] How to mark errors in a new language? Dec 6, 2016
@krzychukula
Copy link
Author

  1. Last question. My context is a little different because I want to have editor for single line of code with folding. If I understand correctly Monaco editor has been build to be used as a editor window, but is it possible to react to how many folded lines there are and to expand the height of the editor?

Basically: have one one of text visible on the page but if it starts to fold - display two lines of text etc.

Thanks!

@alexdima
Copy link
Member

The recommended way to set errors/warnings is via monaco.editor.setModelMarkers. These will then be rendered via squiggles. Here is for example how errors are set for TypeScript/JavaScript.

You can listen to editor.onDidScrollChange and check if e.scrollHeightChanged. Then, you could deduce that wrapping has occurred and then use editor.getLayoutInfo() to look at the lineHeight and then recompute a good height which can then be set via editor.layout({ width: w, height: h});.

@alexdima alexdima self-assigned this Jan 16, 2017
@alexdima alexdima added this to the Backlog milestone Jan 16, 2017
@krzychukula
Copy link
Author

Thanks

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants