Skip to content

Conversation

@camila314
Copy link
Contributor

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 the enum keyword in such a statement.

@camila314 camila314 changed the title [C/C++] Implement C++20 using enum statement [C/C++] Implement C++20 using enum statement + allow templated constructor list initialization Nov 21, 2025
@camila314 camila314 changed the title [C/C++] Implement C++20 using enum statement + allow templated constructor list initialization [C/C++] Implement C++20 using enum statement Nov 21, 2025
@michaelblyons
Copy link
Collaborator

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++
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@FichteFoll FichteFoll Nov 23, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants