jeff-hykin / better-cpp-syntax

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

C++ syntax highlighting falls apart after specific struct syntax #652

Closed alexr00 closed 7 months ago

alexr00 commented 10 months ago

Checklist

If Disabling that^ makes the problem go away, then follow this to make an issue on the C++ extension: https://github.com/microsoft/vscode-cpptools/issues/new/choose

The code with a problem is:

struct foo
{
    void (*bar1)() noexcept;
    void (*bar2)() noexcept;
    void (*bar3)() noexcept;
};

void baz()
{
    static_assert(false, "some string");
    int x = 0;
}

It looks like:

In latest insiders with the default theme image

More issues are apparent depending on the theme being used image

It should look like:

Here's the snippet again with some of the issues annotated. It appears as though the parser gets confused on the first function pointer and essentially thinks all the things after it are parameters in the function pointer type.

struct foo
{
    void (*bar1)() noexcept;        // noexcept is entity.name.type.parameter, should be storage.modifier.special.functional.post-parameters.noexcept.cpp
    void (*bar2)() noexcept;        // bar2 is variable.parameter.pointer.function, should be variable.other.pointer.function.cpp
    void (*bar3)() noexcept;
};                                  // } is meta.parameter.cpp, should be punctuationsection.block.end.bracket.curly.struct.cpp

void baz()                          // baz is entity.name.type.parameter.cpp, should be entity.name.function.definition.cpp
{
    static_assert(false, "string");
    int x = 0;                      // line is string.quoted.double.cpp
}

Originally from @akbyrd in https://github.com/microsoft/vscode/issues/202365

jeff-hykin commented 10 months ago

@akbyrd thank you for including the scopes, that's super helpful. I think you're right, something is confusing the function pointer pattern and then it never closes. I bet it'll be an easy fix so I'll take a look when I get the chance