Skip to content

Add variable/constructor/tvar binding-reference highlighting#2187

Merged
disconcision merged 12 commits intoprobes-IIIfrom
var-highlight
Mar 23, 2026
Merged

Add variable/constructor/tvar binding-reference highlighting#2187
disconcision merged 12 commits intoprobes-IIIfrom
var-highlight

Conversation

@disconcision
Copy link
Member

@disconcision disconcision commented Mar 23, 2026

  • Adds caret-based highlighting of related variable bindings and references: when the cursor is on a variable reference, its binding site and sibling uses are highlighted, and vice versa
  • Supports expression variables, constructors (bidirectional: definition ↔ expr/pat uses), and type variables
  • Uses existing statics infrastructure (co_ctx, ctx) for O(1) lookups; adds tvar_co_ctx to InfoTPat via a single post-processing pass for type variable highlighting
disconcision and others added 12 commits March 22, 2026 16:49
When the caret is on a variable binding (pattern) or reference (expression), highlights related bindings and uses with an underline + subtle background. Supports variables, constructors, and type variables. - StaticsBase: add uses_of_binding (handles let and fun forms) and var_highlight_ids (computes related IDs for any Info.t) - VarHighlight.re: new decoration module computing and rendering overlays - CodeEditable: wire VarHighlight into the decoration layer - editor.css: styling for var-highlight overlays Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When the mouse hovers over a variable binding or reference, highlights related bindings and uses with a dashed underline + background. Hover highlights take precedence over caret highlights when present. - Measured: add piece_at_point for point-to-piece hit testing - CodeWithStatics: add hover_id to model state - CodeEditable: add Hover action, extend mousemove handler to dispatch hover updates when no button held, add mouseleave to clear hover - VarHighlight: compute highlights from both caret and hover sources - editor.css: dashed underline style for hover variant Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rewrite uses_of_binding to scan info_map instead of climbing ancestors. The old approach only handled Let/Fun; now works for all binding forms (match/case, fixf, theorem, etc.) without enumerating them. - Fix multiple references: old code used VarMap.lookup (List.assoc_opt) which only returned first co_ctx entry due to CoCtx.union concatenation. - Add bidirectional type variable highlighting (InfoTPat binding→uses). - Disable hover dispatch (infrastructure retained for future re-enablement). - Clean up VarHighlight.re: use DecUtil.abs_style, remove debug logging. - Move styling to CSS (border-bottom + subtle background tint). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9 tests: let ref→binding, let binding→refs, fun params, match/case bindings (both directions), shadowing, multiple refs, type variable ref→binding, type variable binding→refs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- CoCtx.union: properly merge entries for same variable name instead of concatenating (which caused VarMap.lookup to shadow duplicates). - uses_of_binding: use InfoPat.co_ctx directly instead of scanning the entire info_map. O(1) lookup instead of O(n) scan. - Ctx.add_ctrs: use each variant's own annotation ID instead of the type definition's ID, so constructor highlights point to individual constructor declarations rather than the whole sum type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Populate InfoTPat.tvar_co_ctx via a post-processing pass in Statics.mk so uses_of_tvar_binding does O(1) lookup instead of scanning the info_map. Add constructor highlight tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Hover dispatch restored in mousemove handler with equality check to avoid redundant dispatches. Hover highlights shown with dashed underline; caret highlights remain as fallback when hover target has no variable info. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The pattern's co_ctx was only receiving body.co_ctx, so recursive self-references inside the definition weren't visible as uses. Now unions def.co_ctx with body.co_ctx. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Drop hover_id from Model, Hover action variant, mousemove dispatch, piece_at_point, hover CSS, and all related wiring. Caret-based highlighting is sufficient. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Constructor references now register in co_ctx (like Var does), so uses bubble up to the enclosing TyAlias. uses_of_ctr_binding climbs ancestors to read them. Enables definition→uses and reference→sibling highlighting for constructors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pattern constructors (e.g. `A` in `| A => ...`) now contribute to co_ctx via collect_pat_ctr_refs, wired into all expression forms with patterns (Fun, Let, Theorem, FixF, Case). This enables bidirectional highlighting between constructor definitions, expression uses, and pattern uses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@disconcision disconcision requested a review from 7h3kk1d March 23, 2026 02:44
@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 70.31250% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.28%. Comparing base (768e78e) to head (9761759).
⚠️ Report is 50 commits behind head on probes-III.

Files with missing lines Patch % Lines
src/web/app/editors/decoration/VarHighlight.re 0.00% 15 Missing ⚠️
src/language/statics/StaticsBase.re 77.77% 14 Missing ⚠️
src/web/app/editors/code/CodeEditable.re 0.00% 4 Missing ⚠️
src/language/statics/Statics.re 90.62% 3 Missing ⚠️
src/language/statics/Ctx.re 85.71% 1 Missing ⚠️
src/language/statics/Info.re 50.00% 1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@ ## probes-III #2187 +/- ## ============================================== + Coverage 51.20% 51.28% +0.07%  ============================================== Files 251 252 +1 Lines 30225 30341 +116 ============================================== + Hits 15478 15561 +83  - Misses 14747 14780 +33 
Files with missing lines Coverage Δ
src/language/statics/CoCtx.re 78.57% <100.00%> (+3.57%) ⬆️
src/web/app/editors/code/CodeWithStatics.re 29.62% <ø> (ø)
src/language/statics/Ctx.re 50.79% <85.71%> (+2.40%) ⬆️
src/language/statics/Info.re 45.36% <50.00%> (-0.08%) ⬇️
src/language/statics/Statics.re 86.38% <90.62%> (-0.01%) ⬇️
src/web/app/editors/code/CodeEditable.re 0.00% <0.00%> (ø)
src/language/statics/StaticsBase.re 65.69% <77.77%> (+10.28%) ⬆️
src/web/app/editors/decoration/VarHighlight.re 0.00% <0.00%> (ø)

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@disconcision disconcision merged commit 35c6ade into probes-III Mar 23, 2026
4 checks passed
@disconcision disconcision deleted the var-highlight branch March 23, 2026 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant