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

433 Views Asked by At

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, i.e., 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?

1

There are 1 best solutions below

0
On

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]
                };