Add dedicated actions for LSP completions insertion mode (#28121)

Adds actions so you can have customized keybindings for `insert` and
`replace` modes.

And add `shift-enter` as a default for `replace`, this will override the
default setting
`completions.lsp_insert_mode` which is set to `replace_suffix`, which
tries to "smartly"
decide whether to replace or insert based on the surrounding text.

For those who come from VSCode, if you want to mimic their behavior, you
only have to
set `completions.lsp_insert_mode` to `insert`.

If you want `tab` and `enter` to do different things, you need to remap
them, here is
an example:

```jsonc
[
  // ...
  {
    "context": "Editor && showing_completions",
    "bindings": {
      "enter": "editor::ConfirmCompletionInsert",
      "tab": "editor::ConfirmCompletionReplace"
    }
  },
]
```

Closes #24577

- [x] Make LSP completion insertion mode decision in guest's machine
(host is currently deciding it and not allowing guests to have their own
setting for it)
- [x] Add shift-enter as a hotkey for `replace` by default.
- [x] Test actions.
- [x] Respect the setting being specified per language, instead of using
the "defaults".
- [x] Move `insert_range` of `Completion` to the Lsp variant of
`.source`.
- [x] Fix broken default, forgotten after
https://github.com/zed-industries/zed/pull/27453#pullrequestreview-2736906628,
should be `replace_suffix` and not `insert`.

Release Notes:

- LSP completions: added actions `ConfirmCompletionInsert` and
`ConfirmCompletionReplace` that control how completions are inserted,
these override `completions.lsp_insert_mode`, by default, `shift-enter`
triggers `ConfirmCompletionReplace` which replaces the whole word.
This commit is contained in:
João Marcos 2025-04-08 19:03:03 -03:00 committed by GitHub
parent 0459b1d303
commit b15ee1b1cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 400 additions and 207 deletions

View file

@ -198,8 +198,8 @@ message ApplyCompletionAdditionalEditsResponse {
}
message Completion {
Anchor old_start = 1;
Anchor old_end = 2;
Anchor old_replace_start = 1;
Anchor old_replace_end = 2;
string new_text = 3;
uint64 server_id = 4;
bytes lsp_completion = 5;
@ -208,6 +208,8 @@ message Completion {
optional bytes lsp_defaults = 8;
optional Anchor buffer_word_start = 9;
optional Anchor buffer_word_end = 10;
Anchor old_insert_start = 11;
Anchor old_insert_end = 12;
enum Source {
Lsp = 0;
@ -428,10 +430,12 @@ message ResolveCompletionDocumentation {
message ResolveCompletionDocumentationResponse {
string documentation = 1;
bool documentation_is_markdown = 2;
Anchor old_start = 3;
Anchor old_end = 4;
Anchor old_replace_start = 3;
Anchor old_replace_end = 4;
string new_text = 5;
bytes lsp_completion = 6;
Anchor old_insert_start = 7;
Anchor old_insert_end = 8;
}
message ResolveInlayHint {