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) { 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::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(Decl)) { + if (!Decl) + return ""; + return getDeclComment(Ctx, *Decl); +} + +std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) { + if (llvm::isa(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