Skip to content

feat(document symbols): specializations, aliases, macro names, semantics walk - #566

Merged
16bit-ykiko merged 3 commits into
mainfrom
test/document-symbol-snap-corpus
Aug 1, 2026
Merged

16bit-ykiko merged 3 commits into
mainfrom
test/document-symbol-snap-corpus

Conversation

@16bit-ykiko

Copy link
Copy Markdown
Member

Third per-feature round after semantic tokens (#564) and inlay hints (#565): document symbols gets its traversal migrated onto the Semantics node table, four outline bugs fixed (plus one table-level bug in the builder), and its snap corpus rewoven into 24 doc-generating fixtures.

Traversal migrated onto the semantics node table

document_symbols.cpp no longer runs a FilteredASTVisitor over the TU. A single Collector walks the cached unit.semantics().node_entries() — the DFS pre-order record of the interested file's written AST. Nesting comes for free: a symbol's frame stays open while the walk index is inside its subtree_end, so the outline tree is rebuilt with a plain (subtree_end, cursor) stack, and implicit instantiations are skipped as an index jump. The migration was proven equivalent against the pre-existing snapshots and full unit suite before any behavior was changed.

One behavior improvement falls out of the table's recording contract: abbreviated function templates (void f(Concept auto x)) used to vanish from the outline entirely — the written FunctionDecl hides inside an implicit FunctionTemplateDecl, which the old visitor skipped wholesale. The builder records written children of implicit decls, so these functions now appear (pinned in kinds_templates).

Table-level fix: structured bindings recorded twice

Namespace-scope BindingDecls are members of the enclosing DeclContext and explicitly traversed by TraverseDecompositionDecl's bindings loop, so the builder recorded each one twice — every table consumer saw doubles (the outline showed each binding twice). The builder now records a BindingDecl only when its walk parent is its own DecompositionDecl. Block-scope and TU-scope bindings were already single-visit; both are pinned.

Outline fixes

  • Template specializations: explicit and partial specializations of class and variable templates never appeared (is_interested lacked their decl kinds); their members were orphaned at namespace level. Now Box<void>, Box<T*>, pi<int>, pi<T*> appear with members correctly nested.
  • Type aliases: typedef, using aliases and alias templates never appeared at all. They now render with a type alias detail, mapped to LSP Class (matching clangd).
  • Multi-token name selection ranges: ~Widget selected only the ~; operator== and operator bool selected only operator. Selection ranges now come from DeclarationNameInfo and cover the full written name.
  • Names spelled in macro arguments (clangd#1941): VAR(name) selected the macro name instead of name. The name range now goes through getFileLoc, so argument-spelled names select their written spelling while body-spelled names keep the invocation site; the symbol range is widened when needed to preserve the LSP range ⊇ selection-range invariant.

Corpus rewoven: 24 fixtures, doc generated from them

The 4 seed fixtures were replaced by 24 itemized fixtures with /// doc headers; document_symbol is registered in feature_docs.ts and the checklist sections of docs/en/features/document-symbols.md are now generated from the corpus. Probes confirmed several checklist items are supported by construction and are now pinned: default-argument stripping (clangd#221), multiline signature ranges (clangd#2221), macro-expansion symbol locations (clangd#475), friend function definitions, local symbols inside function bodies (clangd#616), and UTF-16 column counting (CJK fixture). Unsupported items (access-specifier grouping clangd#499, base-class detail, macro/include/module/#pragma mark outline entries, symbol tags clangd#2123) are recorded as compiled-out stubs. The count-based unit tests are retired; every case they touched is pinned structurally by a snapshot, including implicit instantiations not appearing.

Verification

All four suites green: unit (1168) and snap (280) on both RelWithDebInfo and Debug (LLVM assertions), integration (336), smoke (3/3), npm run check, feature_docs.ts check. Three-way pre-PR review (correctness / style / test coverage); findings addressed: inline comment style, reuse of decls::is_implicit_instantiation, and three added pins (implicit instantiation absence, block-scope bindings, static data member + named nested struct).

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: df73674a-d4e8-4ad2-b9c9-bdc1d95fc1b6

📥 Commits

Reviewing files that changed from the base of the PR and between 6c9dd76 and f894aea.

📒 Files selected for processing (5)
  • docs/en/features/document-symbols.md
  • src/feature/document_symbols.cpp
  • tests/snap/document_symbol/kinds_basic.cpp
  • tests/snap/document_symbol/kinds_specializations.cpp
  • tests/snap/document_symbol/kinds_specializations.snap.yml
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/feature/document_symbols.cpp
  • tests/snap/document_symbol/kinds_basic.cpp
  • docs/en/features/document-symbols.md

📝 Walkthrough

Walkthrough

The document-symbol collector now uses cached semantic nodes and explicit nesting state. It supports additional declaration kinds, range normalization, macro locations, and implicit-instantiation filtering. New snapshot fixtures and generated documentation cover hierarchy, symbol kinds, details, local symbols, and macro behavior.

Changes

Document symbols

Layer / File(s) Summary
Semantic binding traversal
src/semantic/semantics.cpp
Decomposition bindings are recorded only under their owning declarations.
Cached semantic symbol collection
src/feature/document_symbols.cpp, tools/snap/inspect.ts
Document symbols are collected from cached semantics. The collector reconstructs nesting, handles ranges and macros, includes specializations and aliases, skips implicit instantiations, and maps type symbols to Class.
Hierarchy and location fixtures
tests/snap/document_symbol/hierarchy_*.cpp, tests/snap/document_symbol/hierarchy_*.snap.yml
Snapshots cover nested, anonymous, inline, reopened, and compact namespaces, selection ranges, UTF-16 positions, and access-specifier grouping.
Symbol kind fixtures
tests/snap/document_symbol/kinds_*.cpp, tests/snap/document_symbol/kinds_*.snap.yml
Snapshots cover core declarations, templates, concepts, specializations, deduction guides, and type aliases.
Symbol detail and edge-case fixtures
tests/snap/document_symbol/detail_*.{cpp,yml}, tests/snap/document_symbol/{local_symbols,friend_definitions,macro_*,missing_*,tags_*}.*
Snapshots cover signatures, types, default arguments, multiline declarations, local symbols, friend definitions, macro locations, missing symbols, and tags.
Generated documentation and tooling
docs/en/features/document-symbols.md, tools/feature_docs.ts
Generated documentation now describes the expanded fixture coverage and changelog. The feature is mapped into documentation generation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes to document-symbol traversal and support for specializations, aliases, and macro names.
Description check ✅ Passed The description directly explains the traversal migration, behavior fixes, test corpus changes, and verification results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/document-symbol-snap-corpus

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c35e1849ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/feature/document_symbols.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/snap/document_symbol/kinds_basic.cpp`:
- Line 3: Update the heading comment in kinds_basic.cpp to state that the listed
constructs are represented in the outline, rather than claiming each maps to a
distinct LSP symbol kind. Regenerate the document-symbols snapshot documentation
in docs/en/features/document-symbols.md.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b92b8895-1221-4629-949a-4e1df82f473c

📥 Commits

Reviewing files that changed from the base of the PR and between 25daba3 and 6c9dd76.

📒 Files selected for processing (53)
  • docs/en/features/document-symbols.md
  • src/feature/document_symbols.cpp
  • src/semantic/semantics.cpp
  • tests/snap/document_symbol/basic.cpp
  • tests/snap/document_symbol/basic.snap.yml
  • tests/snap/document_symbol/detail_base_classes.cpp
  • tests/snap/document_symbol/detail_default_arguments.cpp
  • tests/snap/document_symbol/detail_default_arguments.snap.yml
  • tests/snap/document_symbol/detail_multiline_signatures.cpp
  • tests/snap/document_symbol/detail_multiline_signatures.snap.yml
  • tests/snap/document_symbol/detail_signatures.cpp
  • tests/snap/document_symbol/detail_signatures.snap.yml
  • tests/snap/document_symbol/detail_variable_types.cpp
  • tests/snap/document_symbol/detail_variable_types.snap.yml
  • tests/snap/document_symbol/friend_definitions.cpp
  • tests/snap/document_symbol/friend_definitions.snap.yml
  • tests/snap/document_symbol/hierarchy_access_specifiers.cpp
  • tests/snap/document_symbol/hierarchy_anonymous.cpp
  • tests/snap/document_symbol/hierarchy_anonymous.snap.yml
  • tests/snap/document_symbol/hierarchy_nesting.cpp
  • tests/snap/document_symbol/hierarchy_nesting.snap.yml
  • tests/snap/document_symbol/hierarchy_selection_ranges.cpp
  • tests/snap/document_symbol/hierarchy_selection_ranges.snap.yml
  • tests/snap/document_symbol/hierarchy_utf16.cpp
  • tests/snap/document_symbol/hierarchy_utf16.snap.yml
  • tests/snap/document_symbol/kinds_basic.cpp
  • tests/snap/document_symbol/kinds_basic.snap.yml
  • tests/snap/document_symbol/kinds_specializations.cpp
  • tests/snap/document_symbol/kinds_specializations.snap.yml
  • tests/snap/document_symbol/kinds_templates.cpp
  • tests/snap/document_symbol/kinds_templates.snap.yml
  • tests/snap/document_symbol/kinds_type_aliases.cpp
  • tests/snap/document_symbol/kinds_type_aliases.snap.yml
  • tests/snap/document_symbol/local_symbols.cpp
  • tests/snap/document_symbol/local_symbols.snap.yml
  • tests/snap/document_symbol/macro_argument_names.cpp
  • tests/snap/document_symbol/macro_argument_names.snap.yml
  • tests/snap/document_symbol/macro_symbols.cpp
  • tests/snap/document_symbol/macro_symbols.snap.yml
  • tests/snap/document_symbol/members.snap.yml
  • tests/snap/document_symbol/misc.cpp
  • tests/snap/document_symbol/misc.snap.yml
  • tests/snap/document_symbol/missing_includes.cpp
  • tests/snap/document_symbol/missing_macros.cpp
  • tests/snap/document_symbol/missing_modules.cpp
  • tests/snap/document_symbol/missing_pragma_mark.cpp
  • tests/snap/document_symbol/tags_deprecated.cpp
  • tests/snap/document_symbol/tags_modifiers.cpp
  • tests/snap/document_symbol/templates.cpp
  • tests/snap/document_symbol/templates.snap.yml
  • tests/unit/feature/document_symbol_tests.cpp
  • tools/feature_docs.ts
  • tools/snap/inspect.ts
💤 Files with no reviewable changes (8)
  • tests/snap/document_symbol/members.snap.yml
  • tests/snap/document_symbol/basic.snap.yml
  • tests/snap/document_symbol/templates.cpp
  • tests/unit/feature/document_symbol_tests.cpp
  • tests/snap/document_symbol/misc.snap.yml
  • tests/snap/document_symbol/templates.snap.yml
  • tests/snap/document_symbol/misc.cpp
  • tests/snap/document_symbol/basic.cpp

Comment thread tests/snap/document_symbol/kinds_basic.cpp Outdated
@16bit-ykiko
16bit-ykiko merged commit c5bd079 into main Aug 1, 2026
31 checks passed
@16bit-ykiko
16bit-ykiko deleted the test/document-symbol-snap-corpus branch August 1, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant