Skip to content
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
11 changes: 6 additions & 5 deletions C++/C++.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ contexts:
- include: template
- match: (?=\S)
set: global-modifier
- include: using-namespace
- include: using-namespace-enum
- include: namespace
- include: module
- include: keywords-angle-brackets
Expand Down Expand Up @@ -378,7 +378,7 @@ contexts:
- include: preprocessor-expressions
- include: comments
- include: case-default
- include: using-namespace
- include: using-namespace-enum
- include: typedef
- include: using-alias
- include: keywords-angle-brackets
Expand Down Expand Up @@ -575,11 +575,12 @@ contexts:
pop: true
- include: expressions

using-namespace:
- match: '\b(using)\s+(namespace)\b'
using-namespace-enum:
- match: '\b(using)\s+(?:(namespace)|(enum))\b'
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.

push:
- include: identifiers
- match: ''
Expand Down Expand Up @@ -1546,7 +1547,7 @@ contexts:
- include: template
- match: (?=\S)
set: data-structures-modifier
- include: using-namespace
- include: using-namespace-enum
- include: typedef
- include: using-alias
- match: \b({{visibility_modifiers}})\s*(:)(?!:)
Expand Down
4 changes: 4 additions & 0 deletions C++/syntax_test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,10 @@ using namespace myNameSpace;
/* <- keyword.control */
/* ^ keyword.control */

using enum myEnum;
/* <- keyword.control */
/* ^ keyword.declaration */

namespace ns :: abc /* Neither this comment... */
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.namespace */
/* ^^^^^^^^^ entity.name.namespace */
Expand Down