Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically get list of all symbols in VS Code workspace for custom extension

In VS Code's quick view you can type #mySymbol to search your workspace for a symbol named mySymbol. I'd like to get these symbol results programmatically but don't see a way via the API to do so. Any ideas?

like image 954
maxedison Avatar asked Oct 18 '18 23:10

maxedison


1 Answers

You can run the vscode.executeWorkspaceSymbolProvider command for this:

vscode.executeWorkspaceSymbolProvider - Execute all workspace symbol provider.

  • query - Search string
  • (returns) - A promise that resolves to an array of SymbolInformation instances.
vscode.commands.executeCommand("vscode.executeWorkspaceSymbolProvider", "mySymbol").then(
    function (symbols: vscode.SymbolInformation[]) {
        // do something with the symbols
    }
);

Note that some symbol provider implementations may not return any results if the search query is an empty string.

like image 179
Gama11 Avatar answered Nov 13 '22 05:11

Gama11