[clang-tools-extra] r335718 - [clangd] Do not show namespace comments.

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 27 02:47:20 PDT 2018


Author: ibiryukov
Date: Wed Jun 27 02:47:20 2018
New Revision: 335718

URL: http://llvm.org/viewvc/llvm-project?rev=335718&view=rev
Log:
[clangd] Do not show namespace comments.

Summary:
Comments from namespaces that clangd produces are too noisy and often
not useful.

Namespaces have too many redecls and we don't have a good way of
determining which of the comments are relevant and which should be
ignored (e.g. because they come from code generators like the protobuf
compiler).

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ioeric, MaskRay, jkorous, cfe-commits

Differential Revision: https://reviews.llvm.org/D48211

Modified:
    clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
    clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=335718&r1=335717&r2=335718&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Wed Jun 27 02:47:20 2018
@@ -80,8 +80,16 @@ std::string getDocComment(const ASTConte
   if (Result.Kind != CodeCompletionResult::RK_Declaration)
     return "";
   auto *Decl = Result.getDeclaration();
-  if (!Decl || !canRequestComment(Ctx, *Decl, CommentsFromHeaders))
+  if (!Decl || 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 "";
+  }
+  if (!canRequestComment(Ctx, *Decl, CommentsFromHeaders))
+    return "";
+
   const RawComment *RC = getCompletionComment(Ctx, Decl);
   if (!RC)
     return "";

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=335718&r1=335717&r2=335718&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Jun 27 02:47:20 2018
@@ -1179,6 +1179,10 @@ TEST(CompletionTest, NonDocComments) {
   ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
 
   Annotations Source(R"cpp(
+    // We ignore namespace comments, for rationale see CodeCompletionStrings.h.
+    namespace comments_ns {
+    }
+
     // ------------------
     int comments_foo();
 
@@ -1223,6 +1227,7 @@ TEST(CompletionTest, NonDocComments) {
       UnorderedElementsAre(AllOf(Not(IsDocumented()), Named("comments_foo")),
                            AllOf(IsDocumented(), Named("comments_baz")),
                            AllOf(IsDocumented(), Named("comments_quux")),
+                           AllOf(Not(IsDocumented()), Named("comments_ns")),
                            // FIXME(ibiryukov): the following items should have
                            // empty documentation, since they are separated from
                            // a comment with an empty line. Unfortunately, I




More information about the cfe-commits mailing list