Skip to content

Fix document symbol search for editors without hierarchical support#3555

Open
mmatz-101 wants to merge 1 commit into
facebook:mainfrom
mmatz-101:flat-document-symbols-for-helix
Open

Fix document symbol search for editors without hierarchical support#3555
mmatz-101 wants to merge 1 commit into
facebook:mainfrom
mmatz-101:flat-document-symbols-for-helix

Conversation

@mmatz-101
Copy link
Copy Markdown

Summary

Editors like Helix do not declare hierarchicalDocumentSymbolSupport
in their client capabilities. Previously pyrefly treated this as a
signal to return nothing, so document symbol search was completely
broken in Helix.

Check the client capability at request time and return a flat
SymbolInformation list when hierarchical support is absent, falling
back to the existing nested DocumentSymbol response for clients like
VS Code that support it. The flat list is produced by recursively
unwrapping the symbol tree, preserving dotted container names
(e.g. Outer.Inner) so clients can still display symbol hierarchy
contextually.

Fixes #2945

Test Plan

Added unit tests for flatten_to_symbol_information covering:

  • Basic class with methods flattened correctly with container_name
  • Deep nesting with dotted container names (e.g. Outer.Inner)
  • Empty file returns empty list

Run with: cargo test test_flatten

Fixes facebook#2945

Editors like Helix do not declare `hierarchicalDocumentSymbolSupport`
in their client capabilities. Previously pyrefly treated this as a
signal to return nothing, so document symbol search was completely
broken in Helix.

Check the client capability at request time and return a flat
`SymbolInformation` list when hierarchical support is absent, falling
back to the existing nested `DocumentSymbol` response for clients like
VS Code that support it. The flat list is produced by recursively
unwrapping the symbol tree, preserving dotted container names
(e.g. `Outer.Inner`) so clients can still display symbol hierarchy
contextually.
@Arths17
Copy link
Copy Markdown
Contributor

Arths17 commented May 24, 2026

Good direction overall this correctly restores symbol visibility for non-hierarchical clients like Helix.

I think the key thing to validate is that flattening is purely a presentation-layer transformation and does not leak back into any semantic symbol resolution logic.

If that separation holds, this is a clean compatibility fix. Might be worth adding a regression test for mixed-capability clients (hierarchical true vs false) to ensure identical symbol sets, just different shapes.

@yangdanny97
Copy link
Copy Markdown
Contributor

Is this flattened representation part of the LSP & supported in other editors that don't support hierarchical document symbols, or is this something specific to Helix?

I'm not sure what impact (if any) there is on other editors

I'll let @kinto0 make the call here

Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

looks great! thanks for working on it. I'd like a few more tests like lsp_interaction tests to make sure the behavior works end-to-end. and is there a way to make every document_symbols test test both flat + nested symbols? then we won't need to add any new tests

return Err(EmptyResponseReason::LanguageServicesDisabled);
}
let Some(true) = self
let handle = self.make_handle_if_enabled(uri, Some(DocumentSymbolRequest::METHOD))?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: we should avoid making the handle if they don't have any support for any document symbols

result: &mut Vec<lsp_types::SymbolInformation>,
) {
for sym in symbols {
let children = sym.children.unwrap_or_default();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you double check there's no better way to flatten DocumentSymbols through the lsp_types library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document symbol search not working on helix

4 participants