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

Parameter types are incorrectly confused for parameter identifiers and color highlighted as such. #580

Closed 103sbavert closed 4 months ago

103sbavert commented 2 years ago

Checklist

The code with a problem is (A function declaration without the paramter identifier):

void fn(unsigned int);

void fn(const char[])

It looks like:

image

It should look like:

As you can see, in the code above with the C programming language, both int and char should be colored dark blue instead of light blue (which is used for parameter identifiers in VSC). The problem is only persistent with C and not C++. int and char being keywords should be highlighted with dark blue as all other keywords are but that isn't the case.

103sbavert commented 2 years ago

Another issue I noticed, unlike most IDEs, in VSC most keywords are dark blue but not all. For example the return keyword is pinkish. I don't think that's a good idea. All keywords should be the same color or at least we should be able to make them all the same color.

yume-chan commented 2 years ago

Looks very similar to jeff-hykin/better-cpp-syntax#200.

jeff-hykin/better-cpp-syntax@ad31cfa only fixed its cpp grammar, and indeed the issue doesn't happen when set to cpp mode.

image (c)

image (cpp)

Copied my reply from https://github.com/microsoft/vscode/issues/138695#issuecomment-990025943

jeff-hykin commented 2 years ago

Another issue I noticed, unlike most IDEs, in VSC most keywords are dark blue but not all. For example the return keyword is pinkish. I don't think that's a good idea. All keywords should be the same color or at least we should be able to make them all the same color.

@sbeve72 you can customize any theme for any language to have exactly the colors you want just by editing your settings. Short tutorial here

(I don't control the default theme btw)

Keyword is pretty broad. There's operators, control flow, entity declarations, built in primitives, built-in modifiers, built in pointers, built in macros, built in functions, type casting, access specifiers, and more. It would be a major loss of information if the parser didn't distinguish between them. If you want to make them all the same color you're welcome to find or make a theme that does, but the capability will exist for theme designers who want to deeply color different code functionality.

103sbavert commented 2 years ago

Can I do anything about the bug that I mentioned in the original comment? Is there a way to customize the theme to fix that?

jeff-hykin commented 2 years ago

You can change the color, but the original thing is a legitimate bug that is broken on the parser side. Right now the C parser needs to be rewritten, and that coloring is happening because it thinks int and char are parameters instead of types