zdenek
zdenek

Reputation: 24288

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.

Upvotes: 12

Views: 10936

Answers (2)

zdenek
zdenek

Reputation: 24288

The following code snippet illustrates how to implement "Go To Definition" using vscode-languageserver:

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

Upvotes: 8

yageek
yageek

Reputation: 4455

I think you have to create a class implementing the DefinitionProvider and then register it using registerDefinitionProvider.

Take a look here and here for an example.

Upvotes: 2

Related Questions