【问题标题】:Visual Studio Code Custom Extension Line Based Note基于 Visual Studio Code 自定义扩展线的注释
【发布时间】:2018-05-25 22:13:25
【问题描述】:

我正在尝试为 Visual Studio 代码创建一个扩展,它需要能够注释文件中的行,类似于图片中显示的引用,链接如下。

我希望能够在不修改源代码文件的情况下添加注释,例如红色矩形中所示的注释。我希望能够对源文件的每一行都这样做。我还希望能够对注释的内容进行动态修改。

我已经搜索了 VSC 的文档以及其他地方。我还没有找到它。谁能指导我正确的方向?

我知道以下内容不正确,但我不知道在哪里可以检查它应该如何完成。

class TestCodeLensProvider implements vscode.CodeLensProvider {
    public provideCodeLenses(document: TextDocument, token: CancellationToken):
        CodeLens[] | Thenable<CodeLens[]> {
        return new Array<CodeLens>();
    }

    public resolveCodeLens?(codeLens: CodeLens, token: CancellationToken):
        CodeLens | Thenable<CodeLens> {
        return new CodeLens(new vscode.Range(new vscode.Position(1, 1), new vscode.Position(1, 2)),/*I also don't know how to specify my command here*/ );
    }
}

export function activate(ctx: vscode.ExtensionContext): void {
    ctx.subscriptions.push(
        vscode.languages.registerCodeLensProvider(
            'json', new TestCodeLensProvider()));

【问题讨论】:

    标签: javascript typescript visual-studio-code vscode-extensions


    【解决方案1】:

    您的屏幕截图中的功能称为“代码镜头”。更具体地说,您正在寻找languages namespaceregisterCodeLensProvider() 函数。或者,如果您正在编写语言服务器而不是直接使用 VSCode API,the textDocument/codeLens request method

    【讨论】:

    • 很抱歉响应时间延迟了很长时间。在问另一个问题之前,我想确定我已经尝试了所有我能想到的。我在弄清楚我需要做什么来完成函数 provideCodeLenses 和 resolveCodeLenses 时遇到问题。我应该为第一个提供一个 codeLens 数组,为第二个提供一个 codeLens 吗?我真的迷失了这个。
    • 也许看一个实现示例,例如内置 TypeScript 扩展有帮助? github.com/Microsoft/vscode/blob/… 请注意,resolveCodeLens() 是可选的/没有必须实现。
    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 2018-05-15
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-07
    • 2017-09-13
    相关资源
    最近更新 更多