-
Notifications
You must be signed in to change notification settings - Fork 591
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But logically we want it scoped like a normal function call I believe, a constructor is just a special type of function 🙂 I think other constructor calls are like that, though I'm not at a computer to check right now. Like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I read the line as a declaration, which forwards arguments from specialized The actual instantiation, which calls a constructor as part of object creation would be Even if, I wouldn't scope an object instantiation "meta.function-call" either, as calling one of the available constructors is only one part of the whole object creation process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What scope can we use here then? :) btw in the below public class InvalidException(string _message) : Exception(_message);
public class InvalidException2 : Exception
{
public InvalidException2(string _message) : base(_message)
{
}
} and if we had a breakpoint inside the constructor for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, those constructors are called on Both, long and short form, however just denote a class definition. See how also I find this special syntax worth dedicated scopes, especially as they describe a sort of inheritance or dependency tree. We can find such constructs in Python dataclasses as well as Java's Packages/Java/tests/syntax_test_java.java Lines 2527 to 2536 in c7cd5a7
... except none of them supports direct parameter forwarding to parent classes in declaration syntax. IIRC, Java is the only syntax which applies special We could go with it and just scope those argument lists public class InvalidException(string _message) : Exception(_message);
// ^^^^^^^^^^^^^^^^ meta.class.identifier entity.name.class
// ^^^^^^^^^^^^^^^^ meta.class.parameters meta.group
// ^^^ meta.class
// ^^^^^^^^^^^^^^^^^^^^ meta.class.[extends|inherites]
// ^^^^^^^^^ entity.other.inherited-class
// ^^^^^^^^^^ meta.group or add a new public class InvalidException(string _message) : Exception(_message);
// ^^^^^^^^^^^^^^^^ meta.class.identifier entity.name.class
// ^^^^^^^^^^^^^^^^ meta.class.parameters meta.group
// ^^^ meta.class
// ^ meta.class.extends
// ^^^^^^^^^ meta.class.extends.identifier entity.other.inherited-class
// ^^^^^^^^^^ meta.class.extends.arguments meta.group or just stack another public class InvalidException(string _message) : Exception(_message);
// ^^^^^^^^^^^^^^^^ meta.class.identifier entity.name.class
// ^^^^^^^^^^^^^^^^ meta.class.parameters meta.group
// ^^^ meta.class
// ^^^^^^^^^^^^^^^^^^^^ meta.class.extends
// ^^^^^^^^^ meta.class.identifier entity.other.inherited-class
// ^^^^^^^^^^ meta.class.arguments meta.group Note: Not sure if it is correct, but I somehow got used to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, Java scopes instantiations Packages/Java/tests/syntax_test_java.java Lines 7973 to 7978 in c7cd5a7
It distinguishes it from normal function calls to illustrate it being a special syntax to create a new object and implicitly calling its construtors to initialize attributes/members. I could also imagine to add sub scopes for identifiers and argument lists like |
||||||||||||||||||||||||||||||||||
/// ^ 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 |
There was a problem hiding this comment.
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 thepop: 2
).