英文:
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
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
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论