Skip to content
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

[C#] support class definitions without a body #4120

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions C#/C#.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,7 @@ contexts:
- match: \s*(;)
captures:
1: punctuation.terminator.statement.cs
pop: true

maybe_terminator:
- include: terminator
- match: (?=\S)
pop: true
pop: 1
michaelblyons marked this conversation as resolved.
Show resolved Hide resolved

delegate_end:
- include: terminator
Expand All @@ -477,6 +472,7 @@ contexts:

class_signature:
- meta_scope: meta.class.cs
- include: terminator
- match: (?=\S)
set: class_body

Expand Down Expand Up @@ -517,21 +513,24 @@ contexts:
data_type_expect_block:
- match: \{
scope: punctuation.section.block.begin.cs
push:
- meta_scope: meta.block.cs
- match: \}
scope: punctuation.section.block.end.cs
pop: 2
- include: attribute
- include: class_declaration
- include: interface_declaration
- include: delegate_declaration
- include: method_declaration
- include: stray_close_bracket
push: data_type_inside_block
- include: terminator
- match: \S*
scope: invalid.illegal.cs
pop: true

data_type_inside_block:
- meta_scope: meta.block.cs
- match: \}
scope: punctuation.section.block.end.cs
pop: 2
- include: attribute
- include: class_declaration
- include: interface_declaration
- include: delegate_declaration
- include: method_declaration
- include: stray_close_bracket

data_type_parameter:
- match: '<'
scope: meta.generic.cs punctuation.definition.generic.begin.cs
Expand All @@ -555,8 +554,7 @@ contexts:
- match: '{{name}}'
scope: entity.other.inherited-class.cs
push:
- maybe_terminator
- maybe_constructor_parameters
- function_call_begin_paren
- include: type

type_constraint_common:
Expand Down Expand Up @@ -800,17 +798,19 @@ contexts:
- include: attribute
- include: lambdas

- match: (?=[^\s\[])
set:
- match: '\s*\b(out|ref|this|params|in)\s+'
captures:
1: storage.modifier.parameter.cs
- match: \s
pop: true
- include: type
- match: (?=[^\s\[;])
set: method_param_type_modifier
- match: (?=\}|\)|>|\]|;)
pop: true

method_param_type_modifier:
- match: '\s*\b(out|ref|this|params|in)\s+'
captures:
1: storage.modifier.parameter.cs
- match: \s
pop: true
- include: type

constructor_prebody:
- meta_scope: meta.method.constructor.cs
- match: ':'
Expand Down Expand Up @@ -1572,15 +1572,17 @@ contexts:
type_tuple:
- match: \(
scope: punctuation.section.sequence.begin.cs
set:
- meta_scope: meta.sequence.tuple.cs
- match: \)
scope: punctuation.section.sequence.end.cs
pop: true
- match: ','
scope: punctuation.separator.sequence.cs
- match: (?=\S)
push: var_declaration_explicit
set: type_tuple_content

type_tuple_content:
- meta_scope: meta.sequence.tuple.cs
- match: \)
scope: punctuation.section.sequence.end.cs
pop: true
- match: ','
scope: punctuation.separator.sequence.cs
- match: (?=\S)
push: var_declaration_explicit

type_common:
- include: namespace_variables
Expand Down
40 changes: 40 additions & 0 deletions C#/tests/syntax_test_C#12.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/// SYNTAX TEST "Packages/C#/C#.sublime-syntax"

public class InvalidException(string _message) : Exception(_message);
///^^^ storage.modifier.access.cs
/// ^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs
/// ^^^^^ keyword.declaration.class.cs
/// ^^^^^^^^^^^^^^^^ entity.name.class.cs
/// ^^^^^^^^^^^^^^^^^ meta.class.constructor.parameters.cs
/// ^ punctuation.section.parameters.begin.cs
/// ^^^^^^ storage.type.cs
/// ^^^^^^^^ variable.parameter.cs
/// ^ punctuation.section.parameters.end.cs
/// ^^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs
/// ^ punctuation.separator.type.cs
/// ^^^^^^^^^ entity.other.inherited-class.cs
/// ^^^^^^^^^^ meta.function-call.cs meta.group.cs
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
/// ^ punctuation.section.group.begin.cs
/// ^^^^^^^^ variable.other.cs
/// ^ punctuation.section.group.end.cs
/// ^ punctuation.terminator.statement.cs
/// ^ - meta.class

public class NotFoundException(string _message) : Exception(_message);
///^^^ storage.modifier.access.cs
/// ^^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs
/// ^^^^^ keyword.declaration.class.cs
/// ^^^^^^^^^^^^^^^^^ entity.name.class.cs
/// ^^^^^^^^^^^^^^^^^ meta.class.constructor.parameters.cs
/// ^ punctuation.section.parameters.begin.cs
/// ^^^^^^ storage.type.cs
/// ^^^^^^^^ variable.parameter.cs
/// ^ punctuation.section.parameters.end.cs
/// ^^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs
/// ^ punctuation.separator.type.cs
/// ^^^^^^^^^ entity.other.inherited-class.cs
/// ^^^^^^^^^^ meta.function-call.cs meta.group.cs
/// ^ punctuation.section.group.begin.cs
/// ^^^^^^^^ variable.other.cs
/// ^ punctuation.section.group.end.cs
/// ^ punctuation.terminator.statement.cs
6 changes: 3 additions & 3 deletions C#/tests/syntax_test_C#8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ namespace CommonTests.Attributes;
[AttributeUsage(AttributeTargets.Method)]
public class CustomAutoDataAttribute() : AutoDataAttribute(
() =>
///^^^^^^ meta.class.constructor.parameters.cs
///^^^^^^^ meta.class.cs meta.function-call.cs meta.group.cs
/// ^^^^^ meta.function.anonymous.cs meta.group.cs
/// ^ punctuation.section.group.begin.cs
/// ^ meta.group.cs punctuation.section.group.end.cs
Expand All @@ -333,8 +333,8 @@ public class CustomAutoDataAttribute() : AutoDataAttribute(
fixture.Customizations.Add(new DateOnlySpecimenBuilder());
return fixture;
});
///^^^ meta.class.constructor.parameters.cs
///^^^ meta.class.cs meta.function-call.cs meta.group.cs
/// ^ punctuation.section.block.end.cs
/// ^ punctuation.section.parameters.end.cs
/// ^ punctuation.section.group.end.cs
/// ^ meta.class.cs punctuation.terminator.statement.cs

Loading