ilya-biryukov created this revision. ilya-biryukov added a reviewer: sammccall. Herald added subscribers: jkorous, MaskRay, ioeric.
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). Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D48211 Files: clangd/CodeCompletionStrings.cpp unittests/clangd/CodeCompleteTests.cpp Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -1110,6 +1110,10 @@ 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(); @@ -1151,6 +1155,7 @@ 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 Index: clangd/CodeCompletionStrings.cpp =================================================================== --- clangd/CodeCompletionStrings.cpp +++ clangd/CodeCompletionStrings.cpp @@ -174,6 +174,14 @@ auto *Decl = Result.getDeclaration(); if (!Decl || !canRequestComment(Ctx, *Decl, CommentsFromHeaders)) return ""; + 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 "";
Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -1110,6 +1110,10 @@ 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(); @@ -1151,6 +1155,7 @@ 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 Index: clangd/CodeCompletionStrings.cpp =================================================================== --- clangd/CodeCompletionStrings.cpp +++ clangd/CodeCompletionStrings.cpp @@ -174,6 +174,14 @@ auto *Decl = Result.getDeclaration(); if (!Decl || !canRequestComment(Ctx, *Decl, CommentsFromHeaders)) return ""; + 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 "";
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits