Skip to content

Commit

Permalink
Add option to disable auto hide on pumvisible (#270)
Browse files Browse the repository at this point in the history
Add option to display ghost text while completion menu is open.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
  • Loading branch information
deathbeam committed Jun 15, 2024
1 parent 8b3a427 commit 86537b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ require('copilot').setup({
suggestion = {
enabled = true,
auto_trigger = false,
hide_during_completion = true,
debounce = 75,
keymap = {
accept = "<M-l>",
Expand Down
1 change: 1 addition & 0 deletions lua/copilot/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local default_config = {
suggestion = {
enabled = true,
auto_trigger = false,
hide_during_completion = true,
debounce = 15,
---@type table<'accept'|'accept_word'|'accept_line'|'next'|'prev'|'dismiss', false|string>
keymap = {
Expand Down
17 changes: 16 additions & 1 deletion lua/copilot/suggestion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local copilot = {
context = {},

auto_trigger = false,
hide_during_completion = true,
debounce = 75,
}

Expand Down Expand Up @@ -196,7 +197,7 @@ local function get_current_suggestion(ctx)
local ok, choice = pcall(function()
if
not vim.fn.mode():match("^[iR]")
or vim.fn.pumvisible() == 1
or (copilot.hide_during_completion and vim.fn.pumvisible() == 1)
or vim.b.copilot_suggestion_hidden
or not ctx.suggestions
or #ctx.suggestions == 0
Expand Down Expand Up @@ -574,6 +575,13 @@ local function on_cursor_moved_i()
end
end

local function on_text_changed_p()
local ctx = get_ctx()
if not copilot.hide_during_completion and (copilot._copilot_timer or ctx.params or should_auto_trigger()) then
schedule(ctx)
end
end

local function on_complete_changed()
clear()
end
Expand Down Expand Up @@ -621,6 +629,12 @@ local function create_autocmds()
desc = "[copilot] (suggestion) cursor moved insert",
})

vim.api.nvim_create_autocmd("TextChangedP", {
group = copilot.augroup,
callback = on_text_changed_p,
desc = "[copilot] (suggestion) text changed pum",
})

vim.api.nvim_create_autocmd("CompleteChanged", {
group = copilot.augroup,
callback = on_complete_changed,
Expand Down Expand Up @@ -653,6 +667,7 @@ function mod.setup()
set_keymap(opts.keymap or {})

copilot.auto_trigger = opts.auto_trigger
copilot.hide_during_completion = opts.hide_during_completion

create_autocmds()

Expand Down

0 comments on commit 86537b2

Please sign in to comment.