-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Trim Trailing Whitespace shouldn't affect multiline strings #195010
Comments
+1 — I am running into this as well. I'm writing a test for a function that is expected to handle user input (multiline string) and format it, and I need to test the behavior when there are trailing spaces. I can save the file without formatting, but that's a bit hard to maintain. |
When working with extensive files and many members, this issue can be quite annoying. Adding an option to enable/disable this behavior would provide more control within the workspace scope. |
This is particularly bad when writing tests for parsers and other things where the string content is extremely important. I generally do want to have my trailing whitespace trimmed, but if it can be known syntactically (ie, from VSCode's grammar files, involving no LSP) that the current location is inside a string, VSCode should be able to avoid trimming the trailing content. |
* Do not trim whitespace when part of strings or regexes Fixes #195010. If the token to be removed is part of a string or a regex, then we do not want to remove the character, as it is very likely semantically important. * Address initial feedback: 1. Add a new setting to control whether to trim whitespace in multiline strings/regexes. This setting is then piped through to everywhere that is calling trim whitespace, which is file save editing, the trim whitespace command, and notebooks. 2. Force line tokenization to complete when the setting is enabled so that trim is accurate. * Don't force tokenization; instead, check to see if there are tokens for a given line and do not format if there are none. * Look for syntactical tokens * Fix compilation errors * Add a test --------- Co-authored-by: Alex Dima <alexdima@microsoft.com>
) * Do not trim whitespace when part of strings or regexes Fixes microsoft#195010. If the token to be removed is part of a string or a regex, then we do not want to remove the character, as it is very likely semantically important. * Address initial feedback: 1. Add a new setting to control whether to trim whitespace in multiline strings/regexes. This setting is then piped through to everywhere that is calling trim whitespace, which is file save editing, the trim whitespace command, and notebooks. 2. Force line tokenization to complete when the setting is enabled so that trim is accurate. * Don't force tokenization; instead, check to see if there are tokens for a given line and do not format if there are none. * Look for syntactical tokens * Fix compilation errors * Add a test --------- Co-authored-by: Alex Dima <alexdima@microsoft.com>
This is regarding the
files.trimTrailingWhitespace
setting.While it is possible to set it to False for specific files e.g. markdown, there often cases where we have multiline strings in a code file.
for example:
When
files.trimTrailingWhitespace
is set to True, it would remove the two whitespaces after Line1, which breaks their markdown rendering as two separate lines.Would be great to have this setting ignore multilines strings.
The text was updated successfully, but these errors were encountered: