Skip to content
Draft
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
30 changes: 30 additions & 0 deletions lua/copilot-lsp/nes/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local M = {}
---@param ns_id integer
local function _dismiss_suggestion_ui(bufnr, suggestion_ui, ns_id)
pcall(vim.api.nvim_win_close, suggestion_ui.preview_winnr, true)
pcall(vim.api.nvim_win_close, suggestion_ui.hint_winnr, true)
pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns_id, 0, -1)
end

Expand Down Expand Up @@ -59,6 +60,13 @@ function M._calculate_lines(suggestion)
row = suggestion.range["end"].line + deleted_lines_count + 1,
}

-- Calculate positions for hint window
---@type nes.FloatWin
local hint_win = {
row = (suggestion.range["end"].line + same_line) - vim.api.nvim_win_get_cursor(0)[1] - 1,
height = 1,
}

return {
deleted_lines_count = deleted_lines_count,
added_lines = added_lines,
Expand All @@ -67,6 +75,7 @@ function M._calculate_lines(suggestion)
delete_extmark = delete_extmark,
virt_lines_extmark = virt_lines_extmark,
float_win = float_win,
hint_win = hint_win,
}
end

Expand Down Expand Up @@ -135,6 +144,27 @@ function M._display_next_suggestion(edits, ns_id)
ui.preview_winnr = preview_winnr
end

local hint_bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(hint_bufnr, 0, -1, false, { " ⇥ Accept" })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the keymap is set in config should we adapt to different preferences

Although I'm not sure of the best way to adapt to this. So maybe this fine as-is for now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not really sure here - let me know what you want there or feel free to push changes to this branch if you have an idea.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a vim.g.nesicon or default

We should work out a naming convention for these options


vim.bo[hint_bufnr].modifiable = false
vim.bo[hint_bufnr].buflisted = false
vim.bo[hint_bufnr].buftype = "nofile"
vim.bo[hint_bufnr].bufhidden = "wipe"

local hint_winnr = vim.api.nvim_open_win(hint_bufnr, false, {
relative = "cursor",
width = 10,
height = lines.hint_win.height,
row = lines.hint_win.row,
col = 0,
zindex = 150, -- above ins-completion, below messages
style = "minimal",
border = "none",
})

ui.hint_winnr = hint_winnr

suggestion.ui = ui

vim.b[bufnr].nes_state = suggestion
Expand Down
2 changes: 2 additions & 0 deletions lua/copilot-lsp/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

---@class nes.EditSuggestionUI
---@field preview_winnr? integer
---@field hint_winnr? integer

---@class nes.DeleteExtmark
--- Holds row information for delete highlight extmark.
Expand All @@ -36,3 +37,4 @@
---@field delete_extmark nes.DeleteExtmark
---@field virt_lines_extmark nes.VirtLinesExtmark
---@field float_win nes.FloatWin
---@field hint_win nes.FloatWin
Loading