You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Skip TextEdit when document already formatted (#3864)
* Initial plan
* Fix: Return empty edits when document is already formatted
This change prevents returning unnecessary TextEdits when the formatted
output is identical to the source document. This could potentially fix
issues where empty lines appear to be added to files during formatting.
The minimalEdit function now:
1. Checks if the document text is identical to the formatted result
2. Returns null if no changes are needed
3. The provideEdits function returns an empty array when no edit is needed
This ensures VS Code doesn't apply empty TextEdits which could cause
unexpected behavior with line endings or cursor positioning.
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
* Add logging for when document is already formatted
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
* Address code review feedback
- Fix countTrailingNewlines to use continue instead of break for \r
- Clarify condition in forceFormatDocument to check > 1 instead of !== 1
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
* Update warning message to reflect that 0 edits is valid
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
* Update CHANGELOG.md with fix for unnecessary TextEdits
Added changelog entry documenting the fix for issue #3232 where
unnecessary TextEdits were applied when document was already formatted.
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
* Fix test to format via extension twice for idempotency
Updated the markdown test to call format() twice instead of calling
format() once and prettier.format() once. This better reproduces the
original bug where formatting via the extension multiple times would
add spurious empty lines.
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Co-authored-by: Nathan Totten <nate@zuplo.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ All notable changes to the "prettier-vscode" extension will be documented in thi
14
14
- Fixed parser detection fallback when using plugins with Prettier v3
15
15
- Added new Prettier v3 options: `objectWrap`, `experimentalOperatorPosition`
16
16
- Added support for TypeScript config files (`.prettierrc.ts`, `.prettierrc.cts`, `.prettierrc.mts`, `prettier.config.ts`, etc.) introduced in Prettier 3.5.0 - Thanks to [@dr2009](https://github.com/dr2009)
17
+
- Fixed issue where unnecessary TextEdits were applied when document was already formatted, which could cause spurious changes or cursor positioning issues (#3232)
0 commit comments