11

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.

Gama11
  • 31,714
  • 9
  • 78
  • 100
zdenek
  • 21,428
  • 1
  • 12
  • 33

2 Answers2

8

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 }
  });
});
BYTEzel
  • 3
  • 3
zdenek
  • 21,428
  • 1
  • 12
  • 33
2

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.

yageek
  • 4,115
  • 3
  • 30
  • 48
  • Their extension depends directly on `vscode` modue. But thanks to you I found the connection points in the `vscode-languageserver` – zdenek Feb 17 '16 at 07:28