maxedison
maxedison

Reputation: 17553

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?

Upvotes: 9

Views: 2500

Answers (1)

Gama11
Gama11

Reputation: 34148

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.

Upvotes: 8

Related Questions