https://github.com/liepieshov updated https://github.com/llvm/llvm-project/pull/164854
>From 8d5d646dae02c2de86451c425d1e2a6f58701fc7 Mon Sep 17 00:00:00 2001 From: Kostia Liepieshov <[email protected]> Date: Thu, 23 Oct 2025 17:31:45 +0000 Subject: [PATCH] [Autocomplete] skip static annotation comment Skip /*static*/ annotation on function definitions to use the better defined declaration documentation. --- .../clangd/unittests/HoverTests.cpp | 16 ++++++++++++++++ clang/lib/AST/ASTContext.cpp | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 718c1bc5f355a..d0b88918894c0 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2019,6 +2019,22 @@ TEST(Hover, All) { HI.Definition = "class Foo {}"; HI.Documentation = "Forward class declaration"; }}, + { + R"cpp(// Function declaration ignore static annotation + void foo(); + /*static*/ void foo() {} + void g() { [[f^oo]](); } + )cpp", + [](HoverInfo &HI) { + HI.Name = "foo"; + HI.Kind = index::SymbolKind::Function; + HI.NamespaceScope = ""; + HI.Type = "void ()"; + HI.Definition = "void foo()"; + HI.Documentation = "Function declaration ignore static annotation"; + HI.ReturnType = "void"; + HI.Parameters = std::vector<HoverInfo::Param>{}; + }}, { R"cpp(// Function declaration void foo(); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 32c8f6209a693..1cbd48d3cfdda 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -330,6 +330,11 @@ void ASTContext::addComment(const RawComment &RC) { Comments.addComment(RC, LangOpts.CommentOpts, BumpAlloc); } +bool skipCommentContent(StringRef Text) { + return Text == "/*static*/" || Text == "/*virtual*/" \ + || Text == "/* static */" || Text == "/* virtual */"; +} + const RawComment *ASTContext::getRawCommentForAnyRedecl( const Decl *D, const Decl **OriginalDecl) const { @@ -398,7 +403,7 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl( continue; } const RawComment *RedeclComment = getRawCommentForDeclNoCache(Redecl); - if (RedeclComment) { + if (RedeclComment && !skipCommentContent(RedeclComment->getRawText(SourceMgr))) { cacheRawCommentForDecl(*Redecl, *RedeclComment); if (OriginalDecl) *OriginalDecl = Redecl; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
