Skip to content
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

[vscode] Support keepWhitespace in SnippetTextEdit and insertSnippet #15176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rschnekenbu
Copy link
Contributor

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

  1. install the following exension in the browser or electron example:
  1. in a text file, insert text edits using the 3 following commands from the command palette on lines with different indentations:
  • "Insert Snippet - keepWhitespace True",
  • "Insert Snippet - keepWhitespace False"
  • "Insert Snippet - keepWhitespace Undefined".
    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

export function toMonacoWorkspaceEdit(data: WorkspaceEditDto | undefined): monaco.languages.WorkspaceEdit {
, in the case of a WorkspaceTextEditDto, the returned Monaco type IWorkspaceTextEdit also supports this keepWhitespace parameter.

Sample video:

2025-03-12.16-31-53.mp4

Follow-ups

None

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Contributed on behalf of STMicroelectronics

Review checklist

Reminder for reviewers

fixes #15131

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting on reviewers
Development

Successfully merging this pull request may close these issues.

[vscode] SnippetTextEdit now has an optional keepWhitespace property
1 participant