Repository navigation
Skip a preprocessor line's text when looking for verbatim strings [patch] - #195
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
…tch] The compiler does not tokenize the text after #region, #error, #warning or #pragma, but VerbatimStringScanner did: an @" in a region name opened a verbatim string that never closed, so SplitLines stopped splitting and every later line in the member lost its indent. At the top level, a line whose first non-whitespace character is # is now skipped to its line break, without recording a comment start. A # inside a verbatim literal, inside an interpolation hole, or mid-line starts nothing. Fixes #194 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017vfJW677dmfMN4vzuGiiZH
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Fixes #194
Problem
The compiler does not tokenize the text after
#region,#endregion,#error,#warningor#pragma, butVerbatimStringScannerdid. An@"(or$@"/@$") in that free text opened a "verbatim string" that never closed inside the fragment.SplitLinesthen stopped splitting, so every later line of the member kept its own buffer's indentation, and an extra blank line appeared before the class's}.Change
ScanCodenow tracks whether only whitespace has been seen since the last line break. At the top level, a line whose first non-whitespace character is#is skipped to its line break, the waySkipLineCommentdoes, without recording a comment start. The line break is left to the code around it. The check never applies:#is still left untouched (Template bodies re-indent every line of a multi-line verbatim string, silently changing the generated string's value #121 behaviour),#mid-line.The new logic sits in two small helpers (
TrySkipNonCode,TrySkipPreprocessorLine), soScanCodestays under Sonar's S3776 limit. The local Sonar run (.sonarlint/sonar-local.props) reports nothing new.Tests
TemplateTests.RegionNameWithAVerbatimPrefixKeepsTheMemberIndented: the issue'sClassTemplate/RegionScoperepro, which now gives the expected output.WriteLinesTests.IndentsEveryLineAfterAVerbatimPrefixInADirective:WriteLines("#region Handles @\" prefixes\nint a;\nint b;\n#endregion\n")indents all four lines.SplitLinesTestsdata rows for#region, an indented#errorwith$@",#warningwith@$", and#pragmawith a comment. Further rows check that a verbatim literal spanning#-led lines stays whole and that a mid-line#starts nothing.Generated by Claude Code