Skip to content

Commit 77768bd

Browse files
committed
feat: add accept hint popup
1 parent 69d0934 commit 77768bd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lua/copilot-lsp/nes/ui.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local M = {}
55
---@param ns_id integer
66
local function _dismiss_suggestion_ui(bufnr, suggestion_ui, ns_id)
77
pcall(vim.api.nvim_win_close, suggestion_ui.preview_winnr, true)
8+
pcall(vim.api.nvim_win_close, suggestion_ui.hint_winnr, true)
89
pcall(vim.api.nvim_buf_clear_namespace, bufnr, ns_id, 0, -1)
910
end
1011

@@ -130,6 +131,27 @@ function M._display_next_suggestion(edits, ns_id)
130131
ui.preview_winnr = preview_winnr
131132
end
132133

134+
local hint_bufnr = vim.api.nvim_create_buf(false, true)
135+
vim.api.nvim_buf_set_lines(hint_bufnr, 0, -1, false, { " ⇥ Accept" })
136+
137+
vim.bo[hint_bufnr].modifiable = false
138+
vim.bo[hint_bufnr].buflisted = false
139+
vim.bo[hint_bufnr].buftype = "nofile"
140+
vim.bo[hint_bufnr].bufhidden = "wipe"
141+
142+
local hint_winnr = vim.api.nvim_open_win(hint_bufnr, false, {
143+
relative = "cursor",
144+
width = 10,
145+
height = 1,
146+
row = (suggestion.range["end"].line + lines.same_line) - vim.api.nvim_win_get_cursor(0)[1] - 1,
147+
col = 0,
148+
zindex = 150, -- above ins-completion, below messages
149+
style = "minimal",
150+
border = "none",
151+
})
152+
153+
ui.hint_winnr = hint_winnr
154+
133155
suggestion.ui = ui
134156

135157
vim.b[bufnr].nes_state = suggestion

lua/copilot-lsp/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
---@class nes.EditSuggestionUI
1313
---@field preview_winnr? integer
14+
---@field hint_winnr? integer
1415

1516
---@class nes.Apply.Opts
1617
---@field jump? boolean | { hl_timeout: integer? } auto jump to the end of the new edit

0 commit comments

Comments
 (0)