Skip to content

Find all references API endpoints#3846

Open
navya9singh wants to merge 8 commits into
mainfrom
navyasingh/findAllReferencesApiEndpoints
Open

Find all references API endpoints#3846
navya9singh wants to merge 8 commits into
mainfrom
navyasingh/findAllReferencesApiEndpoints

Conversation

@navya9singh
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 14, 2026 18:26
@navya9singh navya9singh requested a review from andrewbranch May 14, 2026 20:26
Comment thread internal/api/proto.go Outdated
Comment thread _packages/native-preview/src/api/sync/api.ts Outdated
@andrewbranch andrewbranch requested review from Copilot and removed request for Copilot May 15, 2026 18:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 SignatureUsage interface.

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[] {

Comment thread internal/ls/findallreferences.go Outdated

// 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[]> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I intentionally did this for simplicity. Do you want this to change @andrewbranch ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I think the SymbolAndEntries info is valuable, so I would include it all. It also makes the name make more sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed it

return (data ?? []).map(h => new NodeHandle(h));
}

getReferencedSymbolsForNode(file: DocumentIdentifier, node: Node, position: number): NodeHandle[] {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed it.

Comment thread internal/api/proto.go

// Reference methods
MethodGetReferencesToSymbolInFile Method = "getReferencesToSymbolInFile"
MethodGetReferencedSymbolsForNode Method = "getReferencedSymbolsForNode"
Comment thread internal/api/session.go
Comment on lines +2141 to +2143
}

usages := langSvc.GetSignatureUsages(ctx, signatureDecl)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Any thoughts on this @andrewbranch?

Comment thread internal/api/session.go
Comment on lines +2181 to +2183

sourceFiles := setup.program.GetSourceFiles()
entries := langSvc.GetReferencedSymbolsForNode(ctx, params.Position, node, sourceFiles)
Comment on lines +890 to +894
for _, entry := range entries {
for _, ref := range entry.References() {
if !ref.IsNodeEntry() {
continue
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is handled on the client side, so I think it's safe to skip.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the Copilot suggestion makes sense. The method should either return all declarations or none, and the name kind of implies none.

Comment thread internal/api/session.go
Comment on lines +480 to +484
case string(MethodGetReferencesToSymbolInFile):
return s.handleGetReferencesToSymbolInFile(ctx, parsed.(*GetReferencesToSymbolInFileParams))
case string(MethodGetReferencedSymbolsForNode):
return s.handleGetReferencedSymbolsForNode(ctx, parsed.(*GetReferencedSymbolsForNodeParams))
case string(MethodGetSignatureUsages):
Comment thread internal/api/proto.go Outdated
type GetReferencedSymbolsForNodeParams struct {
Snapshot Handle[project.Snapshot] `json:"snapshot"`
Project Handle[project.Project] `json:"project"`
File DocumentIdentifier `json:"file"`
Comment thread internal/api/proto.go Outdated
type GetSignatureUsagesParams struct {
Snapshot Handle[project.Snapshot] `json:"snapshot"`
Project Handle[project.Project] `json:"project"`
File DocumentIdentifier `json:"file"`
@navya9singh navya9singh requested a review from andrewbranch May 15, 2026 21:29
Comment thread internal/api/proto.go

// ReferencedSymbolEntry represents a symbol definition and its references.
type ReferencedSymbolEntry struct {
Definition Handle[ast.Node] `json:"definition"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would expect to be able to get the symbol here in addition to the node.

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.

3 participants