From 1f946ee2faba5395a04a081fbe561e3d91aa2b3d Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Mon, 13 Jan 2020 09:00:19 +0100 Subject: [PATCH] [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`. 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 --- .../clangd/unittests/CodeCompleteTests.cpp | 9 +++++++++ clang/lib/Sema/SemaCodeComplete.cpp | 8 ++++++-- clang/test/CodeCompletion/ctor-signature.cpp | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeCompletion/ctor-signature.cpp diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp index 8017fc9..d765088 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 struct Foo {}; + template struct Foo { Foo(T); }; + Foo 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 7260977..3348067 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 #include #include @@ -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 0000000..4dbd9230 --- /dev/null +++ b/clang/test/CodeCompletion/ctor-signature.cpp @@ -0,0 +1,17 @@ +template +struct Foo {}; +template +struct Foo { Foo(T); }; + +void foo() { + Foo(); + // 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 &#>) + // CHECK-CC1: OVERLOAD: Foo(<#Foo &&#> + Foo(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 &#>) + // CHECK-CC2: OVERLOAD: Foo(<#Foo &&#> +} -- 2.7.4