[clang-tools-extra] 8af9a37 - Add missing semantic highlighing for concepts.

Jens Massberg via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 07:32:05 PDT 2023


Author: Jens Massberg
Date: 2023-07-06T16:28:57+02:00
New Revision: 8af9a373ad95ef49e2f2aa83c021b8043f848ab9

URL: https://github.com/llvm/llvm-project/commit/8af9a373ad95ef49e2f2aa83c021b8043f848ab9
DIFF: https://github.com/llvm/llvm-project/commit/8af9a373ad95ef49e2f2aa83c021b8043f848ab9.diff

LOG: Add missing semantic highlighing for concepts.

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

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 f6a3f7ac66aa09..8003a3c98f0ad8 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -737,8 +737,10 @@ class CollectExtraHighlightings
   }
 
   bool VisitAutoTypeLoc(AutoTypeLoc L) {
-    if (L.isConstrained())
+    if (L.isConstrained()) {
       H.addAngleBracketTokens(L.getLAngleLoc(), L.getRAngleLoc());
+      H.addToken(L.getConceptNameInfo().getLoc(), HighlightingKind::Concept);
+    }
     return true;
   }
 
@@ -953,13 +955,18 @@ class CollectExtraHighlightings
         kindForType(AT->getDeducedType().getTypePtrOrNull(), H.getResolver());
     if (!K)
       return true;
-    SourceLocation StartLoc = D->getTypeSpecStartLoc();
+    auto *TSI = D->getTypeSourceInfo();
+    if (!TSI)
+      return true;
+    SourceLocation StartLoc =
+        TSI->getTypeLoc().getContainedAutoTypeLoc().getNameLoc();
     // The AutoType may not have a corresponding token, e.g. in the case of
     // init-captures. In this case, StartLoc overlaps with the location
     // of the decl itself, and producing a token for the type here would result
     // in both it and the token for the decl being dropped due to conflict.
     if (StartLoc == D->getLocation())
       return true;
+
     auto &Tok =
         H.addToken(StartLoc, *K).addModifier(HighlightingModifier::Deduced);
     const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index ff052e6be9549c..6eee6ec30ac024 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -648,6 +648,15 @@ sizeof...($TemplateParameter[[Elements]]);
       void $Function_def[[bar]]($TemplateParameter[[T]] $Parameter_def[[F]]) {
         $Parameter[[F]].$Unknown_dependentName[[foo]]();
       }
+
+      struct $Class_def[[F]] {
+        void $Method_def[[foo]]() {};
+      };
+      $Concept[[Fooable]] $Class_deduced[[auto]] $Variable_def[[f]] = $Class[[F]]();
+
+      void $Function_def[[Bar]]($Concept[[Fooable]] $TemplateParameter[[auto]] $Parameter_def[[x]]) {}
+
+      template$Bracket[[<]]$Concept[[Fooable]] auto $TemplateParameter_def_readonly[[x]]$Bracket[[>]] void $Function_def[[Boo]]() {}
     )cpp",
       // Dependent template name
       R"cpp(


        


More information about the cfe-commits mailing list