Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 20, 2025

Fixes an issue where var keywords 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 var keywords at the top level:

(int _, var _) = (1, 2);
(var _, var _, var _) = ('a', 'b', 'c');

The var keywords were being tokenized as variable.other.readwrite.cs (regular variables) instead of storage.type.var.cs (type keyword), preventing them from being highlighted correctly in the editor.

Root Cause

The local-tuple-var-deconstruction pattern only matched var (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 treat var as an identifier.

Solution

Added a new local-tuple-declaration-deconstruction pattern to the grammar that:

  • Matches tuple deconstruction with type/var declarations: (type/var id, type/var id) = ...
  • Uses tuple-declaration-deconstruction-element-list to properly handle var keywords
  • Is included in local-declaration so it's checked before general expression patterns

Changes

  • Grammar fix: Added local-tuple-declaration-deconstruction pattern in src/csharp.tmLanguage.yml
  • Test coverage: Added 4 test cases covering both Input.InMethod and Input.FromText scenarios for:
    • Mixed type and var: (int _, var _) = (1, 2);
    • Multiple vars with discards: (var _, var _, var _) = ('a', 'b', 'c');

All 897 tests pass. The var keyword is now correctly tokenized as storage.type.var.cs at both method and top levels.

Original prompt

This section details on the original issue you should resolve

<issue_title>var in tuple deconstruction</issue_title>
<issue_description>## Details

What editor are you seeing the problem in? (e.g. Atom, Visual Studio Code, etc.)
vscode
What version of the editor are you using?
1.86.1
What color theme are you using?
dark plus

Repro

(int _, var _) = (1, 2);
(var _, var _, var _) = ('a', 'b', 'c');

code

Please provide a code example and (optionally) a screenshot demonstrating the problem.</issue_description>

<agent_instructions>From the example, it appears that var is not being classified in tuple deconstruction</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix var classification in tuple deconstruction Add test coverage for var in tuple deconstruction with discards Dec 20, 2025
Copilot AI requested a review from JoeRobich December 20, 2025 02:36
Add local-tuple-declaration-deconstruction pattern to handle tuple deconstruction with type/var declarations like (int x, var y) = ... at the statement level. This fixes the issue where var was incorrectly tokenized as a variable name instead of a keyword when used in top-level tuple deconstruction.

Co-authored-by: JoeRobich <[email protected]>
Copilot AI changed the title Add test coverage for var in tuple deconstruction with discards Fix var keyword tokenization in tuple deconstruction at top level Dec 20, 2025
Copilot AI requested a review from JoeRobich December 20, 2025 03:07
@JoeRobich JoeRobich marked this pull request as ready for review December 20, 2025 03:20
@JoeRobich JoeRobich requested a review from dibarbet December 20, 2025 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

var in tuple deconstruction

2 participants