Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

feat(auto close brace) #393

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions lua/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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("}<left>")
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
Expand Down Expand Up @@ -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
Expand Down