Skip to content

feat(lsp): textDocument/documentHighlight#4081

Open
codeshaunted wants to merge 1 commit into
canaryfrom
avery/document-highlight
Open

feat(lsp): textDocument/documentHighlight#4081
codeshaunted wants to merge 1 commit into
canaryfrom
avery/document-highlight

Conversation

@codeshaunted

@codeshaunted codeshaunted commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Highlights all same-file occurrences of the symbol under the cursor — declaration + usages for locals, parameters, top-level items, and class fields.

  • New document_highlights_at in baml_lsp2_actions reuses the usages_at machinery restricted to the request file: the LSP scopes highlights to one document and editors re-request them on every cursor move, so the package-wide CST scan usages_at does would be wasted work. usages_at behavior is unchanged (it delegates to the same impl with package-wide scope).
  • The declaration occurrence is added back (usages_at excludes it by contract), narrowed to its name token — the semantic index's recorded local range covers let name and a parameter's signature span covers name: type, both too wide to highlight.
  • The enclosing-function scope walk that usages_at and definition_at each had a private copy of is now shared as utils::enclosing_function_loc.
  • No DocumentHighlightKind: BAML has no reassignment, so the read/write split carries no signal.
  • Handler + document_highlight_provider capability wired in bex_project.

Tests: 5 new cursor-marker tests (highlights_tests.rs) covering local declaration+usages from both cursor positions, parameters, cross-file isolation, and non-identifier positions.

Summary by CodeRabbit

  • New Features

    • Added document highlighting for symbols in the current file.
    • Highlights declarations and matching usages for local variables, parameters, and definitions.
    • Advertised document highlighting support through the language server.
  • Bug Fixes

    • Prevented highlights and usage results from crossing into unrelated files.
    • Improved behavior when the cursor is not positioned on an identifier.
  • Tests

    • Added coverage for declarations, usages, parameters, cross-file isolation, and non-identifier positions.

Highlight all same-file occurrences of the symbol under the cursor:
declaration + usages for locals, parameters, top-level items, and class
fields. New document_highlights_at in baml_lsp2_actions reuses the
usages machinery restricted to the request file (highlights fire on
every cursor move, so the package-wide scan usages_at does would be
wasted work), then adds the declaration occurrence back, narrowed to
its name token (the recorded local range covers 'let name' and a
param's covers 'name: type').

Shares the enclosing-function scope walk that usages_at and
definition_at each had their own copy of via a new
utils::enclosing_function_loc. No highlight kinds: BAML has no
reassignment, so the read/write split carries no signal.
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 17, 2026 11:25pm
promptfiddle Ready Ready Preview, Comment Jul 17, 2026 11:25pm
promptfiddle2 Ready Ready Preview, Comment Jul 17, 2026 11:25pm

Request Review

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dd19fe40-320e-4757-94ac-de86cd49d72c

📥 Commits

Reviewing files that changed from the base of the PR and between b48935e and 20e051b.

📒 Files selected for processing (8)
  • baml_language/crates/baml_lsp2_actions/src/definition.rs
  • baml_language/crates/baml_lsp2_actions/src/highlights.rs
  • baml_language/crates/baml_lsp2_actions/src/highlights_tests.rs
  • baml_language/crates/baml_lsp2_actions/src/lib.rs
  • baml_language/crates/baml_lsp2_actions/src/testing.rs
  • baml_language/crates/baml_lsp2_actions/src/usages.rs
  • baml_language/crates/baml_lsp2_actions/src/utils.rs
  • baml_language/crates/bex_project/src/bex_lsp/multi_project/request.rs

📝 Walkthrough

Walkthrough

Adds LSP textDocument/documentHighlight support for same-file symbols, including declaration and usage ranges, shared function-scope resolution, tests, public action wiring, and BEX request handling.

Changes

Document highlight support

Layer / File(s) Summary
Shared usage and function resolution
baml_language/crates/baml_lsp2_actions/src/utils.rs, baml_language/crates/baml_lsp2_actions/src/usages.rs, baml_language/crates/baml_lsp2_actions/src/definition.rs
Adds shared enclosing-function resolution and refactors usage scanning to support explicit same-file or package-wide file sets.
Highlight computation and validation
baml_language/crates/baml_lsp2_actions/src/highlights.rs, baml_language/crates/baml_lsp2_actions/src/lib.rs, baml_language/crates/baml_lsp2_actions/src/testing.rs, baml_language/crates/baml_lsp2_actions/src/highlights_tests.rs
Computes declaration and same-file usage ranges, exports the action, adds cursor-test support, and validates locals, parameters, cross-file isolation, and non-identifier positions.
LSP capability and request wiring
baml_language/crates/bex_project/src/bex_lsp/multi_project/request.rs
Advertises document highlighting and converts returned byte ranges into LSP DocumentHighlight values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LSPClient
  participant BexMulitProject
  participant document_highlights_at
  LSPClient->>BexMulitProject: textDocument/documentHighlight request
  BexMulitProject->>document_highlights_at: file and cursor offset
  document_highlights_at-->>BexMulitProject: sorted same-file ranges
  BexMulitProject-->>LSPClient: DocumentHighlight values
Loading

Suggested reviewers: rossirpaulo

Poem

A rabbit hops through names in flight,
Finding each token, clear and bright.
Local, parameter, file-bound glow,
Through BEX the highlight ranges flow.
“Hop!” says Bun—“the symbols show!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately names the main change: adding LSP document highlight support.
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.
✨ 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 avery/document-highlight

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.

@github-actions

Copy link
Copy Markdown

Binary size checks failed

4 violations · ✅ 3 passed

⚠️ Please fix the size gate issues or acknowledge them by updating baselines.

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 25.3 MB 10.7 MB file 24.5 MB +744.6 KB (+3.0%) FAIL
packed-program Linux 🔒 17.0 MB 7.0 MB file 17.0 MB -4.1 KB (-0.0%) OK
baml-cli macOS 🔒 19.5 MB 9.3 MB file 18.9 MB +628.4 KB (+3.3%) FAIL
packed-program macOS 🔒 13.2 MB 6.2 MB file 13.2 MB +0 B (+0.0%) OK
baml-cli Windows 🔒 21.1 MB 9.5 MB file 20.4 MB +627.2 KB (+3.1%) FAIL
packed-program Windows 🔒 14.1 MB 6.2 MB file 14.1 MB -512 B (-0.0%) OK
bridge_wasm WASM 16.2 MB 🔒 4.4 MB gzip 4.3 MB +133.5 KB (+3.1%) FAIL

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.

Details & how to fix

Violations:

  • baml-cli (Linux) file_bytes: 25.3 MB exceeds limit of 25.2 MB (exceeded by +9.4 KB, policy: max_file_bytes)
  • baml-cli (Linux) file_delta_pct: +3.0% exceeds limit of 3.0% (exceeded by +0.0pp, policy: max_delta_pct)
  • baml-cli (macOS) file_bytes: 19.5 MB exceeds limit of 19.5 MB (exceeded by +61.4 KB, policy: max_file_bytes)
  • baml-cli (macOS) file_delta_pct: +3.3% exceeds limit of 3.0% (exceeded by +0.3pp, policy: max_delta_pct)
  • baml-cli (Windows) file_bytes: 21.1 MB exceeds limit of 21.0 MB (exceeded by +14.4 KB, policy: max_file_bytes)
  • baml-cli (Windows) file_delta_pct: +3.1% exceeds limit of 3.0% (exceeded by +0.1pp, policy: max_delta_pct)
  • bridge_wasm (WASM) gzip_bytes: 4.4 MB exceeds limit of 4.4 MB (exceeded by +5.3 KB, policy: max_gzip_bytes)
  • bridge_wasm (WASM) gzip_delta_pct: +3.1% exceeds limit of 3.0% (exceeded by +0.1pp, policy: max_delta_pct)

Add/update baselines:

.ci/size-gate/aarch64-apple-darwin.toml:

[artifacts.baml-cli]
file_bytes = 19528576
stripped_bytes = 19528624
gzip_bytes = 9327682

.ci/size-gate/wasm32-unknown-unknown.toml:

[artifacts.bridge_wasm]
file_bytes = 16170257
gzip_bytes = 4405840

.ci/size-gate/x86_64-pc-windows-msvc.toml:

[artifacts.baml-cli]
file_bytes = 21053952
stripped_bytes = 21053952
gzip_bytes = 9535850

.ci/size-gate/x86_64-unknown-linux-gnu.toml:

[artifacts.baml-cli]
file_bytes = 25252304
stripped_bytes = 25252296
gzip_bytes = 10724634

Generated by cargo size-gate · workflow run

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