Repository navigation
editor: Add on-demand completion commands - #3411
Merged
Merged
Conversation
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
enabled auto-merge (squash)
October 8, 2026 08:33
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ShowCompletionsaction andshow_completionsAPI. 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 toInput && mode == editor; existingInputbindings remain valid.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
INVOKEDwith 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 usinggpui_kit::component::input.Breaking Changes
None for existing consumers. The public API is additive and existing
Inputbindings 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 --checkandgit 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.