[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
This commit is contained in:
Kadir Cetinkaya 2020-01-13 09:00:19 +01:00
parent 122443a950
commit 1f946ee2fa
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
3 changed files with 32 additions and 2 deletions

View File

@ -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(

View File

@ -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)));

View File

@ -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 *> &&#>
}