[PATCH] D154580: Add missing semantic highlighing for concepts.

Jens Massberg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 01:51:14 PDT 2023


massberg created this revision.
massberg added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
massberg requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154580

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


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -648,6 +648,15 @@
       void $Function_def[[bar]]($TemplateParameter[[T]] $Parameter_def[[F]]) {
         $Parameter[[F]].$Unknown_dependentName[[foo]]();
       }
+
+      struct $Class_def[[F]] {
+        void $Method_def[[foo]]() {};
+      };
+      $Concept[[Fooable]] 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(
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -737,8 +737,10 @@
   }
 
   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;
   }
 
@@ -960,6 +962,14 @@
     // in both it and the token for the decl being dropped due to conflict.
     if (StartLoc == D->getLocation())
       return true;
+
+    if (auto *TSI = D->getTypeSourceInfo()) {
+       auto ATL = TSI->getTypeLoc().getContainedAutoTypeLoc();
+       if (ATL.isConstrained()) {
+         StartLoc = ATL.getConceptNameInfo().getEndLoc().getLocWithOffset(1);
+       }
+    }
+
     auto &Tok =
         H.addToken(StartLoc, *K).addModifier(HighlightingModifier::Deduced);
     const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154580.537625.patch
Type: text/x-patch
Size: 2005 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230706/cb98f49e/attachment.bin>


More information about the cfe-commits mailing list