summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/CodeCompletionStrings.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-08-17 09:29:38 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-08-17 09:29:38 +0000
commit5f4a351306de78453d5c35bbaa4f8f0717db9029 (patch)
tree5ad61b1a2437467dd46852557d4467f6125382bd /clang-tools-extra/clangd/CodeCompletionStrings.cpp
parent7d3e08ff8d017018e6ab408f571c7e9781e7e54d (diff)
downloadbcm5719-llvm-5f4a351306de78453d5c35bbaa4f8f0717db9029.tar.gz
bcm5719-llvm-5f4a351306de78453d5c35bbaa4f8f0717db9029.zip
[clangd] Show function documentation in signature help
Summary: Previously, clangd was trying to show documentation for the active parameter instead, which is wrong per LSP specification. Moreover, the code path that attempts to get parameter comments never succeds, because no attempt is made to parse function doc comment and extract parameter-specific parts out of it. So we also remove the code that claims to fetch parameter comments: it is not used anymore and is incorrect. Reviewers: hokein, ioeric, kadircet Reviewed By: ioeric Subscribers: MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50726 llvm-svn: 340004
Diffstat (limited to 'clang-tools-extra/clangd/CodeCompletionStrings.cpp')
-rw-r--r--clang-tools-extra/clangd/CodeCompletionStrings.cpp34
1 files changed, 8 insertions, 26 deletions
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
index e0277000c67..21db26e0808 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -51,44 +51,26 @@ std::string getDocComment(const ASTContext &Ctx,
// get this declaration, so we don't show documentation in that case.
if (Result.Kind != CodeCompletionResult::RK_Declaration)
return "";
- auto *Decl = Result.getDeclaration();
- if (!Decl || llvm::isa<NamespaceDecl>(Decl)) {
+ return Result.getDeclaration() ? getDeclComment(Ctx, *Result.getDeclaration())
+ : "";
+}
+
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
+ if (llvm::isa<NamespaceDecl>(Decl)) {
// Namespaces often have too many redecls for any particular redecl comment
// to be useful. Moreover, we often confuse file headers or generated
// comments with namespace comments. Therefore we choose to just ignore
// the comments for namespaces.
return "";
}
- const RawComment *RC = getCompletionComment(Ctx, Decl);
- if (!RC)
- return "";
-
- // Sanity check that the comment does not come from the PCH. We choose to not
- // write them into PCH, because they are racy and slow to load.
- assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
- std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
- if (!looksLikeDocComment(Doc))
- return "";
- return Doc;
-}
-
-std::string
-getParameterDocComment(const ASTContext &Ctx,
- const CodeCompleteConsumer::OverloadCandidate &Result,
- unsigned ArgIndex, bool CommentsFromHeaders) {
- auto *Func = Result.getFunction();
- if (!Func)
- return "";
- const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex);
+ const RawComment *RC = getCompletionComment(Ctx, &Decl);
if (!RC)
return "";
// Sanity check that the comment does not come from the PCH. We choose to not
// write them into PCH, because they are racy and slow to load.
assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
- if (!looksLikeDocComment(Doc))
- return "";
- return Doc;
+ return looksLikeDocComment(Doc) ? Doc : "";
}
void getSignature(const CodeCompletionString &CCS, std::string *Signature,
OpenPOWER on IntegriCloud