Skip to content

Resolve reference-like requests from the index for unopened files#2713

Open
rintaro wants to merge 1 commit into
swiftlang:mainfrom
rintaro:references-callhierarchy-index-usr
Open

Resolve reference-like requests from the index for unopened files#2713
rintaro wants to merge 1 commit into
swiftlang:mainfrom
rintaro:references-callhierarchy-index-usr

Conversation

@rintaro

@rintaro rintaro commented Jul 8, 2026

Copy link
Copy Markdown
Member

textDocument/references, textDocument/prepareCallHierarchy, textDocument/implementation, and textDocument/prepareTypeHierarchy previously resolved the symbol at the requested position via the document's language service (symbolInfo), which requires the document to be open. Invoked on a position in a file the editor hadn't opened, they returned nothing.

These requests now resolve the USR(s) at the requested position directly from the index when the document is not open. When the document is open we still prefer cursor info from the live buffer, which is more precise and also resolves local, non-indexed symbols. This matches the LSP model (on-disk contents are authoritative for a closed document). The shared resolution lives in a new usrsOfSymbol helper, and the resolved USRs are sorted and de-duplicated for deterministic results.

prepareTypeHierarchy no longer pre-filters the cursor-info symbols by kind; the existing filter on the index symbol kind is authoritative and applies to both resolution paths.

To support this, CheckedIndex gains symbolOccurrences(inFilePath:), returning up-to-date occurrences with their locations.

@rintaro rintaro force-pushed the references-callhierarchy-index-usr branch 3 times, most recently from 9a9e272 to b1e5917 Compare July 8, 2026 17:45
@rintaro

rintaro commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test

@rintaro rintaro force-pushed the references-callhierarchy-index-usr branch from b1e5917 to 2129b74 Compare July 8, 2026 18:31
@rintaro rintaro changed the title Resolve references and call hierarchy from the index for unopened files Resolve reference-like requests from the index for unopened files Jul 8, 2026
`references`, `prepareCallHierarchy`, `implementation`, and
`prepareTypeHierarchy` previously resolved the symbol at the requested
position by asking the document's language service for cursor info, which
requires the document to be open. As a result, these requests returned
nothing when invoked on a position in a file the editor hadn't opened —
the common case when Find References, Call Hierarchy, Jump to
Implementations, or Type Hierarchy targets a definition in another file.

Resolve the USR(s) at the requested position from the index when the
document is not open, falling back from the language service. Occurrence
locations are mapped to LSP positions using the file's on-disk contents
(via the snapshot-or-disk line table), so no language service or
sourcekitd document is needed. When the document is open we still prefer
cursor info from the live buffer, which is more precise and also resolves
local, non-indexed symbols. The shared resolution lives in a new
`usrsOfSymbol(at:in:workspace:index:)` helper, and the resolved USRs are
sorted and de-duplicated so results are deterministic.

`prepareTypeHierarchy` no longer pre-filters cursor-info symbols by kind;
the existing filter on the index symbol kind is authoritative and applies
to both resolution paths.

Add `CheckedIndex.symbolOccurrences(inFilePath:)`, which returns
up-to-date occurrences carrying their locations, to support this lookup.
@rintaro rintaro force-pushed the references-callhierarchy-index-usr branch from 2129b74 to 638e7f9 Compare July 8, 2026 18:37
@rintaro

rintaro commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test

@rintaro

rintaro commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test Windows

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.

1 participant