Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement "Go To Definition" extension in VSCode

Which method in vscode-languageserver::IConnection has to be implemented to provide functionality "Go To Definition" over multiple files?

I was studying Language Server Node Example and vscode "API documentation", but I didn't find any info.

like image 343
zdenek Avatar asked Feb 16 '16 08:02

zdenek


People also ask

How do you implement to define in Visual Studio code?

If a language supports it, you can go to the definition of a symbol by pressing F12. Tip: You can jump to the definition with Ctrl+Click or open the definition to the side with Ctrl+Alt+Click.

How do I enable definition in Visual Studio?

If you are a keyboard user, place your text cursor somewhere inside the symbol name and press F12. If you are a mouse user, either select Go To Definition from the right-click menu or use the Ctrl-click functionality described in the following section.

How do you add an extension to VS Code?

You can browse and install extensions from within VS Code. Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.

How do you enter method implementation in Visual Studio code?

Place the caret at a symbol in the code viewer or select the symbol in a tool window. Choose Navigate | Go To Implementation in the main menu, press Ctrl+F12 , or click the symbol while holding Ctrl+Alt keys. Note that in Visual Studio 2017 and later, the Ctrl+Alt -click is used for adding multiple carets.


1 Answers

The following code snippet illustrates how to implement "Go To Definition" using vscode-laguageserver.

connection.onInitialize((params): InitializeResult => {
    ...
    return {
        capabilities: {
            definitionProvider: true,
            ...
        }
    }
});

connection.onDefinition((textDocumentIdentifier: TextDocumentIdentifier): Definition => {
    return Location.create(textDocumentIdentifier.uri, {
        start: { line: 2, character: 5 },
        end: { line: 2, character: 6 }
    });
});
like image 143
zdenek Avatar answered Oct 24 '22 22:10

zdenek