Find all references API endpoints#3846
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds native API endpoints and TypeScript client wrappers for find-all-references-related operations, bridging checker/language-service reference data into the native-preview API.
Changes:
- Adds exported LS/checker helpers for reference entries, symbol references, and signature usage lookup.
- Registers new API protocol methods and session handlers for reference/signature usage requests.
- Adds async and generated sync native-preview client methods plus a
SignatureUsageinterface.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
internal/ls/findallreferences.go |
Exposes reference entry accessors and adds referenced-symbol/signature-usage helpers. |
internal/checker/services.go |
Adds a checker helper to collect symbol references within a file. |
internal/api/session.go |
Wires new request methods to checker/LS-backed handlers. |
internal/api/proto.go |
Defines new protocol method constants, unmarshalers, params, and responses. |
_packages/native-preview/src/api/async/api.ts |
Adds async client wrappers and SignatureUsage type. |
_packages/native-preview/src/api/sync/api.ts |
Adds generated sync equivalents for the new client wrappers. |
Comments suppressed due to low confidence (2)
_packages/native-preview/src/api/async/api.ts:534
- The public method name is singular even though it returns an array and calls the plural getSignatureUsages endpoint. This makes the API inconsistent with the Go handler/type names and can confuse consumers; consider naming it getSignatureUsages before publishing the endpoint.
async getSignatureUsage(file: DocumentIdentifier, signatureDecl: Node): Promise<SignatureUsage[]> {
_packages/native-preview/src/api/sync/api.ts:542
- The generated sync API exposes the same singular getSignatureUsage name while returning SignatureUsage[]. If the async source is renamed to getSignatureUsages, regenerate this file so the sync API stays consistent.
getSignatureUsage(file: DocumentIdentifier, signatureDecl: Node): SignatureUsage[] {
|
|
||
| // IsNodeEntry returns true if this is a node-backed reference entry. | ||
| func (e *ReferenceEntry) IsNodeEntry() bool { | ||
| return e.kind == entryKindNode |
| return (data ?? []).map(h => new NodeHandle(h)); | ||
| } | ||
|
|
||
| async getReferencedSymbolsForNode(file: DocumentIdentifier, node: Node, position: number): Promise<NodeHandle[]> { |
There was a problem hiding this comment.
I intentionally did this for simplicity. Do you want this to change @andrewbranch ?
There was a problem hiding this comment.
Yes, I think the SymbolAndEntries info is valuable, so I would include it all. It also makes the name make more sense.
| return (data ?? []).map(h => new NodeHandle(h)); | ||
| } | ||
|
|
||
| getReferencedSymbolsForNode(file: DocumentIdentifier, node: Node, position: number): NodeHandle[] { |
|
|
||
| // Reference methods | ||
| MethodGetReferencesToSymbolInFile Method = "getReferencesToSymbolInFile" | ||
| MethodGetReferencedSymbolsForNode Method = "getReferencedSymbolsForNode" |
| } | ||
|
|
||
| usages := langSvc.GetSignatureUsages(ctx, signatureDecl) |
|
|
||
| sourceFiles := setup.program.GetSourceFiles() | ||
| entries := langSvc.GetReferencedSymbolsForNode(ctx, params.Position, node, sourceFiles) |
| for _, entry := range entries { | ||
| for _, ref := range entry.References() { | ||
| if !ref.IsNodeEntry() { | ||
| continue | ||
| } |
There was a problem hiding this comment.
This is handled on the client side, so I think it's safe to skip.
There was a problem hiding this comment.
I think the Copilot suggestion makes sense. The method should either return all declarations or none, and the name kind of implies none.
| case string(MethodGetReferencesToSymbolInFile): | ||
| return s.handleGetReferencesToSymbolInFile(ctx, parsed.(*GetReferencesToSymbolInFileParams)) | ||
| case string(MethodGetReferencedSymbolsForNode): | ||
| return s.handleGetReferencedSymbolsForNode(ctx, parsed.(*GetReferencedSymbolsForNodeParams)) | ||
| case string(MethodGetSignatureUsages): |
| type GetReferencedSymbolsForNodeParams struct { | ||
| Snapshot Handle[project.Snapshot] `json:"snapshot"` | ||
| Project Handle[project.Project] `json:"project"` | ||
| File DocumentIdentifier `json:"file"` |
| type GetSignatureUsagesParams struct { | ||
| Snapshot Handle[project.Snapshot] `json:"snapshot"` | ||
| Project Handle[project.Project] `json:"project"` | ||
| File DocumentIdentifier `json:"file"` |
|
|
||
| // ReferencedSymbolEntry represents a symbol definition and its references. | ||
| type ReferencedSymbolEntry struct { | ||
| Definition Handle[ast.Node] `json:"definition"` |
There was a problem hiding this comment.
I would expect to be able to get the symbol here in addition to the node.
No description provided.