繁体   English   中英

在 vscode 扩展中获取语法范围/标记

[英]Get grammar scopes / tokens in vscode extension

在 Visual Studio Code 中为新语言的文本突出显示定义了 TextMate 语法后,我现在正在编写一个 DefinitionProvider。 是否可以在我的扩展代码中访问文档的语法标记?

DefinitionProvider 中扩展方法的签名是:

provideDefinition(
    document: vscode.TextDocument,
    position: vscode.Position,
    token: vscode.CancellationToken,
  )

而且我找不到从文档实例中获取任何标记的方法...

非常感谢任何帮助 =)

编辑:让我重新表述一下:是否可以使用已经定义的 TextMate 语法来导航扩展代码中的代码? 我不想自己写一个解析器......

现在有一项服务可以做到这一点:使用我的图书馆:

import TextmateLanguageService from 'vscode-textmate-languageservice';

export async function activate(context: vscode.ExtensionContext) {
    const selector: vscode.DocumentSelector = 'custom';
    const textmateService = new TextmateLanguageService('custom', context);
    const textmateTokenService = await textmateService.initTokenService();
    const textDocument = vscode.window.activeTextEditor!.document;
    const tokens = textmateTokenService.fetch(textDocument);
};

https://github.com/vsce-toolroom/vscode-textmate-languageservice#tokenization

暂无
暂无

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

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