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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
97 changes: 60 additions & 37 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but you use pop: true for the rest of the commit (except the pop: 2).


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 @@ -554,11 +553,31 @@ contexts:
- include: type_constraint_common
- match: '{{name}}'
scope: entity.other.inherited-class.cs
push:
- maybe_terminator
- maybe_constructor_parameters
push: inherited_class_arguments
- include: type

inherited_class_arguments:
- match: (?=\()
push: [inside_inherited_class_arguments, arguments, inherited_class_arguments-begin]
- match: (?=\S)
pop: true

inherited_class_arguments-begin:
- meta_include_prototype: false
- match: \(
scope: punctuation.section.group.begin.cs
pop: true

inside_inherited_class_arguments:
- clear_scopes: 1
- meta_include_prototype: false
- meta_scope: meta.class.constructor.arguments.cs meta.group.cs
- match: \)
scope: punctuation.section.group.end.cs
pop: true
- match: ''
pop: true

type_constraint_common:
- match: (?=\{)
pop: true
Expand Down Expand Up @@ -800,17 +819,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 +1593,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.class.constructor.arguments.cs meta.group.cs
/// ^ 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.class.constructor.arguments.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