Skip to content

Add getSymbolOfSourceFile to the API - #4791

Open
dragomirtitian wants to merge 2 commits into
microsoft:mainfrom
dragomirtitian:add-get-symbol-of-source-file
Open

Add getSymbolOfSourceFile to the API#4791
dragomirtitian wants to merge 2 commits into
microsoft:mainfrom
dragomirtitian:add-get-symbol-of-source-file

Conversation

@dragomirtitian

Copy link
Copy Markdown
Contributor

In our build tool we have a use case where we just walk over the exported symbols of a module to find all the ways a symbol can be accessed. In this case we don't really need the AST to be present on the JS side. Currently the only way to get the symbol for a file is to first have the SourceFile object using getSourceFile. But this triggers the transfer of the AST information which will be unused.

This PR adds a dedicated getSymbolOfSourceFile method that lets us get the symbol bypassing the SourceFile object

Alternate solution: getSymbolAtPosition currently never returns the symbol for the whole file. We could just change getSymbolOfSourceFile to allow undefined for the position parameter and then it would return the symbol for the file itself.

Copilot AI review requested due to automatic review settings July 29, 2026 17:50

Copilot AI left a comment

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.

Pull request overview

Adds direct source-file symbol lookup without transferring AST data to JavaScript clients.

Changes:

  • Adds single and batched protocol handlers.
  • Exposes synchronous and asynchronous checker APIs.
  • Adds module, script, and batching tests.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/api/session.go Implements request handlers.
internal/api/proto.go Defines methods and parameters.
internal/api/session_temporary_test.go Updates diagnostic test parameters.
_packages/native-preview/src/api/sync/api.ts Adds synchronous checker API.
_packages/native-preview/src/api/async/api.ts Adds asynchronous checker API.
_packages/native-preview/test/sync/api.test.ts Tests synchronous behavior.
_packages/native-preview/test/async/api.test.ts Tests asynchronous behavior.
Comments suppressed due to low confidence (3)

internal/api/session_temporary_test.go:76

  • GetDiagnosticsParams has no Files field; this causes a compile error. Use its File *DocumentIdentifier field for the temporary file.
		Files:    []DocumentIdentifier{{FileName: fileName}},

internal/api/session_temporary_test.go:85

  • This references a nonexistent Files field on GetDiagnosticsParams, preventing the test package from compiling. Restore the pointer-valued File field.
		Files:    []DocumentIdentifier{{FileName: fileName}},

internal/api/session_temporary_test.go:97

  • GetDiagnosticsParams only defines File *DocumentIdentifier; using Files here is a compile error. Restore the single-file parameter.
		Files:    []DocumentIdentifier{{FileName: fileName}},

Comment thread internal/api/session_temporary_test.go Outdated
@dragomirtitian
dragomirtitian force-pushed the add-get-symbol-of-source-file branch from 8ef2f80 to 8881c67 Compare July 29, 2026 18:06
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.

2 participants