fix(semantic-tokens): filter ineligible highlight references#434
Conversation
📝 WalkthroughWalkthroughThis PR adds suppression logic for semantic tokens on references with non-highlightable declaration names. A new utility function classifies declaration names (Identifiers, constructors, destructors) that can be highlighted. The semantic token collector now early-returns for references with non-highlightable names, preventing token emission. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/feature/semantic_tokens_tests.cpp (1)
285-307: Add a constructor reference case to exercise the new guard.Line 303 and Line 305 assert constructor declaration/definition tokens, but the new filter only runs for references. If
CXXConstructorNamewere accidentally removed fromcan_highlight_name, these constructor assertions would still pass. Add a constructor-call/reference assertion alongside the destructor reference.Suggested coverage addition
void use(S* value) { + (void)@ctor_ref[S](); value->@dtor_ref[~]S(); } )cpp"); @@ EXPECT_TOKEN("ctor_decl", SymbolKind::Method, declaration | special_member); EXPECT_TOKEN("dtor_decl", SymbolKind::Method, declaration | special_member); EXPECT_TOKEN("ctor_def", SymbolKind::Method, definition | special_member); + EXPECT_TOKEN("ctor_ref", SymbolKind::Method, special_member); EXPECT_TOKEN("dtor_ref", SymbolKind::Method, special_member); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/feature/semantic_tokens_tests.cpp` around lines 285 - 307, Add a constructor-reference case in the ConstructorAndDestructorNamesRemainHighlighted test by inserting a constructor call annotated like new `@ctor_ref`[S](); (or equivalent call site) inside the run_utf8 sample, and then add an assertion EXPECT_TOKEN("ctor_ref", SymbolKind::Method, special_member) alongside the existing dtor_ref assertion; this ensures the new guard that runs only for references (can_highlight_name) is exercised for constructors as well. Ensure you use the same modifier_mask special_member and the unique token name "ctor_ref" so the test locates the annotation and validates the constructor reference highlighting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/unit/feature/semantic_tokens_tests.cpp`:
- Around line 285-307: Add a constructor-reference case in the
ConstructorAndDestructorNamesRemainHighlighted test by inserting a constructor
call annotated like new `@ctor_ref`[S](); (or equivalent call site) inside the
run_utf8 sample, and then add an assertion EXPECT_TOKEN("ctor_ref",
SymbolKind::Method, special_member) alongside the existing dtor_ref assertion;
this ensures the new guard that runs only for references (can_highlight_name) is
exercised for constructors as well. Ensure you use the same modifier_mask
special_member and the unique token name "ctor_ref" so the test locates the
annotation and validates the constructor reference highlighting.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 58aa4fe0-cee0-48a2-ab29-e854b9931069
📒 Files selected for processing (5)
.gitignoresrc/feature/semantic_tokens.cppsrc/semantic/ast_utility.cppsrc/semantic/ast_utility.htests/unit/feature/semantic_tokens_tests.cpp
Add a reusable declaration-name eligibility helper that mirrors clangd's
canHighlightName, use it to suppress unsupported reference tokens in the semantic-token collector, and cover the change with focused semantic-token regression tests plus a constructor/destructor positive case.Summary by CodeRabbit
Bug Fixes
Tests
Chores
.gitignoreconfiguration.