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

Async support for custom TokensProvider #2139

Closed
PranayAgarwal opened this issue Sep 18, 2020 · 1 comment
Closed

Async support for custom TokensProvider #2139

PranayAgarwal opened this issue Sep 18, 2020 · 1 comment
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@PranayAgarwal
Copy link

The setTokensProvider function currently has the signature

export function setTokensProvider(languageId: string, provider: TokensProvider | EncodedTokensProvider | Thenable<TokensProvider | EncodedTokensProvider>): IDisposable;

The Thenable<TokensProvider | EncodedTokensProvider> part doesn't really make sense (unless there is a use case for it I am missing). Instead of this, it would be very helpful to have a tokenize(line: string, state: IState): Thenable<ILineTokens> variant which can defer tokenizing to another process/network/something else (same as all other providers).

@alexdima
Copy link
Member

The Thenable<TokensProvider | EncodedTokensProvider> part doesn't really make sense (unless there is a use case for it I am missing).

All the languages in monaco-languages register a promise in the similarly typed setMonarchTokensProvider. The promise is helpful because it allows the editor to know that there will be a tokenizer for a certain language and the editor can listen for that promise when it encounters embedded modes or when tokenizing hovers, or when the colorize API is used, etc. Basically, when tokenizing html, it will initially tokenize <script> blocks and <style> blocks in black & white and then install listeners for when the tokenizers for JS and CSS are loaded and at that point it will retokenize the blocks.

Instead of this, it would be very helpful to have a tokenize(line: string, state: IState): Thenable<ILineTokens> variant which can defer tokenizing to another process/network/something else (same as all other providers).

Yes, that would be good, but unfortunately there are many assumptions in the editor that tokenization can be done synchronously. I wrote a bit about this in the past at microsoft/vscode#77140

@alexdima alexdima added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Sep 18, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants