Skip to content

feat: chain through forced separators in grammar completion (#467 #343)#478

Open
SJrX wants to merge 1 commit into
issue-345-8from
issue-345-9
Open

feat: chain through forced separators in grammar completion (#467 #343)#478
SJrX wants to merge 1 commit into
issue-345-8from
issue-345-9

Conversation

@SJrX

@SJrX SJrX commented Jun 21, 2026

Copy link
Copy Markdown
Owner

What

Implements "option 1" from the discussion: when you accept a grammar completion, if the only thing the grammar can accept next is a forced separator, it's auto-inserted and completion re-opens. So accepting home gives you home= with the policy-flag popup immediately, instead of stopping on a lone = you'd have to type yourself.

Stacked on #477 (issue-345-8).

Why

After a complete partition designator like home, the grammar allows exactly one next token: =. A completion popup whose only entry is a single punctuation separator is low-value — and the platform won't even autopopup it (you'd need Ctrl+Space). What the user actually wants next is the policy flag. Chaining through the separator gets them there in one motion (mirrors how method completion inserts ()).

How

chainingInsertHandler runs after a choice is accepted:

  1. Resolve the value start via PSI, read the value text up to the caret.
  2. While nextTokenChoices(pre) is exactly one punctuation separator (no letters/digits — so =, +, :, never a content token like verity), insert it and advance. Bounded loop (≤ 8).
  3. scheduleAutoPopup so the following real choices (flags) appear.

It only ever auto-inserts forced separators, never a content token the user should pick. Applies to all grammar-completion items, so it generalizes to other grammars (: in ipv4:tcp:…, etc.).

Test

testAcceptingPartitionChainsTheEqualsSeparator: RootImagePolicy=hom⎉ → accept the single match home → document becomes RootImagePolicy=home=⎉.

Full suite green.

Refs #467 #343

🤖 Generated with Claude Code

Accepting a completion now auto-inserts a following forced separator and re-opens
completion, so e.g. accepting "home" yields "home=" and immediately offers the policy
flags — instead of stopping on a single mandatory "=" that the user must type by hand
(and which the platform won't even autopopup since it's a lone punctuation result).

InsertHandler walks the grammar forward from the accepted token: while the only thing
that can come next is a single punctuation separator (",", "=", "+", ":" depending on
grammar), it inserts it; it never auto-inserts a content token the user should choose.
Then it schedules the autopopup. Bounded loop; resolves the value start via PSI.

Test: accepting a partition designator chains the "=" (RootImagePolicy=hom -> home=).

Refs #467 #343

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

1 134 tests   1 134 ✅  51s ⏱️
  301 suites      0 💤
  301 files        0 ❌

Results for commit cbbfef2.

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