Visual Studio 基于代码自定义扩展行的注释

Visual Studio Code Custom Extension Line Based Note

我正在尝试为 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()));

您屏幕截图中的功能称为 "Code Lens"。更具体地说,您正在寻找 languages namespace. Or if you're writing a Language Server instead of using the VSCode API directly, the textDocument/codeLens request method.

registerCodeLensProvider() 函数