Monaco-editor: Can I get monarch tokens in provideCompletionItems?

Created on 24 Dec 2018  路  2Comments  路  Source: microsoft/monaco-editor


monaco-editor version: 0.15.6
Browser: Google Chrome 68.0.3440.106
OS: Windows 10 64-bit

When I implement the provideCompletionItems function, it looks that the tokens information is important for me to recognize the current state(for example, whether we are in the comment area).

Since I have implemented a Monarch tokens provider, I wonder if I can got the parsed result from the tokens provider in provideCompletionItems. If possible, I need not to implement another parser to get tokens from the whole text, which would be very inefficient.

Any idea? Thanks!

Most helpful comment

Thanks, Alexandru. I have implemented another tokenizer to solve this problem. Although it looks inefficient that my tokenizer works with Monarch concurrently, it really works.
I hope Monarch may provide more interface or more info, it could provide much more convenience for us.
Anyway, thanks.

All 2 comments

This is not API, but since this is JS you can hack your way around.

On the model, you can call model.getLineTokens(lineNumber). This will return a class of type LineTokens. You can loop through tokens or search one given a certain text offset and you can use the getStandardTokenType method to determine what "general" kind of token this is:

export const enum StandardTokenType {
    Other = 0,
    Comment = 1,
    String = 2,
    RegEx = 4
}

But that is kind of the only thing that survives (besides the coloring) from the tokenizer. i.e. token types are not stored in a string format as returned from the tokenizer.

Thanks, Alexandru. I have implemented another tokenizer to solve this problem. Although it looks inefficient that my tokenizer works with Monarch concurrently, it really works.
I hope Monarch may provide more interface or more info, it could provide much more convenience for us.
Anyway, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fabiospampinato picture fabiospampinato  路  3Comments

ststeiger picture ststeiger  路  3Comments

inf9144 picture inf9144  路  3Comments

andreymarchenko picture andreymarchenko  路  3Comments

poloten4uk picture poloten4uk  路  3Comments