Skip to content

Rank __init__.py results lower in workspace symbol search#2899

Open
yslim-030622 wants to merge 1 commit intofacebook:mainfrom
yslim-030622:rank-init-lower-in-workspace-symbols
Open

Rank __init__.py results lower in workspace symbol search#2899
yslim-030622 wants to merge 1 commit intofacebook:mainfrom
yslim-030622:rank-init-lower-in-workspace-symbols

Conversation

@yslim-030622
Copy link

Summary

Fixes #2465

When a symbol is re-exported from __init__.py, workspace symbol search currently surfaces both the __init__.py re-export and the original definition at equal priority. This means users often land on the re-export rather than the actual definition.

This PR applies a single stable sort pass at the workspace symbol response site to push __init__.py results after non-__init__.py results, while keeping both visible. The fuzzy relevance ordering within each group is preserved (Rust's sort_by_key is a stable sort).

Scope: workspace symbol response path only (workspace_symbols.rs). No changes to fuzzy matching, go-to-definition, shared export search logic, dedup behavior, or any other LSP feature.

Changes

  • pyrefly/lib/lsp/non_wasm/workspace_symbols.rs: add a stable sort by is_init() after assembling the result list, with a single comment explaining the invariant.
  • pyrefly/lib/test/lsp/lsp_interaction/workspace_symbol.rs: add regression test test_workspace_symbol_prefers_non_init_result that opens both an implementation module and its package __init__.py, queries for the shared symbol, and asserts the ordering invariant holds.
  • pyrefly/lib/test/lsp/lsp_interaction/test_files/tests_requiring_config/workspace_symbol_prefer_non_init/: minimal fixture package with one definition in implementation.py and one re-export in __init__.py.

Test Plan

  • New LSP interaction test covers the ordering invariant end-to-end.
  • python3 test.py --no-test --no-conformance (fmt + lint) passes with no new errors introduced.
  • Targeted test: cargo test workspace_symbol

@meta-cla
Copy link

meta-cla bot commented Mar 25, 2026

Hi @yslim-030622!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla bot added the cla signed label Mar 25, 2026
@meta-cla
Copy link

meta-cla bot commented Mar 25, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@kinto0 kinto0 self-assigned this Mar 26, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 26, 2026

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D98230779.

Copy link
Member

@samwgoldman samwgoldman left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

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.

rank items from __init__.py lower in symbol search

3 participants