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++ highlighting broken on class template specializations, but only with specific formatting #512

Open alexr00 opened 4 years ago

alexr00 commented 4 years ago

Checklist

The code with a problem is:

template <class T> struct example;

// highlighting works perfectly fine here
template <> struct example<unsigned> {};

// this also works perfectly fine
template <>
struct example<int> 
{};

// highlighting breaks at <>, doesn't matter if there is anything in it or not. 
// doesn't matter if the specialization is partial, full, CV-qualified, or anything else. 
template <> struct example<long> 
{};

It looks like:

image

The scope of the <> in the broken example is unexpected. The scope of the < is:

punctuation.section.angle-brackets.start.template.definition.cpp
source.cpp

When I would expect it to be:

punctuation.section.angle-brackets.start.template.definition.cpp
meta.template.definition.cpp
source.cpp

The scope of the > gets even more unexpected:

keyword.operator.comparison.cpp
meta.template.definition.cpp
source.cpp

Originally from @evanacox in https://github.com/microsoft/vscode/issues/109098