简体   繁体   English

如何标记语法,例如在monaco.editor.tokenize中用于扩展

[英]How to tokenize grammars, like in monaco.editor.tokenize for use in extension

I have used the tokenizer in monaco but I do not see that it is accessible in vscode. 我在摩纳哥使用了分词器 ,但是我看不到它可以在vscode中访问。 This would be helpful for completion/signature help providers, how can I tokenize a grammar? 这将对完成/签名帮助提供者有所帮助,如何标记语法?

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 有一个开放的功能要求,可以在以下位置添加检索tmLanguage范围的功能: #580

There is one potential workaround, which requires adding a dependency to the scope-info extension. 有一种可能的解决方法,它要求向scope-in​​fo扩展添加依赖项。 This extension exposes an API of its own that other extension can use. 此扩展公开了其他扩展可以使用的自己的API。 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);
}

Update: unfortunately, it looks like scope-info is no longer compatible with current VSCode versions . 更新:不幸的是,看起来scope-in​​fo 不再与当前VSCode版本兼容

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

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