diff --git a/README.md b/README.md index 14a4155..712d9f2 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,14 @@ let g:completion_enable_auto_hover = 0 let g:completion_enable_auto_signature = 0 ``` +### Enable/Disable auto close brace + +- By default variable completion with brace will not auto close. Enable it by + +```vim +let g:completion_enable_auto_close_brace = 1 +``` + ### Sorting completion items - You can decide how your items being sorted in the popup menu. The default value diff --git a/lua/completion.lua b/lua/completion.lua index 9184e02..b360860 100644 --- a/lua/completion.lua +++ b/lua/completion.lua @@ -84,6 +84,12 @@ local function autoAddParens(completed_item) end end +local function autoAddBrace(completed_item) + if completed_item.kind == 'Variable' and string.match(completed_item.abbr, '.*}$') and string.match(completed_item.word, '.*}$') == nil then + api.nvim_input("}") + end +end + -- Workaround to avoid expand snippets when not confirm -- confirmCompletion is now triggered by CompleteDone autocmd to solve issue with noselect -- Will cause snippets to expand with not pressing confirm key @@ -128,10 +134,15 @@ local function hasConfirmedCompletion() if opt.get_option('enable_snippet') == "snippets.nvim" then require 'snippets'.expand_at_cursor(completed_item.user_data.actual_item, completed_item.word) end + else + if opt.get_option('enable_auto_close_brace') == 1 then + autoAddBrace(completed_item) + end + if opt.get_option('enable_auto_paren') == 1 then + autoAddParens(completed_item) + end end - if opt.get_option('enable_auto_paren') == 1 then - autoAddParens(completed_item) - end + if completed_item.user_data.snippet_source == 'UltiSnips' then api.nvim_call_function('UltiSnips#ExpandSnippet', {}) elseif completed_item.user_data.snippet_source == 'Neosnippet' then