microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

Wrong syntax highlighting for "deleted" in C++ #3454

Closed gareth618 closed 5 years ago

gareth618 commented 5 years ago

Issue Type: Bug

If I have a variable like "deleted" or something that starts with "delete", this prefix is highlighted like it is a keyword, and the rest of the name is highlighted like a normal variable. Please fix that.

Extension version: 0.22.1 VS Code version: Code 1.33.0 (0dd516dd412d42323fc3464531b1c715d51c4c1a, 2019-04-04T15:14:46.685Z) OS version: Windows_NT ia32 10.0.17134

sean-mcmanus commented 5 years ago

The bug isn't reproing for me. What version of VS Code do you have installed? Is this with a C or C++ file. What is the type of the variable? i.e. can you provide the complete text of the file? What theme are you using?

image

gareth618 commented 5 years ago

The bug is only in C++ files because the delete operator doesn't exist in C. I'm using Monokai, but it's available for any theme. I have the latest version of VSCode, and I think the problem appeared after this update.

image

tat3r commented 5 years ago

Can we just start using the compilers AST (libclang or whatever) instead of using regular expressions?

sean-mcmanus commented 5 years ago

That is strange, because I'm still not reproing with C++, Monokai, and the latest VS Code. image

Our C++ extensions does not implement the colorization. It's implemented by VS Code using the grammar at https://github.com/jeff-hykin/cpp-textmate-grammar . The grammar has been going through a lot of churn recently as they've been fixing bugs (and regressing certain cases as well). Using the latest "Better C++ Syntax" extension might fix the issue for you.

I don't know if using libclang for syntax highlighting is feasible or not. VS Code's infrastructure is setup to run the TextMate grammars currently. Other tools like Atom have switched to TreeSitter.

tat3r commented 5 years ago

Yeah the textmate grammar is just regular expressions, and will never work 100%, see: all of these

It's not a colorization problem, it's a language parsing problem, one that most compilers provide a solution for.

sean-mcmanus commented 5 years ago

@tat3r Porting over the parser/colorizer that Visual Studio uses is high on our list of major features -- it's being tracked by https://github.com/Microsoft/vscode-cpptools/issues/230 (semantic) and https://github.com/Microsoft/vscode-cpptools/issues/3460 (lexer).

gareth618 commented 5 years ago

I've just installed Better C++ Syntax and now it's OK, thank you! :)