@@ -4,6 +4,7 @@ local match = require'completion.matching'
44local source = require ' completion.source'
55local signature = require ' completion.signature_help'
66local hover = require ' completion.hover'
7+ local opt = require ' completion.option'
78local M = {}
89
910---- --------------------------------------------------------------------
@@ -12,7 +13,6 @@ local M = {}
1213
1314M .completionConfirm = false
1415
15-
1616-- Manager variable to keep all state accross completion
1717local manager = {
1818 -- Handle insertCharPre event, turn off imediately when preforming completion
@@ -75,7 +75,7 @@ function M.confirmCompletion()
7575 end
7676 end
7777
78- if vim . g . completion_enable_auto_paren == 1 then
78+ if opt . get_option ( ' enable_auto_paren ' ) == 1 then
7979 M .autoAddParens (complete_item )
8080 end
8181 if complete_item .kind == ' UltiSnips' then
@@ -97,7 +97,7 @@ function M.on_InsertCharPre()
9797 manager .insertChar = true
9898 manager .textHover = true
9999 manager .selected = - 1
100- if vim . g . completion_auto_change_source == 1 then
100+ if opt . get_option ( ' auto_change_source ' ) == 1 then
101101 manager .autoChange = true
102102 end
103103end
@@ -117,28 +117,28 @@ function M.on_InsertEnter()
117117 manager .insertLeave = false
118118 manager .insertChar = false
119119 manager .changeSource = false
120- if vim . g . completion_auto_change_source == 1 then
120+ if opt . get_option ( ' auto_change_source ' ) == 1 then
121121 manager .autoChange = true
122122 end
123123
124124 -- reset source
125125 source .chain_complete_index = 1
126126 source .stop_complete = false
127127 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 ' )
129129
130130 timer :start (100 , timer_cycle , vim .schedule_wrap (function ()
131131 local l_changedTick = api .nvim_buf_get_changedtick (0 )
132132 -- complete if changes are made
133133 if l_changedTick ~= manager .changedTick then
134134 manager .changedTick = l_changedTick
135- if vim . g . completion_enable_auto_popup == 1 then
135+ if opt . get_option ( ' enable_auto_popup ' ) == 1 then
136136 source .autoCompletion (manager )
137137 end
138- if vim . g . completion_enable_auto_hover == 1 then
138+ if opt . get_option ( ' enable_auto_hover ' ) == 1 then
139139 hover .autoOpenHoverInPopup (manager )
140140 end
141- if vim . g . completion_enable_auto_signature == 1 then
141+ if opt . get_option ( ' enable_auto_signature ' ) == 1 then
142142 signature .autoOpenSignatureHelp ()
143143 end
144144 end
@@ -207,16 +207,24 @@ M.prevSource = function()
207207 source .prevCompletion ()
208208end
209209
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
211219 api .nvim_command (" augroup CompletionCommand" )
212220 api .nvim_command (" autocmd! * <buffer>" )
213221 api .nvim_command (" autocmd InsertEnter <buffer> lua require'completion'.on_InsertEnter()" )
214222 api .nvim_command (" autocmd InsertLeave <buffer> lua require'completion'.on_InsertLeave()" )
215223 api .nvim_command (" autocmd InsertCharPre <buffer> lua require'completion'.on_InsertCharPre()" )
216224 api .nvim_command (" autocmd CompleteDone <buffer> lua require'completion'.confirmCompletion()" )
217225 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 ' ) ,
220228 ' pumvisible() ? complete_info()["selected"] != "-1" ? "\\ <Plug>(completion_confirm_completion)" :' ..
221229 ' "\\ <c-e>\\ <CR>" : "\\ <CR>"' ,
222230 {silent = false , noremap = false , expr = true })
@@ -228,17 +236,6 @@ M.on_attach = function(opt)
228236 api .nvim_command (" augroup end" )
229237 end
230238 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
242239end
243240
244241return M
0 commit comments