Skip to content

editor: Add on-demand completion commands - #3411

Merged
huacnlee merged 2 commits into
longbridge:mainfrom
sola-ryu:mv/editor-show-completions
Oct 8, 2026
Merged

huacnlee merged 2 commits into
longbridge:mainfrom
sola-ryu:mv/editor-show-completions

Conversation

@sola-ryu

@sola-ryu sola-ryu commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Editor completions previously opened only as a side effect of typing. Applications could not request suggestions from a command, menu, or their own shortcut without editing text.

Add the Editor-only ShowCompletions action and show_completions API. There is no default shortcut: hosts choose bindings that fit their platform and avoid input-method shortcuts such as Ctrl+Space. Hosts can scope bindings to Input && mode == editor; existing Input bindings remain valid.

window.dispatch_action(Box::new(ShowCompletions), cx);
editor.update(cx, |state, cx| state.show_completions(window, cx));

The action addresses the focused Editor; the method focuses the specified Editor. Suggestions refine against the identifier prefix before the caret, and an empty prefix still requests suggestions. Prefix scanning walks backward through the rope instead of copying the whole preceding document. Manual requests use LSP INVOKED with no trigger character.

Disabled/readonly editors, missing providers, and IME preedit issue no request. An already-open completion menu keeps its selected item. A new request cancels the previous overlay request and inline suggestion, closes code actions, and uses the existing completion lifecycle. Responses are checked against the current document revision, caret, focus, editability, and composition state before being applied.

English and Chinese Editor documentation describe the command, API, host-owned shortcuts, and lifecycle rules.

Public API

gpui-base

  • input::ShowCompletions — Editor action requesting suggestions without typing; no default keybinding.
  • InputBaseState<EditorMode>::show_completions(&mut self, window: &mut Window, cx: &mut Context<Self>) — Request manual completions and focus the Editor, respecting editability, IME, and an existing completion menu.

gpui-component

  • input::ShowCompletions — Re-export the Base action for applications using gpui_kit::component::input.

Breaking Changes

None for existing consumers. The public API is additive and existing Input bindings remain supported.

Validation

  • cargo test -p gpui-kit --features 'test-support component' --test input — 179 passed. Covers explicit and empty-prefix requests, host-configured Editor-only shortcuts, no Ctrl+Space default, menu selection preservation, IME preedit/commit, readonly/disabled/missing-provider guards, request replacement, Escape/caret cancellation, inline suggestion/debounce cancellation, code-action replacement, and API focus from an application command.
  • cargo clippy -p gpui-base -p gpui-kit --features 'gpui-kit/test-support gpui-kit/component' --all-targets -- --deny warnings — passed.
  • cargo fmt --all --check and git diff --check — passed.

The implementation, tests, and documentation revision were generated with AI assistance. IME coverage uses GPUI's simulated input-handler protocol; it does not drive native candidate windows or verify OS shortcut interception.

sola-ryu and others added 2 commits October 7, 2026 21:52
The completion menu only opens from a keystroke the provider accepts as a
trigger. Once it has been dismissed, or with the caret moved into an
existing word, there was no way to ask for suggestions again short of
typing another character and deleting it.

`ShowCompletions`, bound to Ctrl+Space in the editor, and
`EditorState::show_completions` ask the provider at the caret with
`CompletionTriggerKind::INVOKED`. The query is the word the caret ends, so
the menu refines from there exactly as it does after typing that word; with
no word before the caret the query is empty. A read-only or disabled editor
asks nothing. Both paths share one request routine with typed triggers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHBYT8JhqczL6GhYZoKgww
@huacnlee huacnlee changed the title editor: Add ShowCompletions to open the completion menu without typing editor: Add on-demand completion commands Oct 8, 2026
@huacnlee
huacnlee enabled auto-merge (squash) October 8, 2026 08:33
@huacnlee
huacnlee merged commit 32529dc into longbridge:main Oct 8, 2026
15 of 16 checks passed
linruohan pushed a commit to linruohan/gpui-component that referenced this pull request Oct 9, 2026
## Description

Editor completions previously opened only as a side effect of typing.
Applications could not request suggestions from a command, menu, or
their own shortcut without editing text.

Add the Editor-only `ShowCompletions` action and `show_completions` API.
There is no default shortcut: hosts choose bindings that fit their
platform and avoid input-method shortcuts such as Ctrl+Space. Hosts can
scope bindings to `Input && mode == editor`; existing `Input` bindings
remain valid.

```rust
window.dispatch_action(Box::new(ShowCompletions), cx);
editor.update(cx, |state, cx| state.show_completions(window, cx));
```

The action addresses the focused Editor; the method focuses the
specified Editor. Suggestions refine against the identifier prefix
before the caret, and an empty prefix still requests suggestions. Prefix
scanning walks backward through the rope instead of copying the whole
preceding document. Manual requests use LSP `INVOKED` with no trigger
character.

Disabled/readonly editors, missing providers, and IME preedit issue no
request. An already-open completion menu keeps its selected item. A new
request cancels the previous overlay request and inline suggestion,
closes code actions, and uses the existing completion lifecycle.
Responses are checked against the current document revision, caret,
focus, editability, and composition state before being applied.

English and Chinese Editor documentation describe the command, API,
host-owned shortcuts, and lifecycle rules.

## Public API

### gpui-base

- `input::ShowCompletions` — Editor action requesting suggestions
without typing; no default keybinding.
- `InputBaseState<EditorMode>::show_completions(&mut self, window: &mut
Window, cx: &mut Context<Self>)` — Request manual completions and focus
the Editor, respecting editability, IME, and an existing completion
menu.

### gpui-component

- `input::ShowCompletions` — Re-export the Base action for applications
using `gpui_kit::component::input`.

## Breaking Changes

None for existing consumers. The public API is additive and existing
`Input` bindings remain supported.

## Validation

- `cargo test -p gpui-kit --features 'test-support component' --test
input` — 179 passed. Covers explicit and empty-prefix requests,
host-configured Editor-only shortcuts, no Ctrl+Space default, menu
selection preservation, IME preedit/commit,
readonly/disabled/missing-provider guards, request replacement,
Escape/caret cancellation, inline suggestion/debounce cancellation,
code-action replacement, and API focus from an application command.
- `cargo clippy -p gpui-base -p gpui-kit --features
'gpui-kit/test-support gpui-kit/component' --all-targets -- --deny
warnings` — passed.
- `cargo fmt --all --check` and `git diff --check` — passed.

The implementation, tests, and documentation revision were generated
with AI assistance. IME coverage uses GPUI's simulated input-handler
protocol; it does not drive native candidate windows or verify OS
shortcut interception.

---------

Co-authored-by: Sola <sola-ryu@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jason Lee <huacnlee@gmail.com>
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.

2 participants