36
36
local keyword_config = require (' blink.cmp.config' ).completion .keyword
37
37
local config = require (' blink.cmp.config' ).completion .trigger
38
38
39
+ local keyword_regex = vim .regex (keyword_config .regex )
40
+
39
41
--- @type blink.cmp.CompletionTrigger
40
42
--- @diagnostic disable-next-line : missing-fields
41
43
local trigger = {
@@ -62,7 +64,7 @@ function trigger.activate()
62
64
trigger .show ({ trigger_character = char })
63
65
64
66
-- character is part of a keyword
65
- elseif char : match ( keyword_config . regex ) ~= nil and (config .show_on_keyword or trigger .context ~= nil ) then
67
+ elseif keyword_regex : match_str ( char ) ~= nil and (config .show_on_keyword or trigger .context ~= nil ) then
66
68
trigger .show ()
67
69
68
70
-- nothing matches so hide
@@ -82,7 +84,7 @@ function trigger.activate()
82
84
local char_under_cursor = vim .api .nvim_get_current_line ():sub (cursor_col , cursor_col )
83
85
local is_on_trigger_for_show = trigger .is_trigger_character (char_under_cursor )
84
86
local is_on_trigger_for_show_on_insert = trigger .is_trigger_character (char_under_cursor , true )
85
- local is_on_keyword_char = char_under_cursor : match ( keyword_config . regex ) ~= nil
87
+ local is_on_keyword_char = keyword_regex : match_str ( char_under_cursor ) ~= nil
86
88
87
89
local insert_enter_on_trigger_character = config .show_on_trigger_character
88
90
and config .show_on_insert_on_trigger_character
@@ -197,17 +199,16 @@ function trigger.within_query_bounds(cursor)
197
199
end
198
200
199
201
--- Moves forward and backwards around the cursor looking for word boundaries
200
- --- @param regex string
201
202
--- @return blink.cmp.ContextBounds
202
- function trigger .get_context_bounds (regex )
203
+ function trigger .get_context_bounds ()
203
204
local cursor_line = vim .api .nvim_win_get_cursor (0 )[1 ]
204
205
local cursor_col = vim .api .nvim_win_get_cursor (0 )[2 ]
205
206
206
207
local line = vim .api .nvim_buf_get_lines (0 , cursor_line - 1 , cursor_line , false )[1 ]
207
208
local start_col = cursor_col
208
209
while start_col >= 1 do
209
210
local char = line :sub (start_col , start_col )
210
- if char : match ( regex ) == nil then
211
+ if keyword_regex : match_str ( char ) == nil then
211
212
start_col = start_col + 1
212
213
break
213
214
end
@@ -218,7 +219,7 @@ function trigger.get_context_bounds(regex)
218
219
local end_col = cursor_col
219
220
while end_col < # line do
220
221
local char = line :sub (end_col + 1 , end_col + 1 )
221
- if char : match ( regex ) == nil then break end
222
+ if keyword_regex : match_str ( char ) == nil then break end
222
223
end_col = end_col + 1
223
224
end
224
225
@@ -228,7 +229,7 @@ function trigger.get_context_bounds(regex)
228
229
local length = end_col - start_col + 1
229
230
-- Since sub(1, 1) returns a single char string, we need to check if that single char matches
230
231
-- and otherwise mark the length as 0
231
- if start_col == end_col and line :sub (start_col , end_col ): match ( regex ) == nil then length = 0 end
232
+ if start_col == end_col and keyword_regex : match_str ( line :sub (start_col , end_col )) == nil then length = 0 end
232
233
233
234
return { line_number = cursor_line , start_col = start_col , end_col = end_col , length = length }
234
235
end
0 commit comments