[clangd] Don't show header for namespace decl in Hover
authorHaojian Wu <hokein.wu@gmail.com>
Thu, 29 Jun 2023 11:57:36 +0000 (13:57 +0200)
committerHaojian Wu <hokein.wu@gmail.com>
Thu, 29 Jun 2023 15:11:19 +0000 (17:11 +0200)
The header for namespace symbol is barely useful.

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

clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

index 5184fcb..fbd0be0 100644 (file)
@@ -1374,7 +1374,10 @@ std::optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
         if (!HI->Value)
           HI->Value = printExprValue(N, AST.getASTContext()).PrintedValue;
         maybeAddCalleeArgInfo(N, *HI, PP);
-        maybeAddSymbolProviders(AST, *HI, include_cleaner::Symbol{*DeclToUse});
+
+        if (!isa<NamespaceDecl>(DeclToUse))
+          maybeAddSymbolProviders(AST, *HI,
+                                  include_cleaner::Symbol{*DeclToUse});
       } else if (const Expr *E = N->ASTNode.get<Expr>()) {
         HoverCountMetric.record(1, "expr");
         HI = getHoverContents(N, E, AST, PP, Index);
index 7002e27..0f45e78 100644 (file)
@@ -3059,7 +3059,13 @@ TEST(Hover, Providers) {
                   }
                   ns::F^oo d;
                 )cpp",
-                [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }}};
+                [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
+                {R"cpp(
+                  namespace foo {};
+                  using namespace fo^o;
+                )cpp",
+                [](HoverInfo &HI) { HI.Provider = ""; }},
+                };
 
   for (const auto &Case : Cases) {
     Annotations Code{Case.Code};