Skip to content

Commit 69a69dd

Browse files
committed
feat: add show_on_keyword and show_on_trigger_character trigger options
Closes #402
1 parent 9bf108b commit 69a69dd

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,19 @@ MiniDeps.add({
279279
trigger = {
280280
-- When false, will not show the completion window automatically when in a snippet
281281
show_in_snippet = true,
282+
-- When true, will show the completion window after typing a character that matches the `keyword.regex`
283+
show_on_keyword = true,
284+
-- When true, will show the completion window after typing a trigger character
285+
show_on_trigger_character = true,
282286
-- LSPs can indicate when to show the completion window via trigger characters
283287
-- however, some LSPs (i.e. tsserver) return characters that would essentially
284288
-- always show the window. We block these by default.
285289
show_on_blocked_trigger_characters = { ' ', '\n', '\t' },
286-
-- When true, will show the completion window when the cursor comes after a trigger character
287-
-- after accepting an item
290+
-- When both this and show_on_trigger_character are true, will show the completion window
291+
-- when the cursor comes after a trigger character after accepting an item
288292
show_on_accept_on_trigger_character = true,
289-
-- When true, will show the completion window when the cursor comes after a trigger character
290-
-- when entering insert mode
293+
-- When both this and show_on_trigger_character are true, will show the completion window
294+
-- when the cursor comes after a trigger character when entering insert mode
291295
show_on_insert_on_trigger_character = true,
292296
-- List of trigger characters (on top of `show_on_blocked_trigger_characters`) that won't trigger
293297
-- the completion window when the cursor comes after a trigger character when

lua/blink/cmp/completion/trigger.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ function trigger.activate()
5757
if trigger.context ~= nil then trigger.show({ send_upstream = false }) end
5858

5959
-- character forces a trigger according to the sources, create a fresh context
60-
elseif trigger.is_trigger_character(char) then
60+
elseif trigger.is_trigger_character(char) and config.show_on_trigger_character then
6161
trigger.context = nil
6262
trigger.show({ trigger_character = char })
6363

6464
-- character is part of the current context OR in an existing context
65-
elseif char:match(keyword_config.regex) ~= nil then
65+
elseif char:match(keyword_config.regex) ~= nil and config.show_on_keyword then
6666
trigger.show()
6767

6868
-- nothing matches so hide
@@ -84,7 +84,8 @@ function trigger.activate()
8484
local is_on_trigger_for_show_on_insert = trigger.is_trigger_character(char_under_cursor, true)
8585
local is_on_context_char = char_under_cursor:match(keyword_config.regex) ~= nil
8686

87-
local insert_enter_on_trigger_character = config.show_on_insert_on_trigger_character
87+
local insert_enter_on_trigger_character = config.show_on_trigger_character
88+
and config.show_on_insert_on_trigger_character
8889
and is_on_trigger_for_show_on_insert
8990
and event == 'InsertEnter'
9091

@@ -132,7 +133,12 @@ function trigger.suppress_events_for_callback(cb)
132133
end
133134

134135
function trigger.show_if_on_trigger_character(opts)
135-
if opts and opts.is_accept and not config.show_on_accept_on_trigger_character then return end
136+
if
137+
(opts and opts.is_accept)
138+
and (not config.show_on_trigger_character or not config.show_on_accept_on_trigger_character)
139+
then
140+
return
141+
end
136142

137143
local cursor_col = vim.api.nvim_win_get_cursor(0)[2]
138144
local char_under_cursor = vim.api.nvim_get_current_line():sub(cursor_col, cursor_col)

lua/blink/cmp/config/completion/trigger.lua

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
--- @class (exact) blink.cmp.CompletionTriggerConfig
22
--- @field show_in_snippet boolean When false, will not show the completion window when in a snippet
3+
--- @field show_on_keyword boolean When true, will show the completion window after typing a character that matches the `keyword.regex`
4+
--- @field show_on_trigger_character boolean When true, will show the completion window after typing a trigger character
35
--- @field show_on_blocked_trigger_characters 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.
4-
--- @field show_on_accept_on_trigger_character boolean When true, will show the completion window when the cursor comes after a trigger character after accepting an item
5-
--- @field show_on_insert_on_trigger_character boolean When true, will show the completion window when the cursor comes after a trigger character when entering insert mode
6+
--- @field show_on_accept_on_trigger_character boolean When both this and show_on_trigger_character are true, will show the completion window when the cursor comes after a trigger character after accepting an item
7+
--- @field show_on_insert_on_trigger_character boolean When both this and show_on_trigger_character are true, will show the completion window when the cursor comes after a trigger character when entering insert mode
68
--- @field show_on_x_blocked_trigger_characters string[] List of trigger characters (on top of `show_on_blocked_trigger_characters`) that won't trigger the completion window when the cursor comes after a trigger character when entering insert mode/accepting an item
79

810
local validate = require('blink.cmp.config.utils').validate
911
local trigger = {
1012
--- @type blink.cmp.CompletionTriggerConfig
1113
default = {
1214
show_in_snippet = true,
15+
show_on_keyword = true,
16+
show_on_trigger_character = true,
1317
show_on_blocked_trigger_characters = { ' ', '\n', '\t' },
1418
show_on_accept_on_trigger_character = true,
1519
show_on_insert_on_trigger_character = true,
@@ -20,6 +24,8 @@ local trigger = {
2024
function trigger.validate(config)
2125
validate('completion.trigger', {
2226
show_in_snippet = { config.show_in_snippet, 'boolean' },
27+
show_on_keyword = { config.show_on_keyword, 'boolean' },
28+
show_on_trigger_character = { config.show_on_trigger_character, 'boolean' },
2329
show_on_blocked_trigger_characters = { config.show_on_blocked_trigger_characters, 'table' },
2430
show_on_accept_on_trigger_character = { config.show_on_accept_on_trigger_character, 'boolean' },
2531
show_on_insert_on_trigger_character = { config.show_on_insert_on_trigger_character, 'boolean' },

0 commit comments

Comments
 (0)