Skip to content

feat(completion): add interactive snippet placeholders - #262

Merged
fcoury-oai merged 1 commit into
mainfrom
codex/autocomplete-snippet-placeholders
Aug 17, 2026
Merged

fcoury-oai merged 1 commit into
mainfrom
codex/autocomplete-snippet-placeholders

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Why

Language servers can return editable argument placeholders, but completion acceptance currently flattens them into ordinary text. Completing a call such as self.spawn_asteroid(d, pos, size) therefore leaves the user to replace each generated argument by hand.

What changed

  • Preserve numbered placeholder ranges and the final $0 cursor position when expanding completion snippets.
  • Highlight the active placeholder in Insert mode; typing or pasting replaces its default, and Tab / Shift-Tab move between arguments.
  • Track placeholder positions through transactional edits, including Unicode text and additional LSP edits. Keep completion-menu acceptance, commit characters, and undo behavior intact, and end the session when leaving Insert mode or moving outside the snippet.
  • Add parser and editor-level regression coverage, including the spawn_asteroid example.

This covers numbered placeholder navigation. Full snippet-variable/transform expansion and linked-placeholder mirroring are not included.

How to Test

  1. Open a Rust file with rust-analyzer running and complete a method that takes several arguments, such as spawn_asteroid. Accept the completion with Tab. The first generated argument should be highlighted while the editor stays in Insert mode.
  2. Type a longer replacement, press Tab, paste a replacement for the next argument, then use Shift-Tab to return. Each replacement should affect only the selected argument, and later placeholders should remain correctly positioned. The final Tab should leave the cursor at the snippet's final stop.
  3. Request ordinary completion while editing an argument. With the completion menu open, Tab should accept its selected item; the next Tab should move to the following snippet argument. Press Esc or undo the completion and confirm subsequent typing no longer replaces a stale placeholder.
  4. Run cargo test --test completion -- --test-threads=1 for the argument-navigation, rendering, Unicode/import-edit, commit-character, cancellation, and undo regressions.

Validation

  • Completion integration suite: 44 passed.
  • Snippet parser tests: 3 passed.
  • Full library suite: 1,835 passed, 1 ignored.
  • cargo clippy --all-targets --all-features -- -D warnings: passed.
  • Formatting and diff whitespace checks: passed.

@fcoury-oai
fcoury-oai merged commit cb95bdb into main Aug 17, 2026
19 of 20 checks passed
@fcoury-oai
fcoury-oai deleted the codex/autocomplete-snippet-placeholders branch August 17, 2026 17:49
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