[clang-tools-extra] 1f946ee - [clang][CodeComplete] Propogate printing policy to FunctionDecl

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 20 03:23:20 PST 2020


Author: Kadir Cetinkaya
Date: 2020-01-20T12:20:20+01:00
New Revision: 1f946ee2faba5395a04a081fbe561e3d91aa2b3d

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

LOG: [clang][CodeComplete] Propogate printing policy to FunctionDecl

Summary:
Printing policy was not propogated to functiondecls when creating a
completion string which resulted in canonical template parameters like
`foo<type-parameter-0-0>`. This patch propogates printing policy to those as
well.

Fixes https://github.com/clangd/clangd/issues/76

Reviewers: ilya-biryukov

Subscribers: jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Added: 
    clang/test/CodeCompletion/ctor-signature.cpp

Modified: 
    clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
    clang/lib/Sema/SemaCodeComplete.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 8017fc98b8ef..d76508834efd 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2297,6 +2297,15 @@ TEST(CompletionTest, DeprecatedResults) {
                            AllOf(Named("TestClangc"), Deprecated())));
 }
 
+TEST(SignatureHelpTest, PartialSpec) {
+  const auto Results = signatures(R"cpp(
+      template <typename T> struct Foo {};
+      template <typename T> struct Foo<T*> { Foo(T); };
+      Foo<int*> F(^);)cpp");
+  EXPECT_THAT(Results.signatures, Contains(Sig("Foo([[T]])")));
+  EXPECT_EQ(0, Results.activeParameter);
+}
+
 TEST(SignatureHelpTest, InsideArgument) {
   {
     const auto Results = signatures(R"cpp(

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 7260977c634d..3348067a7669 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -37,6 +37,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
 #include <list>
 #include <map>
 #include <string>
@@ -3705,8 +3706,11 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
         Result.addBriefComment(RC->getBriefText(S.getASTContext()));
     }
     AddResultTypeChunk(S.Context, Policy, FDecl, QualType(), Result);
-    Result.AddTextChunk(
-        Result.getAllocator().CopyString(FDecl->getNameAsString()));
+
+    std::string Name;
+    llvm::raw_string_ostream OS(Name);
+    FDecl->getDeclName().print(OS, Policy);
+    Result.AddTextChunk(Result.getAllocator().CopyString(OS.str()));
   } else {
     Result.AddResultTypeChunk(Result.getAllocator().CopyString(
         Proto->getReturnType().getAsString(Policy)));

diff  --git a/clang/test/CodeCompletion/ctor-signature.cpp b/clang/test/CodeCompletion/ctor-signature.cpp
new file mode 100644
index 000000000000..4dbd92300566
--- /dev/null
+++ b/clang/test/CodeCompletion/ctor-signature.cpp
@@ -0,0 +1,17 @@
+template <typename T>
+struct Foo {};
+template <typename T>
+struct Foo<T *> { Foo(T); };
+
+void foo() {
+  Foo<int>();
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:7:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: OVERLOAD: Foo()
+  // CHECK-CC1: OVERLOAD: Foo(<#const Foo<int> &#>)
+  // CHECK-CC1: OVERLOAD: Foo(<#Foo<int> &&#>
+  Foo<int *>(3);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:12:14 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+  // CHECK-CC2: OVERLOAD: Foo(<#int#>)
+  // CHECK-CC2: OVERLOAD: Foo(<#const Foo<int *> &#>)
+  // CHECK-CC2: OVERLOAD: Foo(<#Foo<int *> &&#>
+}


        


More information about the cfe-commits mailing list