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

跟風遠走 提交于 2019-11-27 06:26:46

问题


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?


回答1:


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

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);
}

Update: unfortunately, it looks like scope-info is no longer compatible with current VSCode versions.



来源:https://stackoverflow.com/questions/45113929/how-to-tokenize-grammars-like-in-monaco-editor-tokenize-for-use-in-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!