简体   繁体   English

Monaco 编辑器自定义令牌提供者行为

[英]Monaco editor custom token provider behaviour

I am attempting to implement a tokenizer with quite specific behaviour, where for example, in the following situation:我正在尝试实现具有非常特定行为的标记器,例如,在以下情况下:

1:   Line 1
2:   Line 2
3:
4:   Line 4 
5:   Line 5
6:   Line 6
7:
8:
9:   Line 9

A change on line 1, will cause a retokenization on lines 1-3, a change on line 5 will cause a retokenization on lines 3-8, a change on line 9 will cause a retokenziation on lines 7-9, etc.... This is because the tokenization of a given line might vary based on what happens until the next empty line.第 1 行的更改将导致第 1-3 行的重新标记化,第 5 行的更改将导致第 3-8 行的重新标记化,第 9 行的更改将导致第 7-9 行的重新标记化,等等...... . 这是因为给定行的标记化可能会根据在下一个空行之前发生的情况而有所不同。

So basically, I'm looking to tokenize the text by chunks delimited with empty lines.所以基本上,我希望通过用空行分隔的块来标记文本。

I have a vague prototype working with decorations, but for my usecase there's just no way of using decorations or semantic tokens, mainly for performance reasons.我有一个使用装饰的模糊原型,但对于我的用例来说,没有办法使用装饰或语义标记,主要是出于性能原因。 However monaco's setTokensProvider only seems to work on a line-by-line basis: editing a line in a document will cause every subsequent line to be retokenized, with no way of stopping it, and with no way of retokenizing lines prior to it.然而,摩纳哥的setTokensProvider似乎只能逐行工作:编辑文档中的一行将导致每个后续行都被重新标记,无法停止它,也无法重新标记之前的行。

Is there any realistic way of doing this currently, even if it's hacky and/or involves fiddling with some unexposed APIs?目前是否有任何现实的方法可以做到这一点,即使它是 hacky 和/或涉及摆弄一些未公开的 API? vscode's textmate grammars are capable of specifying tokens which span multiple lines, so I feel like I'm missing something:/ vscode 的 textmate 语法能够指定跨越多行的标记,所以我觉得我错过了一些东西:/

It sounds like you're looking for DocumentSemanticTokensProvider .听起来您正在寻找DocumentSemanticTokensProvider Take a look at this blog post :看看这篇博文

As its name implies, the DocumentSemanticTokensProvider in Monaco handles providing of semantics for an entire entered document.顾名思义,摩纳哥的 DocumentSemanticTokensProvider 处理为整个输入文档提供语义。 Unlike a tokens provider, instead of providing a set of regular expressions to tokenize the document, a DocumentSemanticTokensProvider implementation is a callback function: When invoked, the function is provided with the overall model containing the code entered by the user, and it is the responsibility of the implementor to return the necessary semantic information, requiring a full parse. Unlike a tokens provider, instead of providing a set of regular expressions to tokenize the document, a DocumentSemanticTokensProvider implementation is a callback function: When invoked, the function is provided with the overall model containing the code entered by the user, and it is the responsibility实现者返回必要的语义信息,需要完整的解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM