Fix var keyword tokenization in tuple deconstruction at top level #356
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 an issue where
varkeywords were not being correctly tokenized in tuple deconstruction patterns at the top level (outside of methods), causing them to appear as regular variables instead of type keywords.Problem
When using tuple deconstruction with
varkeywords at the top level:The
varkeywords were being tokenized asvariable.other.readwrite.cs(regular variables) instead ofstorage.type.var.cs(type keyword), preventing them from being highlighted correctly in the editor.Root Cause
The
local-tuple-var-deconstructionpattern only matchedvar (x, y) = ...syntax but not(var x, var y) = ...syntax at the statement level. When at the top level, the parenthesized expression pattern would match first and treatvaras an identifier.Solution
Added a new
local-tuple-declaration-deconstructionpattern to the grammar that:(type/var id, type/var id) = ...tuple-declaration-deconstruction-element-listto properly handlevarkeywordslocal-declarationso it's checked before general expression patternsChanges
local-tuple-declaration-deconstructionpattern insrc/csharp.tmLanguage.ymlInput.InMethodandInput.FromTextscenarios for:(int _, var _) = (1, 2);(var _, var _, var _) = ('a', 'b', 'c');All 897 tests pass. The
varkeyword is now correctly tokenized asstorage.type.var.csat both method and top levels.Original prompt
varin tuple deconstruction #316✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.