[PATCH] D50726: [clangd] Show function documentation in sigHelp
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 16 05:59:38 PDT 2018
ilya-biryukov updated this revision to Diff 161011.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.
- Expose getDeclComment instead of getDocComment
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D50726
Files:
clangd/CodeComplete.cpp
clangd/CodeCompletionStrings.cpp
clangd/CodeCompletionStrings.h
Index: clangd/CodeCompletionStrings.h
===================================================================
--- clangd/CodeCompletionStrings.h
+++ clangd/CodeCompletionStrings.h
@@ -32,18 +32,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: clangd/CodeCompletionStrings.cpp
===================================================================
--- clangd/CodeCompletionStrings.cpp
+++ clangd/CodeCompletionStrings.cpp
@@ -52,34 +52,20 @@
if (Result.Kind != CodeCompletionResult::RK_Declaration)
return "";
auto *Decl = Result.getDeclaration();
- if (!Decl || llvm::isa<NamespaceDecl>(Decl)) {
+ if (!Decl)
+ return "";
+ return getDeclComment(Ctx, *Decl);
+}
+
+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
Index: clangd/CodeComplete.cpp
===================================================================
--- clangd/CodeComplete.cpp
+++ 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.161011.patch
Type: text/x-patch
Size: 3954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180816/f6a66dd7/attachment.bin>
More information about the cfe-commits
mailing list