Skip to content

Commit

Permalink
[C#] Standardize scope name for throwaway variables (sublimehq#3415)
Browse files Browse the repository at this point in the history
This commit assigns `variable.language.anonymous` to throwaway variables
which enables highlighting `_` special.

The scope is already used in Erlang, Go, Haskell, Java, Matlab & Python.

See also: SublimeText/ScopeNamingGuidelines#5
  • Loading branch information
jwortmann committed May 31, 2022
1 parent e73a3e9 commit 83a8f3e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions C#/C#.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ contexts:
- match: ':'
scope: keyword.operator.assignment.cs
- match: _\b
scope: variable.language.deconstruction.discard.cs
scope: variable.language.anonymous.cs
- match: (?!{{reserved}})(?={{namespaced_name}}{{type_suffix}}\s+{{name}}\s*[:,])
push: var_declaration_explicit
- match: '({{name}})(<)'
Expand Down Expand Up @@ -2075,7 +2075,7 @@ contexts:
pop: true
- include: line_of_code_in
- match: \b_\b
scope: variable.language.deconstruction.discard.cs
scope: variable.language.anonymous.cs
- match: '\bwhen\b'
scope: keyword.control.switch.case.when.cs
- match: \(
Expand All @@ -2088,7 +2088,7 @@ contexts:
- match: ','
scope: punctuation.separator.sequence.cs
- match: _\b
scope: variable.language.deconstruction.discard.cs
scope: variable.language.anonymous.cs
- include: line_of_code_in_no_semicolon # needed for "when" syntax?
- match: (?={{namespaced_name}}\s+(?:\{|(?!{{reserved}}|when\b){{name}}))
push: [maybe_pattern_matching_object, var_declaration]
Expand Down Expand Up @@ -2153,7 +2153,7 @@ contexts:
scope: meta.sequence.tuple.cs punctuation.section.sequence.end.cs
pop: true
- match: _\b
scope: variable.language.deconstruction.discard.cs
scope: variable.language.anonymous.cs
- match: '{{name}}'
scope: variable.other.cs
- match: ','
Expand Down
4 changes: 2 additions & 2 deletions C#/tests/syntax_test_C#7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ string Beta
/// ^^^^^^ storage.type
/// ^^^^ variable.other
/// ^ punctuation.separator.sequence
/// ^ variable.language.deconstruction.discard
/// ^ variable.language.anonymous
/// ^ punctuation.separator.sequence
/// ^^^^^^ storage.type
/// ^^^^ variable.other
Expand All @@ -436,7 +436,7 @@ string Beta
/// ^ punctuation.separator.sequence
/// ^^^^^^^^^^ variable.other
/// ^ punctuation.separator.sequence
/// ^ variable.language.deconstruction
/// ^ variable.language.anonymous
/// ^ punctuation.section.sequence.end
/// ^ keyword.operator.assignment
var (_, _, _, pop1, _, pop2) = QueryCityDataForYears("New York City", 1960, 2010);
Expand Down
8 changes: 4 additions & 4 deletions C#/tests/syntax_test_C#8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ vehicle switch
/// ^^ meta.method meta.block punctuation.separator.case-expression

_ => throw new ArgumentException("Not a known vehicle type", nameof(vehicle))
/// ^ variable.language.deconstruction.discard
/// ^ variable.language.anonymous
/// ^^ punctuation.separator.case-expression
};

Expand Down Expand Up @@ -239,11 +239,11 @@ public static string RockPaperScissors(string first, string second)
var (_, _) => Quadrant.OnBorder,
/// ^^^ storage.type.variable
/// ^^^^^^ meta.sequence.tuple
/// ^ variable.language.deconstruction.discard
/// ^ variable.language.anonymous
/// ^ punctuation.separator.sequence
/// ^ variable.language.deconstruction.discard
/// ^ variable.language.anonymous
_ => Quadrant.Unknown
/// ^ variable.language.deconstruction.discard
/// ^ variable.language.anonymous
/// ^^ punctuation.separator.case-expression
};
/// <- punctuation.section.block.end
Expand Down
4 changes: 2 additions & 2 deletions C#/tests/syntax_test_C#9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public record Student : Person { int ID; }
/// ^^ constant.numeric.value
/// ^^ punctuation.separator.case-expression
_ => "More than 10"
/// ^ variable.language.deconstruction.discard
/// ^ variable.language.anonymous
/// ^^ punctuation.separator.case-expression
} + ".";
/// <- punctuation.section.block.end
Expand Down Expand Up @@ -138,7 +138,7 @@ static bool CheckIfCanWalkIntoBank(Bank bank, bool isVip)
/// ^ punctuation.accessor.dot
/// ^^^^ variable.other
/// ^ punctuation.separator.sequence
/// ^ variable.language.deconstruction.discard
/// ^ variable.language.anonymous
/// ^ punctuation.section.sequence.end
/// ^^ punctuation.separator.case-expression
/// ^^^^ constant.language
Expand Down

0 comments on commit 83a8f3e

Please sign in to comment.