[PATCH] D50726: [clangd] Show function documentation in sigHelp
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 17 02:30:34 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340004: [clangd] Show function documentation in signature help (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
https://reviews.llvm.org/D50726
Files:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
Index: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
@@ -51,44 +51,26 @@
// 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,
Index: clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
===================================================================
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.h
@@ -33,18 +33,8 @@
const CodeCompletionResult &Result,
bool CommentsFromHeaders);
-/// Gets a minimally formatted documentation for parameter of \p Result,
-/// corresponding to argument number \p ArgIndex.
-/// This currently looks for comments attached to the parameter itself, and
-/// doesn't extract them from function documentation.
-/// Returns empty string when no comment is available.
-/// If \p CommentsFromHeaders parameter is set, only comments from the main
-/// file will be returned. It is used to workaround crashes when parsing
-/// comments in the stale headers, coming from completion preamble.
-std::string
-getParameterDocComment(const ASTContext &Ctx,
- const CodeCompleteConsumer::OverloadCandidate &Result,
- unsigned ArgIndex, bool CommentsFromHeaders);
+/// Similar to getDocComment, but returns the comment for a NamedDecl.
+std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &D);
/// Formats the signature for an item, as a display string and snippet.
/// e.g. for const_reference std::vector<T>::at(size_type) const, this returns:
Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -729,8 +729,9 @@
// FIXME: for headers, we need to get a comment from the index.
ScoredSignatures.push_back(processOverloadCandidate(
Candidate, *CCS,
- getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
- /*CommentsFromHeaders=*/false)));
+ Candidate.getFunction()
+ ? getDeclComment(S.getASTContext(), *Candidate.getFunction())
+ : ""));
}
std::sort(ScoredSignatures.begin(), ScoredSignatures.end(),
[](const ScoredSignature &L, const ScoredSignature &R) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50726.161188.patch
Type: text/x-patch
Size: 4724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180817/66e02835/attachment.bin>
More information about the llvm-commits
mailing list