jeff-hykin / better-cpp-syntax

💾 The source of VS Code's C++ syntax highlighting
GNU General Public License v3.0
154 stars 29 forks source link

multiline macros scoping #590

Closed jeff-hykin closed 2 years ago

jeff-hykin commented 2 years ago

(Movign this discussion here @alexr00)

It seems like with the latest C++ grammars multiline macros get scoped differently. Specifically, the additional lines have lost the meta.preprocessor.macro.cpp scope. In VS Code, some tokens get colored differently because of this (before on top, after on the bottom):

image

Snippet:

#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators)                                     \
    namespace {                                                                                    \
        struct der : public base                                                                   \
        {                                                                                          \
            void f();                                                                              \
        };                                                                                         \
        static void func() {                                                                       \
            der v;                                                                                 \
            v.f();                                                                                 \
        }                                                                                          \
        DOCTEST_REGISTER_FUNCTION(DOCTEST_EMPTY, func, decorators)                                 \
    }                                                                                              \
    inline DOCTEST_NOINLINE void der::f()
jeff-hykin commented 2 years ago

I'm actually suprised this behavior didn't always exist as this was the intended scoping. meta tags are described as containing nested scopes,meta.preprocessor.macro is supposed to be the entire macro.

For theming I would recommend avoiding standalone meta tags, since they more or less only exist to provide context. For example meta.preprocessor.macro punctuation.vararg-ellipses would be for highlighting ... but only in the context of a macro.

I went ahead and added meta.function.preprocessor.parameters to allow for more customization. The following should make them look the same:

Dark blue: entity.name.function.preprocessor punctuation.definition.parameters.begin.preprocessor punctuation.definition.parameters.end.preprocessor meta.function.preprocessor.parameters punctuation

Light blue: variable.parameter.preprocessor

alexr00 commented 2 years ago

I think I'm misunderstanding something. The latest changes I pulled in last week no longer include meta.preprocessor.macro.cpp on all parts of the macro. Is this intentional?

Scopes of namespace with latest grammar:

storage.type.namespace.definition.cpp
keyword.other.namespace.definition.cpp
meta.head.namespace.cpp
meta.block.namespace.cpp
source.cpp

Scopes of namespace before the updates I pulled in last week (VS Code used to be on commit db3f4e4a5d8335b2f6d689bec490c23f8313630f):

storage.type.namespace.definition.cpp
keyword.other.namespace.definition.cpp
meta.head.namespace.cpp
meta.block.namespace.cpp
meta.preprocessor.macro.cpp
source.cpp
jeff-hykin commented 2 years ago

Oh I apologize, I looked at the images in the wrong order. This is definitely a bug

jeff-hykin commented 2 years ago

Okay it should be fixed with v1.15.18

alexr00 commented 2 years ago

Pulled in the changes. Thank you for the fix!