如何标记语法,例如在 monaco.editor.tokenize 中用于扩展 [英] How to tokenize grammars, like in monaco.editor.tokenize for use in extension
问题描述
我使用了 tokenizer在摩纳哥,但我没有看到它可以在 vscode 中访问.这对完成/签名帮助提供者很有帮助,我如何标记语法?
I have used the tokenizer in monaco but I do not see that it is accessible in vscode. This would be helpful for completion/signature help providers, how can I tokenize a grammar?
推荐答案
目前似乎没有正式的方法来执行此操作.有一个开放的功能请求,用于在此处的某个位置添加检索 tmLanguage 范围的功能:#580
It doesn't seem like there's an official way of doing this right now. There is an open feature request for adding the ability to retrieve tmLanguage scopes at a position here: #580
有一种可能的解决方法,它需要向 scope- 添加依赖项-信息 扩展名.此扩展公开了其他扩展可以使用的自己的 API.这是一个代码示例作者在链接问题中发布:
There is one potential workaround, which requires adding a dependency to the scope-info extension. This extension exposes an API of its own that other extension can use. Here's a code example posted by the author in the linked issue:
import * as api from 'scope-info'
async function example(doc : vscode.TextDocument, pos: vscode.Position) {
const siExt = vscode.extensions.getExtension<api.ScopeInfoAPI>('siegebell.scope-info');
const si = await siExt.activate();
const t1 : api.Token = si.getScopeAt(doc, pos);
}
更新:不幸的是,范围信息看起来像 不再与当前的 VSCode 版本兼容.
Update: unfortunately, it looks like scope-info is no longer compatible with current VSCode versions.
这篇关于如何标记语法,例如在 monaco.editor.tokenize 中用于扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!