Visual Studio Code Custom Language IntelliSense and Go to symbol

好久不见. 提交于 2019-12-05 02:24:21

问题


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?


回答1:


@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.




回答2:


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.



来源:https://stackoverflow.com/questions/34640625/visual-studio-code-custom-language-intellisense-and-go-to-symbol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!