[clangd] Show non-instantiated decls in signatureHelp
Summary:
To avoid producing very verbose output in substitutions involving
typedefs, e.g.
T -> std::vector<std::string>::iterator
gets turned into an unreadable mess when printed out for libstdc++,
result contains internal types (std::__Vector_iterator<...>) and
expanded well-defined typedefs (std::basic_string<char>).
Until we improve the presentation code in clang, going with
non-instantiated decls looks like a better UX trade-off.
Reviewers: hokein, ioeric, kadircet
Reviewed By: hokein
Subscribers: MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D50645
llvm-svn: 339665
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 12a3d5f..72e395f 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -714,7 +714,15 @@
"too many arguments");
SigHelp.activeParameter = static_cast<int>(CurrentArg);
for (unsigned I = 0; I < NumCandidates; ++I) {
- const auto &Candidate = Candidates[I];
+ OverloadCandidate Candidate = Candidates[I];
+ // We want to avoid showing instantiated signatures, because they may be
+ // long in some cases (e.g. when 'T' is substituted with 'std::string', we
+ // would get 'std::basic_string<char>').
+ if (auto *Func = Candidate.getFunction()) {
+ if (auto *Pattern = Func->getTemplateInstantiationPattern())
+ Candidate = OverloadCandidate(Pattern);
+ }
+
const auto *CCS = Candidate.CreateSignatureString(
CurrentArg, S, *Allocator, CCTUInfo, true);
assert(CCS && "Expected the CodeCompletionString to be non-null");