Skip to content

Conversation

@deirn
Copy link
Contributor

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

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2025

🦋 Changeset detected

Latest commit: 0f89dc4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
svelte-language-server Patch
svelte-check Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

The snippet/event handler bugs are independent, my guess is the document symbols logic within the typescript and/or svelte and/or html plugin need to be adjusted. That can happen separately though

@dummdidumm dummdidumm merged commit ba9185b into sveltejs:master Nov 11, 2025
3 checks passed
@github-actions github-actions bot mentioned this pull request Nov 11, 2025
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

3 participants