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

Commit 895a12f

Browse files
committed
feat: configurable snippet expansion
fix
1 parent 6d7c66e commit 895a12f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

lua/completion/source/lsp.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@ local function get_context_aware_snippets(item, completion_item, line_to_cursor)
4545
end
4646
local line = vim.api.nvim_get_current_line()
4747
local nextWord = line:sub(#line_to_cursor+1, #line_to_cursor+1)
48-
if nextWord == " " or #nextWord == 0 then
48+
if #nextWord == 0 then
4949
return
50-
else
51-
local matches
52-
word, matches = item.word:gsub("%(.*%)$", "")
53-
if matches == 0 then
54-
word, matches = item.word:gsub("<.*>$", "")
55-
end
56-
if matches ~= 0 then
57-
item.word = word
58-
item.user_data = {}
50+
end
51+
for _,ch in ipairs(vim.g.completion_expand_characters) do
52+
if nextWord == ch then
53+
return
5954
end
6055
end
56+
item.user_data = {}
57+
local matches
58+
word, matches = item.word:gsub("%(.*%)$", "")
59+
if matches == 0 then
60+
word, matches = item.word:gsub("<.*>$", "")
61+
end
62+
if matches ~= 0 then
63+
item.word = word
64+
end
6165
end
6266

6367
local function text_document_completion_list_to_complete_items(result, params)

plugin/completion.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ if ! exists('g:completion_fuzzy_match')
7777
let g:completion_enable_fuzzy_match = 0
7878
endif
7979

80+
if ! exists('g:completion_expand_characters')
81+
let g:completion_expand_characters = [' ', '\t', '>', ';']
82+
endif
83+
8084
if ! exists('g:completion_matching_ignore_case')
8185
let g:completion_matching_ignore_case = 0
8286
endif

0 commit comments

Comments
 (0)