[clang-tools-extra] 1c056f8 - [clangd] Use the "macro" semantic token for pre-defined identifiers

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 18 07:13:09 PDT 2022


Author: Christian Kandeler
Date: 2022-08-18T16:12:55+02:00
New Revision: 1c056f8df26b542b21b61a538203244215701113

URL: https://github.com/llvm/llvm-project/commit/1c056f8df26b542b21b61a538203244215701113
DIFF: https://github.com/llvm/llvm-project/commit/1c056f8df26b542b21b61a538203244215701113.diff

LOG: [clangd] Use the "macro" semantic token for pre-defined identifiers

This matches user expectations.

Reviewed By: sammccall

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

Added: 
    

Modified: 
    clang-tools-extra/clangd/SemanticHighlighting.cpp
    clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 4a50853455b92..5b6fcf923e3fa 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -542,6 +542,14 @@ class CollectExtraHighlightings
     return Base::TraverseConstructorInitializer(Init);
   }
 
+  bool VisitPredefinedExpr(PredefinedExpr *E) {
+    H.addToken(E->getLocation(), HighlightingKind::LocalVariable)
+        .addModifier(HighlightingModifier::Static)
+        .addModifier(HighlightingModifier::Readonly)
+        .addModifier(HighlightingModifier::FunctionScope);
+    return true;
+  }
+
   bool VisitCallExpr(CallExpr *E) {
     // Highlighting parameters passed by non-const reference does not really
     // make sense for literals...

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 128cd620d710e..32f0f58ade2c3 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -841,6 +841,12 @@ sizeof...($TemplateParameter[[Elements]]);
             $Function_deprecated[[Foo]]($Parameter[[x]]); 
         }
       )cpp",
+      // Predefined identifiers
+      R"cpp(
+        void $Function_decl[[Foo]]() {
+            const char *$LocalVariable_decl_readonly[[s]] = $LocalVariable_readonly_static[[__func__]];
+        }
+      )cpp",
       // Explicit template specialization
       R"cpp(
         struct $Class_decl[[Base]]{};


        


More information about the cfe-commits mailing list