Skip to content

Expose formatNodeForInsertion in internal API#3515

Open
andrewbranch wants to merge 2 commits intomicrosoft:mainfrom
andrewbranch:api/formatting
Open

Expose formatNodeForInsertion in internal API#3515
andrewbranch wants to merge 2 commits intomicrosoft:mainfrom
andrewbranch:api/formatting

Conversation

@andrewbranch
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 22, 2026 21:55
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 exposes a new internal API endpoint to format a synthesized AST node with the correct indentation for insertion at a given position in an existing file, and factors out shared “synthetic source file” construction logic into the printer package.

Changes:

  • Added formatNodeForInsertion request handling to the Go internal API and protocol schema.
  • Introduced reusable printer helpers for printing/positioning a synthetic node and wrapping it in a synthetic SourceFile.
  • Exposed the functionality in the native-preview TS client (snapshot.internal.formatNodeForInsertion) and added sync/async tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
internal/printer/syntheticfile.go New shared helpers to print+position synthetic nodes and create a synthetic SourceFile for formatting.
internal/ls/completions.go Replaces local synthetic file creation with printer.CreateSyntheticSourceFile.
internal/ls/change/trackerimpl.go Replaces duplicated print/position/synthetic-file logic with new printer helpers.
internal/api/session.go Adds request routing + handler implementing formatNodeForInsertion.
internal/api/proto.go Adds method constant, unmarshaler entry, and request params type.
_packages/native-preview/src/api/sync/api.ts Adds Snapshot.internal and sync InternalAPI.formatNodeForInsertion.
_packages/native-preview/src/api/async/api.ts Adds Snapshot.internal and async InternalAPI.formatNodeForInsertion.
_packages/native-preview/test/sync/api.test.ts Adds sync tests covering indentation behavior.
_packages/native-preview/test/async/api.test.ts Adds async tests covering indentation behavior.

Comment thread _packages/native-preview/src/api/async/api.ts Outdated
Comment thread internal/api/session.go Outdated
Comment thread _packages/native-preview/test/sync/api.test.ts
Comment thread _packages/native-preview/test/async/api.test.ts
Comment thread internal/api/proto.go
Comment thread _packages/native-preview/src/api/sync/api.ts Outdated
…on-ASCII tests

- Convert UTF-16 position to UTF-8 in handleFormatNodeForInsertion using
  the target file's PositionMap, consistent with other API endpoints
- Update @param doc comments in sync/async TS APIs to say 'UTF-16 code-unit offset'
- Update Go proto comment to say 'UTF-16 code-unit offset'
- Add non-ASCII test cases to sync and async test suites to verify correct
  UTF-16→UTF-8 position conversion when non-ASCII chars precede insertion point

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

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