Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
improve textEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Nov 3, 2023
1 parent 0d55a25 commit 2a59b9a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lua/epo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,29 @@ local function complete_ondone(bufnr)
lsp.util.apply_text_edits(completion_item.additionalTextEdits, bufnr, 'utf-8')
end

local curline = api.nvim_get_current_line()
local is_snippet = completion_item.insertTextFormat == protocol.InsertTextFormat.Snippet
local offset_snip
--apply textEdit
if completion_item.textEdit then
if is_snippet then
if is_snippet and completion_item.textEdit.newText:find('%$%d') then
offset_snip = completion_item.textEdit.newText
else
local range = completion_item.textEdit.range
range['end'].character = col
if col ~= #curline and curline:sub(col + 1, col + 1) ~= ' ' then
range['end'].character = col + 1
api.nvim_win_set_cursor(0, { lnum, col + 1 })
else
range['end'].character = col
end
lsp.util.apply_text_edits({ completion_item.textEdit }, bufnr, client.offset_encoding)
end
elseif completion_item.insertTextFormat == protocol.InsertTextFormat.Snippet then
offset_snip = completion_item.insertText
end

if offset_snip then
offset_snip = completion_item.insertText:sub(col - context[args.buf].startidx + 1)
offset_snip = offset_snip:sub(col - context[args.buf].startidx + 1)
if #offset_snip > 0 then
vim.snippet.expand(offset_snip)
end
Expand Down

0 comments on commit 2a59b9a

Please sign in to comment.