Skip to content

Preserve encoding during DocumentState updates #77354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

sharwell
Copy link
Contributor

Fixes dotnet/sdk#46780

This issue was introduced by #74623, which changed Document.WithSyntaxRoot to always use the encoding specified by the new syntax root. APIs like SyntaxRewriter do not preserve the input encoding during node rewrites, so Formatter.Format would overwrite the document syntax root with a node that did not specify any encoding. The fix allows WithSyntaxRoot to specify a new encoding, but for cases where the encoding of the new syntax root is not known, we fall back to the original behavior of preserving the encoding from the previous root and/or document text.

@sharwell sharwell requested a review from a team as a code owner February 26, 2025 21:24
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 26, 2025
Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

Nice one! Pretty sure this would have made #76736 unnecessary.

@sharwell sharwell merged commit 94cbd0b into dotnet:main Feb 27, 2025
25 checks passed
@sharwell sharwell deleted the preserve-encoding branch February 27, 2025 01:42
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Feb 27, 2025
@sharwell
Copy link
Contributor Author

/backport to release/dev17.14

@sharwell
Copy link
Contributor Author

/backport to release/dev17.13

Copy link
Contributor

Started backporting to release/dev17.14: https://github.com/dotnet/roslyn/actions/runs/13557096207

Copy link
Contributor

Started backporting to release/dev17.13: https://github.com/dotnet/roslyn/actions/runs/13557097339

sharwell added a commit that referenced this pull request Feb 27, 2025
…7362)

Backport of #77354 to release/dev17.13

/cc @sharwell

## Customer Impact

## Regression

- [ ] Yes
- [ ] No

[If yes, specify when the regression was introduced. Provide the PR or
commit if known.]

## Testing

[How was the fix verified? How was the issue missed previously? What
tests were added?]

## Risk

[High/Medium/Low. Justify the indication by mentioning how risks were
measured and addressed.]
JoeRobich added a commit to dotnet/vscode-csharp that referenced this pull request Mar 8, 2025
* Don't use an implicit-object if the lang version doesn't support it (PR: [#77437](dotnet/roslyn#77437))
* Fix issue where we were changing semantics when converting to a collection expr. (PR: [#77417](dotnet/roslyn#77417))
* Detect and emit more idiomatic null check patterns (PR: [#77412](dotnet/roslyn#77412))
* Partial events and constructors: IDE (PR: [#77337](dotnet/roslyn#77337))
* Simplify keyword recommenders. (PR: [#77396](dotnet/roslyn#77396))
* Remove async/await (PR: [#77397](dotnet/roslyn#77397))
* Preserve encoding during DocumentState updates (PR: [#77354](dotnet/roslyn#77354))
* Don't realize the SourceText in SyntaxTree.OverlapsHiddenPosition if not needed (PR: [#77334](dotnet/roslyn#77334))
* Handle ModuleCancellationTokenExpression in AbstractFlow visitor (PR: [#77310](dotnet/roslyn#77310))
* PERF: Reduce the number of nodes walked during import completion commit. (PR: [#77305](dotnet/roslyn#77305))
* Allow expression body refactorings on non empty selections (PR: [#76969](dotnet/roslyn#76969))
* Partial events and constructors: public API (PR: [#77202](dotnet/roslyn#77202))
* Refresh diagnostics when fading options change (PR: [#77322](dotnet/roslyn#77322))
* Reduce allocations during completion in FilterToVisibleAndBrowsableSymbols (PR: [#77315](dotnet/roslyn#77315))
* Change override completion to select text after updating the buffer. (PR: [#76983](dotnet/roslyn#76983))
* Fix false positive 'Unnecessary assignment of a value' (PR: [#77297](dotnet/roslyn#77297))
@jjonescz jjonescz modified the milestones: Next, 17.14 P3 Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet format throws because it can't determine file encodings in 9.0.200
5 participants