-
Notifications
You must be signed in to change notification settings - Fork 597
[C/C++] Implement C++20 using enum statement #4390
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
base: master
Are you sure you want to change the base?
Conversation
|
Add a regression test? You don't want the feature getting lost when the C family is rewritten. 🙃 |
| captures: | ||
| 1: keyword.control.c++ | ||
| 2: keyword.control.c++ | ||
| 3: keyword.declaration.c++ |
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.
I have to wonder why you specifically chose to assign the keyword.declaration scope to only enum. To me, it seems more natural to have this scope name on either using or all of these keywords since the "using" is what determines the semantic behavior of this statement.
A using enum declaration introduces the enumerator names of the named enumeration as if by a using declaration for each enumerator. ([via])(https://en.cppreference.com/w/cpp/language/enum.html#Using-enum-declaration)
That said, since the identifier that's being referenced isn't actually added to the scope but instead the members within, I'm not sure a keyword.declaration scope would even be the proper one here. A quick survey on other syntaxes might be useful here as I don't know this off the top of my head. Perhaps someone else does, though.
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.
The use of keyword.declaration is because that's how other non-declaring instances of the enum keyword are scoped, for example void func(enum Enum value). To me it makes more sense to value consistency here because the language file already has many cases of strangely assigned keywords (e.g namespace being keyword.control).
From what I could search, other languages have a different syntax for bringing things into scope that doesn't use a keyword also used for type declaration. Not much to go off from to me
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.
The actual inconsistency is namespace scope not having been changed from keyword.control to keyword.declaration, back when we did the keyword.declaration move.
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.
FYI on a more general note, we tend to use the scopes previously determined in the issues labeled "RFC" here:
https://github.com/sublimehq/Packages/issues?q=sort%3Aupdated-desc+state%3Aopen+label%3ARFC
which are all in the PackageDev package. Here is an overview:
https://github.com/SublimeText/PackageDev/blob/master/plugins/lib/scope_data/data.py
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.
I'm uncharacteristically 🤷 about the scope right now. The scopes for the whole language are not great, and the place to fix them, imo, is #4147 or the like.
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.
Well, in that case I suggest just using the same scope for enum as for the other two keywords here until the C language family gets revampt.
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.
Well, as enum is already scoped keyword.declaration in all other patterns, the - IMHO - correct way forward was to fix scope of namespace keyword, which should receive keyword.declaration as well, everywhere.
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.
Imo not, because afaiu the enum and namespace keywords following using are not declarations but rather function like scoped imports and afaik we do not scope imports as declarations.
In C++20 the
using enum SomeEnum;statement was added to bring an enum class scope into the current scope. This pull request implements a basic tweak to highlight theenumkeyword in such a statement.