Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion doc/configuration/completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ The completion list in **cmdline mode** does **not** inherit the following setti
:::tabs
== Preselect, Auto Insert (default)
```lua
completion.list.selection = { preselect = true, auto_insert = true }
completion.list.selection = { preselect = true, auto_insert = true, auto_insert_blacklist = {} }
```
Selects the first item automatically, and inserts a preview of the item on selection. The `cancel` keymap (default `<C-e>`) will close the menu and undo the preview.

Expand Down Expand Up @@ -234,6 +234,16 @@ completion.list.selection = {
}
```

To blacklist certain big or misbehaving completion sources (like Copilot) from being automatically inserted regardless of `auto_insert` being true, use `auto_insert_blacklist`.
The blacklist accepts `client_name` and `source_name` values allowing you to blacklist entire sources or specific lsp clients:

```lua
completion.list.selection = {
preselect = false,
auto_insert = true,
auto_insert_blacklist = { 'copilot' },
}
```

## Accept <!-- panvimdoc-ignore-start --><Badge type="info"><a href="./reference#completion-accept">Go to default configuration</a></Badge><!-- panvimdoc-ignore-end -->

Expand Down
11 changes: 11 additions & 0 deletions lua/blink/cmp/completion/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ function list.apply_preview(item)
-- undo the previous preview if it exists
list.undo_preview()

-- Skip applying preview when the suggestion is blacklisted from being previewed
local blacklist = list.config.selection.auto_insert_blacklist
if blacklist ~= nil and #blacklist > 0 then
for _, v in ipairs(blacklist) do
if v == item.client_name or v == item.source_name then
list.preview_undo = nil
return
end
end
end

-- apply the new preview
local undo_text_edit, undo_cursor = require('blink.cmp.completion.accept.preview')(item)
list.preview_undo = {
Expand Down
3 changes: 3 additions & 0 deletions lua/blink/cmp/config/completion/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
--- @class (exact) blink.cmp.CompletionListSelectionConfig
--- @field preselect boolean | fun(ctx: blink.cmp.Context): boolean When `true`, will automatically select the first item in the completion list
--- @field auto_insert boolean | fun(ctx: blink.cmp.Context): boolean When `true`, inserts the completion item automatically when selecting it. You may want to bind a key to the `cancel` command (default <C-e>) when using this option, which will both undo the selection and hide the completion menu
--- @field auto_insert_blacklist? string[] List of mixed client_names and source_names that won't auto-insert when selected, even if `auto_insert` is `true`

--- @class (exact) blink.cmp.CompletionListCycleConfig
--- @field from_bottom boolean When `true`, calling `select_next` at the *bottom* of the completion list will select the *first* completion item.
Expand All @@ -19,6 +20,7 @@ local list = {
selection = {
preselect = true,
auto_insert = true,
auto_insert_blacklist = {},
},
cycle = {
from_bottom = true,
Expand All @@ -43,6 +45,7 @@ function list.validate(config)
validate('completion.list.selection', {
preselect = { config.selection.preselect, { 'boolean', 'function' } },
auto_insert = { config.selection.auto_insert, { 'boolean', 'function' } },
auto_insert_blacklist = { config.selection.auto_insert_blacklist, 'table' },
}, config.selection)

validate('completion.list.cycle', {
Expand Down
1 change: 1 addition & 0 deletions lua/blink/cmp/config/modes/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
--- @class blink.cmp.ModeCompletionListSelectionConfig
--- @field preselect? boolean | fun(ctx: blink.cmp.Context, items: blink.cmp.CompletionItem[]): boolean Whether to preselect the first item when the list is shown
--- @field auto_insert? boolean | fun(ctx: blink.cmp.Context, items: blink.cmp.CompletionItem[]): boolean When `true`, inserts the completion item automatically when selecting it
--- @field auto_insert_blacklist? string[] List of mixed client_names and source_names that won't auto-insert when selected, even if `auto_insert` is `true`

--- @class blink.cmp.ModeCompletionTriggerConfig
--- @field show_on_blocked_trigger_characters? string[] | (fun(): string[]) LSPs can indicate when to show the completion window via trigger characters. However, some LSPs (i.e. tsserver) return characters that would essentially always show the window. We block these by default.
Expand Down
Loading