Skip to content

refactor(web): detect hoverable symbols via Lezer highlight tags#1194

Merged
brendan-kellam merged 2 commits into
mainfrom
brendan/codenav-tag-based-symbol-detection-sou-1077
May 12, 2026
Merged

refactor(web): detect hoverable symbols via Lezer highlight tags#1194
brendan-kellam merged 2 commits into
mainfrom
brendan/codenav-tag-based-symbol-detection-sou-1077

Conversation

@brendan-kellam
Copy link
Copy Markdown
Contributor

@brendan-kellam brendan-kellam commented May 12, 2026

Fixes SOU-1077

Summary

  • Replaces the hand-maintained NODE_TYPES list in symbolHoverTargetsExtension with a tag-based check that asks each node's highlight tag whether it descends from tags.name — the same vocabulary every CodeMirror grammar already uses for syntax highlighting. New grammars now work for free; the previously-missed C++ TypeIdentifier (return types, parameter types, base classes) is now detected, along with modifier-wrapped variants like definition(variableName).
  • Adds C/C++ aliasing to the language filter in codeNav/api.ts so search-based goto-definition resolves across both languages.
  • Adds vitest coverage in TypeScript+JSX, Python, Go, Rust, Java, C++, and PHP with positive (expected identifiers present) and negative (keywords/punctuation absent) assertions.

Test plan

  • yarn workspace @sourcebot/web vitest run src/ee/features/codeNav/components/symbolHoverPopup/symbolHoverTargetsExtension.test.ts — all 9 language tests pass
  • Open a TypeScript file in the browser; hover over identifiers (variables, types, JSX components) and verify the popup appears
  • Open a C++ file in the browser; hover over return types and parameter types and verify they now underline (regression vs. previous behavior where TypeIdentifier was missed)
  • In a C/C++ file, verify search-based goto-definition pulls results from both C and C++ indices

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced symbol hover detection to identify a broader range of code identifiers across all supported languages.
    • Fixed C language code navigation to properly include C++ matches.
  • Tests

    • Added comprehensive test coverage for symbol hover detection across JavaScript/TypeScript, Python, Go, Rust, Java, C++, and PHP.

Review Change Stack

Replaces the hand-maintained NODE_TYPES list in symbolHoverTargetsExtension
with a tag-based check that asks each node's highlight tag whether it descends
from `tags.name`. This is the same vocabulary every CodeMirror grammar already
uses for syntax highlighting, so identifier coverage now follows the grammar
authors' classification instead of a guess-driven cross-product of node names.

Side effects worth noting:
- Picks up C/C++ TypeIdentifier nodes that the old list missed (return types,
  parameter types, base classes).
- Picks up modifier-wrapped variants like `definition(variableName)` and
  `local(variableName)` automatically.
- Adds C/C++ aliasing to the language filter in codeNav api.ts so search-based
  goto-definition resolves across both.

Also adds vitest coverage exercising identifier detection in TypeScript+JSX,
Python, Go, Rust, Java, C++, and PHP with positive and negative assertions
(expected identifiers present, keywords/punctuation absent).

Fixes SOU-1077

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Walkthrough

The PR refactors symbol hover target detection to use Lezer highlight tags instead of hardcoded node types for broader identifier coverage, adds comprehensive multi-language test validation, enhances C/C++ language filtering, and updates the changelog.

Changes

Symbol hover targets detection

Layer / File(s) Summary
Identifier detection via Lezer highlight tags
packages/web/src/ee/features/codeNav/components/symbolHoverPopup/symbolHoverTargetsExtension.ts
Adds getStyleTags import from @lezer/highlight and replaces hardcoded NODE_TYPES with dynamic highlight tag inspection; nodes are now identified as hoverbable when their highlight tags include t.name.
Test suite for multi-language symbol detection
packages/web/src/ee/features/codeNav/components/symbolHoverPopup/symbolHoverTargetsExtension.test.ts
Introduces Vitest test file with CodeMirror editor helpers and assertion utilities; validates identifier detection across JavaScript/TypeScript, Python, Go, Rust, Java, C++, and PHP; tests edge cases including zero-width nodes and missing grammar extensions.
Language filter support for C and C++ variants
packages/web/src/features/codeNav/api.ts
getExpandedLanguageFilter now explicitly matches both "C" and "C++" together via an or query instead of handling them as separate language cases.
Changelog update
CHANGELOG.md
Documents the switch to Lezer highlight tags for symbol hover detection in the unreleased changelog section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • sourcebot-dev/sourcebot#325: Modifies the same symbolHoverTargetsExtension.ts file with related changes to node selection and decoration logic.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: refactoring symbol hover detection to use Lezer highlight tags instead of a manual node-types list.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 brendan/codenav-tag-based-symbol-detection-sou-1077

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.

@github-actions

This comment has been minimized.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@brendan-kellam brendan-kellam merged commit f006651 into main May 12, 2026
8 checks passed
@brendan-kellam brendan-kellam deleted the brendan/codenav-tag-based-symbol-detection-sou-1077 branch May 12, 2026 03:53
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