[clangd] Added highlighting for tokens that are macro arguments.
authorJohan Vikstrom <jvikstrom@google.com>
Mon, 19 Aug 2019 16:27:49 +0000 (16:27 +0000)
committerJohan Vikstrom <jvikstrom@google.com>
Mon, 19 Aug 2019 16:27:49 +0000 (16:27 +0000)
commitf497da304161c58388d2cc1e09507cde87d51eaa
tree0c7ff491da7d9321864b27fb93468dd6e9953a70
parent8880ac648ceb337868b7c4949776e50f5fd1cad0
[clangd] Added highlighting for tokens that are macro arguments.

Summary:
Adds semantic highlighting for tokens that are a macro argument.
Example:
```
D_V(SomeVar);
```
The "SomeVar" inside the macro is highlighted as a variable now.

Tokens that are in a macro body expansion are ignored in this patch for three reasons.
* The spelling loc is inside the macro "definition" meaning it would highlight inside the macro definition (could probably easily be fixed by using getExpansionLoc instead of getSpellingLoc?)
* If wanting to highlight the macro definition this could create duplicate tokens. And if the tokens are of different types there would be conflicts (tokens in the same range but with different types). Say a macro defines some name and both a variable declaration and a function use this, there would be two tokens in the macro definition but one with Kind "Variable" and the other with Kind "Function".
* Thirdly, macro body expansions could come from a file that is not the main file (easily fixed, just check that the Loc is in the main file and not even a problem if we wanted to highlight the actual macro "invocation")

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64741

llvm-svn: 369275
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp