From 32be0c61c18425056e52b92df566242559d754d6 Mon Sep 17 00:00:00 2001 From: Rafael Quintela Date: Tue, 17 Aug 2021 11:21:11 -0300 Subject: [PATCH 1/3] feat(auto close brace) --- README.md | 8 ++++++++ lua/completion.lua | 11 +++++++++++ 2 files changed, 19 insertions(+) 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..2dca745 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 @@ -132,6 +138,11 @@ local function hasConfirmedCompletion() if opt.get_option('enable_auto_paren') == 1 then autoAddParens(completed_item) end + + if opt.get_option('enable_auto_close_brace') == 1 then + autoAddBrace(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 From 0869ea35910d09b4418e8048491393f212551446 Mon Sep 17 00:00:00 2001 From: Rafael Quintela Date: Fri, 20 Aug 2021 11:58:35 -0300 Subject: [PATCH 2/3] fix conflict with lsp --- lua/completion.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/completion.lua b/lua/completion.lua index 2dca745..1e32c9b 100644 --- a/lua/completion.lua +++ b/lua/completion.lua @@ -134,15 +134,13 @@ 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 + elseif 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 - if opt.get_option('enable_auto_close_brace') == 1 then - autoAddBrace(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 From 3da68247dab5d1bc431816bc187db17945ba9ed1 Mon Sep 17 00:00:00 2001 From: Rafael Quintela Date: Fri, 3 Sep 2021 09:14:56 -0300 Subject: [PATCH 3/3] autoAddParens is still usefull when not in conflict with lsp --- lua/completion.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/completion.lua b/lua/completion.lua index 1e32c9b..b360860 100644 --- a/lua/completion.lua +++ b/lua/completion.lua @@ -134,11 +134,13 @@ 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 - elseif 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) + 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 completed_item.user_data.snippet_source == 'UltiSnips' then