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

Semantic Colorization Issue with Custom Iterators #584

Closed ArktisDev closed 2 years ago

ArktisDev commented 2 years ago

Checklist

The code with a problem is:

A custom iterator, a MWE being a simple thing like:

#include <iostream>

class Foo {
    public:
        int a;

        Foo(int a) : a( a ) {}
};

class FooIterator : public std::forward_iterator_tag {
    public:
        int a;
        const Foo* f;

        FooIterator(int a, const Foo& f) : a( a ), f( &f ) {}

        FooIterator operator++() {
            advance();
            return *this;
        }

        bool operator==(const FooIterator& f) const {
            return this->a == f.a;
        }

        bool operator!=(const FooIterator& f) const {
            return this->a != f.a;
        }

        int operator*() const {
            return a;
        }

        void advance() {
            a++;
        }
};

FooIterator begin(const Foo& f) {
    return FooIterator(0, f);
}

FooIterator end(const Foo& f) {
    return FooIterator(f.a, f);
}

int main() {
    Foo f(10);

    for (int a : f) {
        std::cout << a << std::endl;
    }

    return 0;
}

It looks like:

Screen Shot 2022-01-04 at 20 55 15

It should look like:

Not having the right ) and { colored yellow on line 50.

jeff-hykin commented 2 years ago

Does the problem go away with "C_Cpp.enhancedColorization": "Disabled" ?

I can't reproduce the issue:

Screen Shot 2022-01-10 at 11 06 08 AM
ArktisDev commented 2 years ago

With "C_Cpp.enhancedColorization": "Disabled" in my settings.json file this issue doesn't exist, but also no other colorization exists. I am still having this issue for some reason. Maybe it is platform specific, I can try the example later on ubuntu to see what it looks like there.

Screen Shot 2022-01-24 at 14 51 44
jeff-hykin commented 2 years ago

If you pick a theme that colors more stuff (mine is XD Theme, the MixItUp variant) it'd bet money it'll be colored like mine.

However the option you turned of is disabling the C++ extension (which isn't a part of this repository). So its probably is a bug with the C++, extension by Microsoft.

The code here is only a lightweight grammar, it won't matter what OS because it's not using a C++ compiler or language server to color the code.

ArktisDev commented 2 years ago

This is correct. I used the XD Theme MixItUp variant and the coloring was as you described. I really do like the default dark+ theme of VSCode, but if enhanced colorization screws up like this then I'll be looking for another theme that gives all the nice colorization.

This issue is seemingly also platform dependent. It is happening on my mac, but not in windows + WSL or in an ubuntu install. I'll go ahead and make an issue with the C/C++ extension and see if they can fix it.

ArktisDev commented 2 years ago

I've opened the issue with the C/C++ extension at microsoft/vscode-cpptools#9123. Looks like they have classified it as a bug and will be working on it.