Skip to content
Merged
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
25 changes: 18 additions & 7 deletions lua/copilot-lsp/nes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local nes_ns = vim.api.nvim_create_namespace("copilotlsp.nes")
---@param ctx lsp.HandlerContext
local function handle_nes_response(err, result, ctx)
if err then
-- vim.notify(err.message)
vim.notify("[copilot-lsp] " .. err.message)
return
end
-- Validate buffer still exists before processing response
Expand All @@ -22,21 +22,32 @@ local function handle_nes_response(err, result, ctx)
--- Convert to textEdit fields
edit.newText = edit.text
end
nes_ui._display_next_suggestion(ctx.bufnr, nes_ns, result.edits)
if nes_ui._display_next_suggestion(ctx.bufnr, nes_ns, result.edits) then
local client = vim.lsp.get_client_by_id(ctx.client_id)
assert(client, errs.ErrNotStarted)
client:notify("textDocument/didShowInlineEdit", {
item = {
command = result.edits[1].command,
},
})
end
end

--- Requests the NextEditSuggestion from the current cursor position
---@param copilot_lss? vim.lsp.Client|string
function M.request_nes(copilot_lss)
local pos_params = vim.lsp.util.make_position_params(0, "utf-16")
local version = vim.lsp.util.buf_versions[vim.api.nvim_get_current_buf()]
local bufnr = vim.api.nvim_get_current_buf()
if type(copilot_lss) == "string" then
copilot_lss = vim.lsp.get_clients({ name = copilot_lss })[1]
end
assert(copilot_lss, errs.ErrNotStarted)
---@diagnostic disable-next-line: inject-field
pos_params.textDocument.version = version
copilot_lss:request("textDocument/copilotInlineEdit", pos_params, handle_nes_response)
if copilot_lss.attached_buffers[bufnr] then
local version = vim.lsp.util.buf_versions[bufnr]
local pos_params = vim.lsp.util.make_position_params(0, "utf-16")
---@diagnostic disable-next-line: inject-field
pos_params.textDocument.version = version
copilot_lss:request("textDocument/copilotInlineEdit", pos_params, handle_nes_response)
end
end

--- Walks the cursor to the start of the edit.
Expand Down
4 changes: 3 additions & 1 deletion lua/copilot-lsp/nes/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ end
---@param bufnr integer
---@param ns_id integer
---@param edits copilotlsp.InlineEdit[]
---@return boolean
function M._display_next_suggestion(bufnr, ns_id, edits)
M.clear_suggestion(bufnr, ns_id)
if not edits or #edits == 0 then
return
return false
end

local suggestion = edits[1]
Expand Down Expand Up @@ -290,6 +291,7 @@ function M._display_next_suggestion(bufnr, ns_id, edits)
return false -- Keep the autocmd
end,
})
return true
end

return M
1 change: 0 additions & 1 deletion lua/copilot-lsp/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ local function merge_captures(captures)
then
local prev_hl = type(prev.hl) == "table" and prev.hl or { prev.hl }
local curr_hl = type(curr.hl) == "table" and curr.hl or { curr.hl }
---@diagnostic disable-next-line: param-type-mismatch
vim.list_extend(prev_hl, curr_hl)
curr.hl = prev_hl
else
Expand Down