Skip to content

Add a workaround for forcing keepWhitespace=true for snippet edits from the server - #6121

Merged
DanTup merged 2 commits into
masterfrom
fix-snippet-keep-whitespace
Jul 16, 2026
Merged

DanTup merged 2 commits into
masterfrom
fix-snippet-keep-whitespace

Conversation

@DanTup

@DanTup DanTup commented Jul 15, 2026

Copy link
Copy Markdown
Member

Fixes #6120

@DanTup DanTup added this to the v3.140.0 milestone Jul 15, 2026
@DanTup DanTup added is bug fix in editor Relates to code editing or language features labels Jul 15, 2026
@DanTup
DanTup requested a review from Copilot July 15, 2026 18:35

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a custom implementation of asWorkspaceEdit (named asWorkspaceEditWithKeepWhitespaceSnippets) in the LSP analyzer to ensure keepWhitespace is set to true on SnippetTextEdits, preventing VS Code from altering indentation. It also updates related tests to accommodate these changes. The review feedback highlights two important issues: first, SnippetTextEdit.snippet is a string in the LSP specification, meaning edit.snippet.value will evaluate to undefined; second, the item parameter in asCodeAction should be typed as ls.CodeAction | undefined | null to match the p2c.asCodeAction signature and prevent TypeScript compilation errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/extension/analysis/analyzer.ts
Comment thread src/extension/analysis/analyzer.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

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 introduces a client-side workaround in the Dart-Code VS Code extension to ensure snippet-based workspace edits preserve indentation by forcing keepWhitespace=true on SnippetTextEdits converted from LSP responses, addressing the whitespace regression described in #6120.

Changes:

  • Overrides the LSP client’s internal protocol-to-code workspace edit conversion to set SnippetTextEdit.keepWhitespace = true.
  • Routes code actions’ edit conversion through the custom workspace edit converter.
  • Adjusts an assist code action provider test to account for legacy vs new snippet edit behaviors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/extension/analysis/analyzer.ts Adds a custom workspace edit converter to force keepWhitespace=true for snippet edits and wires it into code action conversion.
src/test/flutter/providers/assist_code_action_provider.test.ts Updates the snippet-related test to handle legacy vs inline-edit code action results.
src/extension/analysis/analyzer_snippet_text_edits.ts Minor whitespace-only cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/extension/analysis/analyzer.ts Outdated
Comment thread src/extension/analysis/analyzer.ts
Comment thread src/test/flutter/providers/assist_code_action_provider.test.ts
Comment thread src/extension/analysis/analyzer.ts Outdated
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.11%. Comparing base (e86e12a) to head (8219b6e).

Files with missing lines Patch % Lines
src/extension/analysis/analyzer.ts 44.44% 13 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6121      +/-   ##
==========================================
- Coverage   71.18%   71.11%   -0.07%     
==========================================
  Files         170      170              
  Lines       13096    13124      +28     
  Branches     2633     2642       +9     
==========================================
+ Hits         9322     9333      +11     
- Misses       3263     3274      +11     
- Partials      511      517       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DanTup
DanTup merged commit 3bc2864 into master Jul 16, 2026
24 of 25 checks passed
@DanTup
DanTup deleted the fix-snippet-keep-whitespace branch July 16, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in editor Relates to code editing or language features is bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a workaround for SnippetTextEdit.keepWhitespace not being available in LSP

2 participants