diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2018-06-15 08:31:17 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2018-06-15 08:31:17 +0000 |
commit | 89fcf6b2b6651354a4c2a5fdbffd5ece0470297f (patch) | |
tree | 9a063b20b5957b77c82f2328004d2c2924071e1e /clang-tools-extra/clangd/CodeCompletionStrings.cpp | |
parent | 0531ec654af2ee33c9d8e57f838e42519331f63c (diff) | |
download | bcm5719-llvm-89fcf6b2b6651354a4c2a5fdbffd5ece0470297f.tar.gz bcm5719-llvm-89fcf6b2b6651354a4c2a5fdbffd5ece0470297f.zip |
[clangd] Do not report comments that only have special chars.
Summary:
Like the following:
// -------
// =======
// *******
It does not cover all the cases, but those are definitely not very
useful.
Reviewers: sammccall, ioeric, hokein
Reviewed By: sammccall
Subscribers: MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D48171
llvm-svn: 334807
Diffstat (limited to 'clang-tools-extra/clangd/CodeCompletionStrings.cpp')
-rw-r--r-- | clang-tools-extra/clangd/CodeCompletionStrings.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp index 8cdaa3380b8..c3066939a5a 100644 --- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp +++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp @@ -151,6 +151,16 @@ bool canRequestComment(const ASTContext &Ctx, const NamedDecl &D, const ObjCPropertyDecl *PDecl = M ? M->findPropertyDecl() : nullptr; return !PDecl || canRequestForDecl(*PDecl); } + +bool LooksLikeDocComment(llvm::StringRef CommentText) { + // We don't report comments that only contain "special" chars. + // This avoids reporting various delimiters, like: + // ================= + // ----------------- + // ***************** + return CommentText.find_first_not_of("/*-= \t\r\n") != llvm::StringRef::npos; +} + } // namespace std::string getDocComment(const ASTContext &Ctx, @@ -167,7 +177,10 @@ std::string getDocComment(const ASTContext &Ctx, const RawComment *RC = getCompletionComment(Ctx, Decl); if (!RC) return ""; - return RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); + std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); + if (!LooksLikeDocComment(Doc)) + return ""; + return Doc; } std::string @@ -180,7 +193,10 @@ getParameterDocComment(const ASTContext &Ctx, const RawComment *RC = getParameterComment(Ctx, Result, ArgIndex); if (!RC) return ""; - return RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); + std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics()); + if (!LooksLikeDocComment(Doc)) + return ""; + return Doc; } void getLabelAndInsertText(const CodeCompletionString &CCS, std::string *Label, |