[vscode] Support keepWhitespace in SnippetTextEdit and insertSnippet #15176
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.
What it does
This introduces the support of the keepWhitespace optional value added in the TextEditor.insertSnippet API and SnippetTextEdit.
fixes #15131
How to test
These 3 commands will add 2 lines of text with 2 spaces at the beginning of each line. The keep whitespace parameter keeps or not the indentation at the beginning of the line. If you insert the text on an already indented line, 4 in video example, the insert with keepwhitespace parameter being true or false will behave differently. The second line will have a different indentation based on the parameter. If keepWhitespace is true, the second line will only have the spaces has defined in the snippet (2 in the extension case). If false or undefined, it will have snippet indentation (2) + current line indentation (4 in the video example) . The behavior is similar with the one on vscode.
Note: this only tests the insertSnippet() parameter addition.
The SnippetTextEdit keepWhiteSpace property is simply passed from the extension to the main, and transformed directly to equivalent monaco type.
When looking at
theia/packages/plugin-ext/src/main/browser/languages-main.ts
Line 1415 in 5e851cd
Sample video:
2025-03-12.16-31-53.mp4
Follow-ups
None
Breaking changes
Attribution
Contributed on behalf of STMicroelectronics
Review checklist
Reminder for reviewers