Skip to content

Commit 37a9de0

Browse files
committed
feat(nes): display inline edit with extmarks
Add a display_nes function to render inline edits as virtual lines using extmarks. Also, add keymaps for accepting and declining inline edits.
1 parent b24759c commit 37a9de0

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

lua/copilot-lsp/nes/init.lua

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@ local utils = require("copilot-lsp.util")
33

44
local M = {}
55

6+
local nes_ext
7+
local nes_ns = vim.api.nvim_create_namespace("copilot-nes")
8+
9+
---@param edit copilotInlineEdit
10+
local function display_nes(edit)
11+
dd("trying to display")
12+
local bufnr = vim.uri_to_bufnr(edit.textDocument.uri)
13+
if edit.text:match("\n") then
14+
assert(false, "multi line edits not supported yet")
15+
end
16+
17+
nes_ext = vim.api.nvim_buf_set_extmark(bufnr, nes_ns, edit.range.start.line, edit.range.start.character, {
18+
id = nes_ext,
19+
virt_lines = { { { edit.text, "Comment" } } },
20+
})
21+
22+
--create accept and decline keymaps
23+
vim.keymap.set("n", "<leader>xa", function()
24+
utils.apply_inline_edit(edit)
25+
vim.api.nvim_buf_del_extmark(bufnr, nes_ns, nes_ext)
26+
end, { buffer = bufnr })
27+
28+
vim.keymap.set("n", "<leader>xd", function()
29+
vim.api.nvim_buf_del_extmark(bufnr, nes_ns, nes_ext)
30+
end, { buffer = bufnr })
31+
end
32+
633
---@param err lsp.ResponseError?
734
---@param result copilotInlineEditResponse
835
local function handle_nes_response(err, result)
@@ -21,7 +48,8 @@ local function handle_nes_response(err, result)
2148
end
2249

2350
local edit = result.edits[1]
24-
utils.apply_inline_edit(edit)
51+
display_nes(edit)
52+
-- utils.apply_inline_edit(edit)
2553
end
2654

2755
---@param copilot_lss vim.lsp.Client?

0 commit comments

Comments
 (0)