-
Notifications
You must be signed in to change notification settings - Fork 35
Fix boolean literal highlighting in switch expression when clauses #352
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
base: main
Are you sure you want to change the base?
Conversation
- Add test case for boolean literals (true/false) in switch expression when clauses - Fix anonymous-method-expression pattern to exclude boolean and null keywords - This ensures true/false are correctly classified as constant.language.boolean instead of parameter names Co-authored-by: JoeRobich <[email protected]>
src/csharp.tmLanguage.yml
Outdated
| ((?:\b(?:async|static)\b\s*)*) | ||
| (?: | ||
| (@?[_[:alpha:]][_[:alnum:]]*)\b| | ||
| (?!\b(?:true|false|null)\b)(@?[_[:alpha:]][_[:alnum:]]*)\b| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot we shouldn't update the anonymous-method-express. true and false are literal expressions. Perhaps we should move literal higher in the list of expression patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e2ff38b. Moved #boolean-literal and #null-literal before #anonymous-method-expression in the expression patterns list. I kept the rest of #literal (including #tuple-literal) in its original position to avoid breaking lambda expressions with parenthesized parameters like (x, y) =>.
Instead of modifying the anonymous-method-expression pattern, move #boolean-literal and #null-literal higher in the expression patterns list to ensure they are matched before lambda expressions. This prevents true/false/null from being incorrectly interpreted as lambda parameter names while preserving all lambda expression functionality. Co-authored-by: JoeRobich <[email protected]>
Boolean literals (
true,false) andnullin switch expressionwhenclauses were being tokenized as lambda parameter names instead of their respective literal types.Changes
#boolean-literaland#null-literalpatterns before#anonymous-method-expressionin the expression patterns list to ensure these literal expressions are matched before lambda parameter detectionwhenclausesThe fix prioritizes boolean and null literal matching while preserving lambda expression functionality by keeping other literal patterns (like
#tuple-literal) in their original positions.Example
Before this fix,
trueandfalsein the following code were incorrectly highlighted as parameter names:The lambda expression pattern was matching
<identifier> =>patterns before the grammar could recognize boolean keywords as literals.Original prompt
whenclause ofswitchstatement #321💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.