@@ -4,6 +4,7 @@ local match = require'completion.matching'
4
4
local source = require ' completion.source'
5
5
local signature = require ' completion.signature_help'
6
6
local hover = require ' completion.hover'
7
+ local opt = require ' completion.option'
7
8
local M = {}
8
9
9
10
---- --------------------------------------------------------------------
@@ -12,7 +13,6 @@ local M = {}
12
13
13
14
M .completionConfirm = false
14
15
15
-
16
16
-- Manager variable to keep all state accross completion
17
17
local manager = {
18
18
-- Handle insertCharPre event, turn off imediately when preforming completion
@@ -75,7 +75,7 @@ function M.confirmCompletion()
75
75
end
76
76
end
77
77
78
- if vim . g . completion_enable_auto_paren == 1 then
78
+ if opt . get_option ( ' enable_auto_paren ' ) == 1 then
79
79
M .autoAddParens (complete_item )
80
80
end
81
81
if complete_item .kind == ' UltiSnips' then
@@ -97,7 +97,7 @@ function M.on_InsertCharPre()
97
97
manager .insertChar = true
98
98
manager .textHover = true
99
99
manager .selected = - 1
100
- if vim . g . completion_auto_change_source == 1 then
100
+ if opt . get_option ( ' auto_change_source ' ) == 1 then
101
101
manager .autoChange = true
102
102
end
103
103
end
@@ -117,28 +117,28 @@ function M.on_InsertEnter()
117
117
manager .insertLeave = false
118
118
manager .insertChar = false
119
119
manager .changeSource = false
120
- if vim . g . completion_auto_change_source == 1 then
120
+ if opt . get_option ( ' auto_change_source ' ) == 1 then
121
121
manager .autoChange = true
122
122
end
123
123
124
124
-- reset source
125
125
source .chain_complete_index = 1
126
126
source .stop_complete = false
127
127
local l_complete_index = source .chain_complete_index
128
- local timer_cycle = vim . g . completion_timer_cycle
128
+ local timer_cycle = opt . get_option ( ' timer_cycle ' )
129
129
130
130
timer :start (100 , timer_cycle , vim .schedule_wrap (function ()
131
131
local l_changedTick = api .nvim_buf_get_changedtick (0 )
132
132
-- complete if changes are made
133
133
if l_changedTick ~= manager .changedTick then
134
134
manager .changedTick = l_changedTick
135
- if vim . g . completion_enable_auto_popup == 1 then
135
+ if opt . get_option ( ' enable_auto_popup ' ) == 1 then
136
136
source .autoCompletion (manager )
137
137
end
138
- if vim . g . completion_enable_auto_hover == 1 then
138
+ if opt . get_option ( ' enable_auto_hover ' ) == 1 then
139
139
hover .autoOpenHoverInPopup (manager )
140
140
end
141
- if vim . g . completion_enable_auto_signature == 1 then
141
+ if opt . get_option ( ' enable_auto_signature ' ) == 1 then
142
142
signature .autoOpenSignatureHelp ()
143
143
end
144
144
end
@@ -207,16 +207,24 @@ M.prevSource = function()
207
207
source .prevCompletion ()
208
208
end
209
209
210
- M .on_attach = function (opt )
210
+ M .on_attach = function (option )
211
+ -- setup completion_option tables
212
+ if option ~= nil then
213
+ opt .set_option_table (option )
214
+ else
215
+ opt .set_option_table (option )
216
+ end
217
+ -- setup autocommand
218
+ -- TODO: Modified this if lua callbacks for autocmd is merged
211
219
api .nvim_command (" augroup CompletionCommand" )
212
220
api .nvim_command (" autocmd! * <buffer>" )
213
221
api .nvim_command (" autocmd InsertEnter <buffer> lua require'completion'.on_InsertEnter()" )
214
222
api .nvim_command (" autocmd InsertLeave <buffer> lua require'completion'.on_InsertLeave()" )
215
223
api .nvim_command (" autocmd InsertCharPre <buffer> lua require'completion'.on_InsertCharPre()" )
216
224
api .nvim_command (" autocmd CompleteDone <buffer> lua require'completion'.confirmCompletion()" )
217
225
api .nvim_command (" augroup end" )
218
- if string.len (vim . g . completion_confirm_key ) ~= 0 then
219
- api .nvim_buf_set_keymap (0 , ' i' , vim . g . completion_confirm_key ,
226
+ if string.len (opt . get_option ( ' confirm_key ' ) ) ~= 0 then
227
+ api .nvim_buf_set_keymap (0 , ' i' , opt . get_option ( ' confirm_key ' ) ,
220
228
' pumvisible() ? complete_info()["selected"] != "-1" ? "\\ <Plug>(completion_confirm_completion)" :' ..
221
229
' "\\ <c-e>\\ <CR>" : "\\ <CR>"' ,
222
230
{silent = false , noremap = false , expr = true })
@@ -228,17 +236,6 @@ M.on_attach = function(opt)
228
236
api .nvim_command (" augroup end" )
229
237
end
230
238
api .nvim_buf_set_var (0 , ' completion_enable' , 1 )
231
- if opt == nil then return end
232
- local sorter = opt .sorter
233
- local matcher = opt .matcher
234
- if sorter ~= nil then
235
- vim .validate {sorter = {sorter , ' string' }}
236
- vim .b .completion_sorting = sorter
237
- end
238
- if matcher ~= nil then
239
- vim .validate {matcher = {matcher , ' table' }}
240
- vim .b .completion_matching_strategy_list = matcher
241
- end
242
239
end
243
240
244
241
return M
0 commit comments