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

Commit 02df2fd

Browse files
authored
Merge pull request #339 from runiq/use-matchend-for-suffix
matchend() instead of reverse()+match() for suffix
2 parents fc9b2fd + 133b7be commit 02df2fd

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lua/completion/source.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ function M.triggerCompletion(force)
142142
local bufnr, line_to_cursor, cursor_to_end = getPositionParam()
143143
local textMatch = vim.fn.match(line_to_cursor, '\\k*$')
144144
local prefix = line_to_cursor:sub(textMatch+1)
145-
local rev_textMatch = #cursor_to_end - vim.fn.match(cursor_to_end:reverse(), '\\k*$')
146-
local suffix = cursor_to_end:sub(1, rev_textMatch)
145+
local suffix = cursor_to_end:sub(1, vim.fn.matchend(cursor_to_end, '^\\k*'))
147146
manager.insertChar = true
148147
-- force is used when manually trigger, so it doesn't repect the trigger word length
149148
triggerCurrentCompletion(bufnr, line_to_cursor, prefix, textMatch, suffix, force)
@@ -154,8 +153,7 @@ function M.autoCompletion()
154153
local bufnr, line_to_cursor, cursor_to_end = getPositionParam()
155154
local textMatch = vim.fn.match(line_to_cursor, '\\k*$')
156155
local prefix = line_to_cursor:sub(textMatch+1)
157-
local rev_textMatch = #cursor_to_end - vim.fn.match(cursor_to_end:reverse(), '\\k*$')
158-
local suffix = cursor_to_end:sub(1, rev_textMatch)
156+
local suffix = cursor_to_end:sub(1, vim.fn.matchend(cursor_to_end, '^\\k*'))
159157
local length = opt.get_option('trigger_keyword_length')
160158

161159
-- reset completion when deleting character in insert mode

0 commit comments

Comments
 (0)