在VS Code扩展中实现叠加层的方法是什么?

huangapple go评论74阅读模式
英文:

How to implement overlay in VS Code Extension?

问题

I have been developing the VS Code extension. I implemented the codelens and added few command actions based on content in the document.

Now, whenever the user clicks on the codelens command, I would like to add an overlay as shown in the screenshot below 在VS Code扩展中实现叠加层的方法是什么?

The closest thing that I came across is https://github.com/microsoft/vscode-extension-samples/tree/main/code-actions-sample, which is more about diagnostics but does not necessarily solve the requirement of showing an overlay.

Is there any good example of how to add an overlay when a codelens command or any command is invoked?

英文:

I have been developing the VS Code extension. I implemented the codelens and added few command actions based on content in the document.

Now, whenever user clicks on the codelens command, I would like to add a overlay as in below screenshot 在VS Code扩展中实现叠加层的方法是什么?

The closest thing that I came across is https://github.com/microsoft/vscode-extension-samples/tree/main/code-actions-sample which is more over diagnostic but does not necessarily solve the requirement of showing overlay.

Is there any good example about how to add overlay when a codelens command or any command is invoked ?

答案1

得分: 1

你需要在你的 CodeLens 对象中使用 editor.action.peekLocations 命令,并传递一个名为 "gotoAndPeek" 的额外参数。这发生在你的 provideCodeLens 方法内部。

类似这样:

let somLens = new ImplementationLens(
    someRange,
    <Command>{
        title: "Your CodeLens Title",
        command: "editor.action.peekLocations",
        arguments: [
            window.activeTextEditor?.document.uri,
            somePositionThisPeekRefersTo,
            theListOfLocationsToBePeeked,
            "gotoAndPeek"
        ]
    }

希望对你有所帮助。

英文:

You need to use the editor.action.peekLocations command in your CodeLens object, and also pass an additional argument called "gotoAndPeek" to it. This happens inside your provideCodeLens method).

Something like this:

    let somLens = new ImplementationLens(
       someRange,
       <Command>{
           title: "Your CodeLens Title,
           command: "editor.action.peekLocations",
            arguments: [
                window.activeTextEditor?.document.uri,
                somePositionThisPeekRefersTo,
                theListOfLocationsToBePeeked,
                "gotoAndPeek"
            ]

Hope this helps

huangapple
  • 本文由 发表于 2023年3月7日 14:47:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定