Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Custom Language IntelliSense and Go to symbol

I am in the process of writing an extension for a custom language in Visual Studio Code. Syntax detection is working well via the tmLanguage file. I am trying to figure out how to add intellisense and go to symbol support, neither of which I have been able to find clear documentation on nor reference file(s) to work from.

When I have a file open with my custom language selected and I select go to symbol I get the following error: Unfortunately we have no symbol information for the file.

Is there any documentation, or can you provide some tips on how to get started, or do we know that these options are not available for custom languages?

like image 311
edencorbin Avatar asked Jan 06 '16 18:01

edencorbin


2 Answers

@Wosi is correct but he refers the API preview. Since the Nov-release you want to implement a WorkspaceSymbolProvider (https://code.visualstudio.com/docs/extensionAPI/vscode-api#WorkspaceSymbolProvider) to achieve this.

You can find how we did it TypeScript here and this is how to register the feature. Basically provide a provideWorkspaceSymbols function that given a search string returns a list of symbols.

like image 68
Johannes Rieken Avatar answered Nov 15 '22 06:11

Johannes Rieken


Go to any symbol in workspace: Implement a WorkspaceSymbolProvider and register it in your extension's main.js like this

function registerSupports(modeID, host, client) {
    vscode.languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider(client, modeID));
}

Go to symbol (at current cursor position): Implement a DefinitionProvider and register it in your extension's main.js like this

function registerSupports(modeID, host, client) {
    vscode.languages.registerDefinitionProvider(modeID, new DeclarationSupport(client));
}

IntelliSense: Implement a CompletionItemProvider and register it in your extension's main.js like this

function registerSupports(modeID, host, client) {
    vscode.languages.registerCompletionItemProvider(modeID, new SuggestSupport(client), '.');
}

See also HelloWorld extension and Language server example.

like image 20
Wosi Avatar answered Nov 15 '22 07:11

Wosi