简体   繁体   中英

How to link Codelens provider with reference provider for VS Code API

I already have an existing reference provider for the custom language. It works, it opens a references using go to references and go to peek: Go to references

Although, I am not using these commands editor.action.peekLocations or editor.action.showReferences for the reference provider and everything is automatically managed by VS Code API, we just need to implement provideReferences and return location and uri.

Now, I want to do the same with codelens provider as done for typecript, ie, on clicking on references, it opens a peek window. : Code lens references

I have provide Is there a way, to directly link this codelens and reference provider, so on clicking on the references it does the same?

Found the answer, We have to use "editor.action.showReferences" command from VS- Code built-in commands. Reference from the github repo of vscode: https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/codeLens/baseCodeLensProvider.ts

lens.command = {
                    title: "References",
                    tooltip: "References",
                    command: "editor.action.showReferences",
                    arguments: [document.uri, lens.range.start, lens.location]
                };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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