Skip to content

Commit 86537b2

Browse files
authored
Add option to disable auto hide on pumvisible (zbirenbaum#270)
Add option to display ghost text while completion menu is open. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 8b3a427 commit 86537b2

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ require('copilot').setup({
6464
suggestion = {
6565
enabled = true,
6666
auto_trigger = false,
67+
hide_during_completion = true,
6768
debounce = 75,
6869
keymap = {
6970
accept = "<M-l>",

lua/copilot/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local default_config = {
2121
suggestion = {
2222
enabled = true,
2323
auto_trigger = false,
24+
hide_during_completion = true,
2425
debounce = 15,
2526
---@type table<'accept'|'accept_word'|'accept_line'|'next'|'prev'|'dismiss', false|string>
2627
keymap = {

lua/copilot/suggestion.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local copilot = {
2323
context = {},
2424

2525
auto_trigger = false,
26+
hide_during_completion = true,
2627
debounce = 75,
2728
}
2829

@@ -196,7 +197,7 @@ local function get_current_suggestion(ctx)
196197
local ok, choice = pcall(function()
197198
if
198199
not vim.fn.mode():match("^[iR]")
199-
or vim.fn.pumvisible() == 1
200+
or (copilot.hide_during_completion and vim.fn.pumvisible() == 1)
200201
or vim.b.copilot_suggestion_hidden
201202
or not ctx.suggestions
202203
or #ctx.suggestions == 0
@@ -574,6 +575,13 @@ local function on_cursor_moved_i()
574575
end
575576
end
576577

578+
local function on_text_changed_p()
579+
local ctx = get_ctx()
580+
if not copilot.hide_during_completion and (copilot._copilot_timer or ctx.params or should_auto_trigger()) then
581+
schedule(ctx)
582+
end
583+
end
584+
577585
local function on_complete_changed()
578586
clear()
579587
end
@@ -621,6 +629,12 @@ local function create_autocmds()
621629
desc = "[copilot] (suggestion) cursor moved insert",
622630
})
623631

632+
vim.api.nvim_create_autocmd("TextChangedP", {
633+
group = copilot.augroup,
634+
callback = on_text_changed_p,
635+
desc = "[copilot] (suggestion) text changed pum",
636+
})
637+
624638
vim.api.nvim_create_autocmd("CompleteChanged", {
625639
group = copilot.augroup,
626640
callback = on_complete_changed,
@@ -653,6 +667,7 @@ function mod.setup()
653667
set_keymap(opts.keymap or {})
654668

655669
copilot.auto_trigger = opts.auto_trigger
670+
copilot.hide_during_completion = opts.hide_during_completion
656671

657672
create_autocmds()
658673

0 commit comments

Comments
 (0)