local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
require("lazy").setup({
spec = {
{
{
"zbirenbaum/copilot.lua",
cmd = "Copilot",
build = ":Copilot auth",
event = "BufReadPost",
opts = {
suggestion = {
auto_trigger = true,
keymap = {
accept = false,
},
},
panel = { enabled = false },
},
},
},
},
install = { colorscheme = { "habamax" } },
checker = { enabled = true },
})
vim.keymap.set({ "i", "s" }, "<Tab>", function()
local copilot = require("copilot.suggestion")
vim.notify(string.format("is_visible() => %s", tostring(copilot.is_visible())), vim.log.levels.INFO)
if copilot.is_visible() then
copilot.accept()
else
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Tab>", true, false, true), "n", false)
end
end)
In some cases, when suggestions are accepted programmatically (like the super-tab behavior), the
is_visiblefunction incorrectly returns a truthy value.Reproduction Path
Use the following configuration:
~/.config/nvim/init.lua
Use the following file:
~/test.ts
Open the file at the 6th line in insert mode:
Press
<Tab>two or more times.Open diagnostic messages via
:messagesExpected Behavior
is_visible()function returns a falsy value:Actual Behavior
is_visible()function returns a truthy value.