Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect highlighting for C++ special identifiers #8745

Closed
aladram opened this issue Aug 10, 2021 · 5 comments
Closed

Incorrect highlighting for C++ special identifiers #8745

aladram opened this issue Aug 10, 2021 · 5 comments

Comments

@aladram
Copy link

aladram commented Aug 10, 2021

Describe the bug
C++ identifiers with special meaning (final, override, import and module). are incorrectly highlighted out-of-context. These keywords should be considered as regular identifiers when used out of their special meaning context (c.f. C++20 standard, section 5.10, paragraph 2).

To Reproduce

  1. Run vim --clean
  2. Edit a.cc
  3. Type 'int final, override, import, module;'
  4. Incorrect highlighting for these variables name

Expected behavior
Highlighting for these variables names should be the same as the one for int x;

Environment (please complete the following information):
Vim version 8.2.3323

@chrisbra
Copy link
Member

That is a CPP syntax issue. So I'll leave that for https://github.com/vim-jp/vim-cpp

@dpelle
Copy link
Member

dpelle commented Aug 30, 2021

This is probably difficult to do properly as C++ syntax is complex and Vim does not use a C++ parser, but uses heuristics based on regexp for syntax highlighting. We can maybe improve heuristics, but we can't expect to get syntax highlighting it 100% right with heuristics. In practice, it's already doing a fairly good job for C++. Calling variables override,final or module seems quite rare and is asking for trouble. I understand that C++ allowed that for to avoid breaking existing software. Backward compatibility is important for C++. For Vim, the cost / benefit of fixing this ticket seems low IMO.

The only way to syntax highlight C++ (and other languages) 100% correctly, is to have a real C++ parser using e.g. Tree-sitter. Maybe something for Vim-10? :-)

@chrisbra
Copy link
Member

yes, related: #8658

Note, Vim cannot do semantic highlighting (yet), just regex based highlighting.

@brammool
Copy link
Contributor

brammool commented Aug 30, 2021 via email

@chrisbra
Copy link
Member

apparently it works quite nicely for Neovim (for languages that have treesitter parsers).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants