Skip to content

feat(lsp): double-click-to-insert text edits on type inlay hints#4080

Open
codeshaunted wants to merge 2 commits into
canaryfrom
avery/inlay-hint-edits
Open

feat(lsp): double-click-to-insert text edits on type inlay hints#4080
codeshaunted wants to merge 2 commits into
canaryfrom
avery/inlay-hint-edits

Conversation

@codeshaunted

@codeshaunted codeshaunted commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Type inlay hints on let bindings now carry LSP textEdits that insert the label at the hint position, so double-clicking a hint in VS Code turns : int into a real annotation (rust-analyzer style). Parameter-name hints get no edits since there is nothing to insert.

Edits are attached only when the rendered type is valid, resolvable surface syntax, decided by a new ty_is_insertable walk on Ty in baml_lsp2_actions::annotations. The classification was verified against baml-cli check rather than guessed:

Insertable: primitives, classes, enums, enum variants (Color.R), unions, maps, lists, function types with throws clauses, never, unknown, type, int/bigint/negative literal types, interface names, in-scope generic params, evolved empty literals (render as plain int[]).

Not insertable: Future<...> (unresolvable name in type position), _[] / map<_, _> (never-evolved empty literals, not parseable), float literal types (parser rejects), synthetic callback effect params, associated-type projections, void, and the opaque runtime leafs ($rust_type, baml.llm.Resource, baml.llm.PromptAst).

The LSP handler builds the edit as a zero-width insert at the hint offset with the label text; resolve_provider stays false since edits are attached eagerly.

Summary by CodeRabbit

  • New Features

    • Inlay hints can now provide interactive text edits when the hint’s displayed type is valid, insertable syntax.
    • Eligible type hints can be applied via double-click to insert the corresponding text.
  • Bug Fixes

    • Prevented text edits from being offered for non-insertable, unresolved/invalid, or parameter-name inlay hints.

Type hints on let bindings now carry LSP textEdits inserting the label
at the hint position, so VS Code's double-click-to-apply turns a ': int'
hint into a real annotation (rust-analyzer style).

Edits are attached only when the rendered type is valid, resolvable
surface syntax, via a new ty_is_insertable walk on Ty. Verified against
the compiler: enum variants, function types with throws, never, unknown,
type, int/bigint literal types, and interface names are insertable;
Future<...> (unresolvable), _[] / map<_, _> (never-evolved empty
literals), float literal types (parser rejects), synthetic callback
effect params, associated-type projections, and opaque runtime leafs are
not. Parameter-name hints get no edits (nothing to insert).
@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:14pm
promptfiddle Ready Ready Preview, Comment Jul 17, 2026 11:14pm
promptfiddle2 Ready Ready Preview, Comment Jul 17, 2026 11:14pm

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: e304dcab-b167-4c53-8ac2-04c75a0ae244

📥 Commits

Reviewing files that changed from the base of the PR and between 9a47198 and ffc16a3.

📒 Files selected for processing (1)
  • baml_language/crates/baml_lsp2_actions/src/annotations.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • baml_language/crates/baml_lsp2_actions/src/annotations.rs

📝 Walkthrough

Walkthrough

Type and parameter inlay annotations now expose an insertable flag. The LSP inlay-hint handler uses this flag to conditionally provide text edits for valid type-hint labels.

Changes

Inlay hint editability

Layer / File(s) Summary
Annotation insertability classification
baml_language/crates/baml_lsp2_actions/src/annotations.rs
InlineAnnotation records insertability; type hints classify supported syntax, parameter hints remain non-insertable, and tests cover both cases.
LSP text edit wiring
baml_language/crates/bex_project/src/bex_lsp/multi_project/request.rs
The inlay-hint handler emits a zero-length text edit containing the label only when the annotation is insertable.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TypeHintGenerator
  participant InlineAnnotation
  participant InlayHintHandler
  participant LSPClient
  TypeHintGenerator->>InlineAnnotation: create annotation with insertable flag
  InlineAnnotation->>InlayHintHandler: provide label and insertability
  InlayHintHandler->>LSPClient: return conditional text edit
Loading

Possibly related PRs

  • BoundaryML/baml#3176: Extends the inlay-hint pipeline with edit support related to type and parameter hint insertion.

Poem

I’m a rabbit with hints in my den,
Now valid type text can hop in again.
Bad shapes stay still, parameters rest,
Insertable labels pass the test.
LSP edits bloom where syntax is best.

🚥 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 clearly and concisely summarizes the main change: adding double-click-to-insert text edits for type inlay hints.
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/inlay-hint-edits

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

github-actions Bot commented Jul 17, 2026

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.2 MB 10.7 MB file 24.5 MB +737.8 KB (+3.0%) FAIL
packed-program Linux 🔒 17.0 MB 7.0 MB file 17.0 MB +0 B (+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.0 MB 9.5 MB file 20.4 MB +622.1 KB (+3.0%) FAIL
packed-program Windows 🔒 14.1 MB 6.2 MB file 14.1 MB +0 B (+0.0%) OK
bridge_wasm WASM 16.2 MB 🔒 4.4 MB gzip 4.3 MB +130.7 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.2 MB exceeds limit of 25.2 MB (exceeded by +2.6 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.0 MB exceeds limit of 21.0 MB (exceeded by +9.3 KB, policy: max_file_bytes)
  • baml-cli (Windows) file_delta_pct: +3.0% exceeds limit of 3.0% (exceeded by +0.0pp, policy: max_delta_pct)
  • bridge_wasm (WASM) gzip_bytes: 4.4 MB exceeds limit of 4.4 MB (exceeded by +2.6 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 = 19528560
stripped_bytes = 19528608
gzip_bytes = 9324616

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

[artifacts.bridge_wasm]
file_bytes = 16161152
gzip_bytes = 4403113

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

[artifacts.baml-cli]
file_bytes = 21048832
stripped_bytes = 21048832
gzip_bytes = 9535103

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

[artifacts.baml-cli]
file_bytes = 25245456
stripped_bytes = 25245448
gzip_bytes = 10721454

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