[clang-tools-extra] [clangd] Ignore section-divider comments in hover documentation (PR #225404)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 22 07:06:53 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Anthony Gaudino (Anthony-Gaudino)

<details>
<summary>Changes</summary>

## Summary

A comment block containing a section-divider line was reported as documentation for the next declaration. In practice this meant the title of a banner was shown on hover, e.g.:

```cpp
// Per-frame pump
// ========================================================================
void update(); // hover showed "Per-frame pump\n===..."
```

`getDeclComment` already filtered comments consisting solely of special characters (`looksLikeDocComment`), but a divider combined with a title line passed the filter and the title was shown as documentation.

## What this changes

- `looksLikeDocComment` (`CodeCompletionStrings.cpp`) now also rejects any comment containing a divider line: a line that, trimmed, is a run of 10+ repetitions of a single character. The check runs on the formatted text, so it applies regardless of comment style (`//`, `///`, `/* ... */`).
- The length threshold keeps short runs (markdown `---` rules and similar adornments) working as documentation; a regression test pins this boundary.

This affects hover and code-completion documentation, which share `getDeclComment`.

## Testing

- New cases in `TEST(Hover, Structured)`: titled `===` divider, same with a blank line before the declaration, `---` divider, `/* ### */` block banner, `+++` divider, and a short-run negative control.
- Verified the divider cases fail without the fix (hover showed the banner title) and pass with it.
- Full `ClangdTests` suite passes (1434 tests).

## Related

- Related to clangd/clangd#<!-- -->974 (divider banners matched across blank lines).

---
Full diff: https://github.com/llvm/llvm-project/pull/225404.diff


2 Files Affected:

- (modified) clang-tools-extra/clangd/CodeCompletionStrings.cpp (+27-1) 
- (modified) clang-tools-extra/clangd/unittests/HoverTests.cpp (+100) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


https://github.com/llvm/llvm-project/pull/225404


More information about the cfe-commits mailing list