[PATCH] D62579: [Index] Compute correct symbol kind for variable templates

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 29 05:34:25 PDT 2019


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added subscribers: arphaman, jkorous.
Herald added a project: clang.

The index library itself seems to never pass variable templates as
input, however clangd does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62579

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Index/IndexSymbol.cpp


Index: clang/lib/Index/IndexSymbol.cpp
===================================================================
--- clang/lib/Index/IndexSymbol.cpp
+++ clang/lib/Index/IndexSymbol.cpp
@@ -96,6 +96,13 @@
     Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface;
   }
 
+  if (auto *VT = dyn_cast<VarTemplateDecl>(D)) {
+    Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+    Info.Lang = SymbolLanguage::CXX;
+    // All other fields are filled from the templated decl.
+    D = VT->getTemplatedDecl();
+  }
+
   if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
     switch (TD->getTagKind()) {
     case TTK_Struct:
@@ -333,6 +340,23 @@
           Info.Lang = SymbolLanguage::CXX;
       }
       break;
+    case Decl::ClassTemplatePartialSpecialization:
+    case Decl::ClassScopeFunctionSpecialization:
+    case Decl::ClassTemplateSpecialization:
+    case Decl::CXXRecord:
+    case Decl::Enum:
+    case Decl::Record:
+      llvm_unreachable("records handled before");
+      break;
+    case Decl::VarTemplateSpecialization:
+    case Decl::VarTemplatePartialSpecialization:
+    case Decl::ImplicitParam:
+    case Decl::ParmVar:
+    case Decl::Var:
+    case Decl::VarTemplate:
+      llvm_unreachable("variables handled before");
+      break;
+    // Other decls get the 'unknown' kind.
     default:
       break;
     }
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -463,6 +463,26 @@
   EXPECT_THAT(
       Results.Completions,
       UnorderedElementsAre(AllOf(Named("a"), Kind(CompletionItemKind::Field))));
+
+  // Completion kinds for templates should not be unknown.
+  Results = completions(
+      R"cpp(
+        template <class T> struct complete_class {};
+        template <class T> void complete_function();
+        template <class T> using complete_type_alias = int;
+        template <class T> int complete_variable = 10;
+
+        auto x = complete_^
+      )cpp");
+  EXPECT_THAT(
+      Results.Completions,
+      UnorderedElementsAre(
+          AllOf(Named("complete_class"), Kind(CompletionItemKind::Class)),
+          AllOf(Named("complete_function"), Kind(CompletionItemKind::Function)),
+          AllOf(Named("complete_type_alias"),
+                Kind(CompletionItemKind::Reference)),
+          AllOf(Named("complete_variable"),
+                Kind(CompletionItemKind::Variable))));
 }
 
 TEST(CompletionTest, NoDuplicates) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62579.201874.patch
Type: text/x-patch
Size: 2615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190529/5708f737/attachment.bin>


More information about the cfe-commits mailing list