Skip to content

fix(semantic-tokens): filter ineligible highlight references - #434

Merged
16bit-ykiko merged 8 commits into
mainfrom
requests/highlight-name-filter/d9eec958-acd5-4df7-92cc--c074498e6e1badd9/a1-proposal-1
Jun 4, 2026
Merged

16bit-ykiko merged 8 commits into
mainfrom
requests/highlight-name-filter/d9eec958-acd5-4df7-92cc--c074498e6e1badd9/a1-proposal-1

Conversation

@Myriad-Dreamin

@Myriad-Dreamin Myriad-Dreamin commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

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

    • Improved semantic token highlighting to suppress ineligible operator references lacking meaningful source text.
    • Ensured constructor and destructor names remain properly highlighted with correct visual modifiers.
  • Tests

    • Added test coverage for semantic token highlighting behavior across various declaration types.

Review Change Stack

@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fe0d8506-dc8b-4926-bb87-45f894aa26a5

📥 Commits

Reviewing files that changed from the base of the PR and between f1c2841 and 0557d60.

📒 Files selected for processing (1)
  • src/feature/semantic_tokens.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/feature/semantic_tokens.cpp

📝 Walkthrough

Walkthrough

This PR refines semantic token emission by filtering out declaration references with ineligible names. A new helper determines which declaration name kinds warrant syntax highlighting by kind, and the reference-handling path now early-returns before computing modifiers and emitting tokens for those ineligible occurrences.

Changes

Semantic Token Filtering

Layer / File(s) Summary
Declaration name highlighting filter
src/feature/semantic_tokens.cpp
Introduces can_highlight_name helper that validates declaration names based on NameKind (allowing identifiers with non-empty text and most C++ names but filtering ObjC selector kinds), and integrates it into handleDeclOccurrence to early-return for reference relations when a name is ineligible, skipping modifier computation and token emission.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • clice-io/clice#395: Both PRs modify SemanticTokensCollector::handleDeclOccurrence to control semantic token emission and modifiers for declaration references.

Suggested reviewers

  • 16bit-ykiko

Poem

🐰 A filter to refine the shine,
Operators and selectors need not define,
Eligibility checked with care and grace,
Tokens flow only to the proper place!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(semantic-tokens): filter ineligible highlight references' accurately summarizes the main change: adding filtering to suppress unsupported reference tokens in semantic-token highlighting based on declaration-name eligibility.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch requests/highlight-name-filter/d9eec958-acd5-4df7-92cc--c074498e6e1badd9/a1-proposal-1

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@Myriad-Dreamin
Myriad-Dreamin marked this pull request as ready for review April 21, 2026 18:54

@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.

🧹 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 CXXConstructorName were accidentally removed from can_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

📥 Commits

Reviewing files that changed from the base of the PR and between 17e6801 and f1c2841.

📒 Files selected for processing (5)
  • .gitignore
  • src/feature/semantic_tokens.cpp
  • src/semantic/ast_utility.cpp
  • src/semantic/ast_utility.h
  • tests/unit/feature/semantic_tokens_tests.cpp

@16bit-ykiko
16bit-ykiko merged commit 3b45888 into main Jun 4, 2026
20 checks passed
@16bit-ykiko
16bit-ykiko deleted the requests/highlight-name-filter/d9eec958-acd5-4df7-92cc--c074498e6e1badd9/a1-proposal-1 branch June 4, 2026 16:03
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.

2 participants