Skip to content

Return DocumentSymbol[] on textDocument/documentSymbol #2817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

deirn
Copy link

@deirn deirn commented Aug 7, 2025

Closes #1519

Return hierarchical DocumentSymbol instead of the deprecated SymbolInformation, useful for breadcrumb feature in various clients.

Screenshots from Emacs with LSP-Bridge

Screenshot From 2025-08-08 03-47-37 Screenshot From 2025-08-08 03-49-38 Screenshot From 2025-08-08 04-04-56

@jasonlyu123
Copy link
Member

jasonlyu123 commented Aug 8, 2025

Thank you. Can you create a separate getHierarchicalDocumentSymbols method in the DocumentSymbolsProvider for the new format, while retaining the old format for compatibility? You can add a check in the server.ts to check configManager.getClientCapabilities()?.textDocument?.documentSymbol?.hierarchicalDocumentSymbolSupport to know whether we can provide the new format.

Also, since the server controls the hierarchy in the new format. We need to manually merge the result from TypeScript and HTML. Otherwise, the variables that are inside the template are no longer being marked as under a component/HTML tag. This can be done in the PluginHost. But this is a bit complex for a first-time contributor, so feel free to ask for direction if you can't figure out a way to do it. Or we can also add it in a later PR.

@deirn
Copy link
Author

deirn commented Aug 8, 2025

Thank you. Can you create a separate getHierarchicalDocumentSymbols method in the DocumentSymbolsProvider for the new format, while retaining the old format for compatibility? You can add a check in the server.ts to check configManager.getClientCapabilities()?.textDocument?.documentSymbol?.hierarchicalDocumentSymbolSupport to know whether we can provide the new format.

So return SymbolInformation[]?

Also, since the server controls the hierarchy in the new format. We need to manually merge the result from TypeScript and HTML. Otherwise, the variables that are inside the template are no longer being marked as under a component/HTML tag. This can be done in the PluginHost. But this is a bit complex for a first-time contributor, so feel free to ask for direction if you can't figure out a way to do it. Or we can also add it in a later PR.

Yeah, I just noticed that it also messed up snippets, will take a look.

@jasonlyu123
Copy link
Member

So return SymbolInformation[]?

Returns DocumentSymbol[] if the LSP client supports the new format.

// packages/language-server/src/server.ts
connection.onDocumentSymbol((evt, cancellationToken) => {
    if (
        configManager.getClientCapabilities()?.textDocument?.documentSymbol
            ?.hierarchicalDocumentSymbolSupport
    ) {
        return pluginHost.getHierarchicalDocumentSymbols(evt.textDocument, cancellationToken);
    }
    return pluginHost.getDocumentSymbols(evt.textDocument, cancellationToken);
});

@deirn
Copy link
Author

deirn commented Aug 8, 2025

Ok, so now it sorts and builds the hierarchical tree manually based on the symbol range.
And since it does it manually anyway, it's better to return the flat SymbolInformation[] in the plugins.

Screenshot, notice the root now is the style element

image

Typescript inside HTML and Snippets are still messed up, though, I'm not sure where to look to fix it.

Screenshots

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LSP uses old SymbolInformation format
2 participants