Expose formatNodeForInsertion in internal API#3515
Open
andrewbranch wants to merge 2 commits intomicrosoft:mainfrom
Open
Expose formatNodeForInsertion in internal API#3515andrewbranch wants to merge 2 commits intomicrosoft:mainfrom
andrewbranch wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
formatNodeForInsertionrequest 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. |
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.