better-cpp-syntax icon indicating copy to clipboard operation
better-cpp-syntax copied to clipboard

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

Open ti1024 opened this issue 4 years ago • 2 comments

Checklist

  • [ ] This problem exists even with the setting "C_Cpp.enhancedColorization": "Disabled" → Not sure, see below
  • [ ] This bug exists for C
  • [x] This bug exists for C++
  • [ ] This bug exists for Objective-C
  • [ ] This bug exists for Objective-C++

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.

ti1024 avatar Jan 13 '21 23:01 ti1024

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 avatar Jun 09 '21 14:06 a-stewart

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

a-stewart avatar Jun 27 '22 12:06 a-stewart