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

A raw string literal inside a struct/class definition breaks the highlighting #530

Closed ti1024 closed 2 years ago

ti1024 commented 3 years ago

Checklist

The issue persists even after I add "C_Cpp.enhancedColorization": "Disabled" to settings.json and restart VS Code, but VS Code says that C_Cpp.enhancedColorization is an unknown configuration setting, so I am not sure if I am adding the setting correctly. I am using VS Code 1.51.1 on Mac.

The code with a problem is:

struct S {
  int x =
      f(R"(some raw string literal)");
  int y = 100;
  const char* z = "hello";
};

It looks like:

image

Color Theme: Default Light+

It should look like:

The raw string literal should be colored like a string literal, and everything after that should not be colored like a string literal.

a-stewart commented 3 years ago

This seems to effect any string literals inside parentheses, it seems to be fixable by adding #string_context before #parameter in the function_parameter_context within the json file.

image

a-stewart commented 2 years ago

Just a follow up on this, it looks like we can still reach an error state even with the fix submitted last year.

Result after existing fix:

image

But we can break this by simply adding whitespace before the start of the raw string:

struct S {
  int x =
      f( R"(some raw string literal)");
  int y = 100;
  const char* z = "hello";
};

image

Or adding another nested call:

struct S {
  int x =
      f(g(R"(some raw string literal)"));
  int y = 100;
  const char* z = "hello";
};

image

My current theory is that #string_context should be under #paremeter, rather than #function_parameter_context.

That does seem to fix this issue