diff --git a/lua/cargdev/core/keymaps/copilot.lua b/lua/cargdev/core/keymaps/copilot.lua index c3290bb..e6f68e2 100644 --- a/lua/cargdev/core/keymaps/copilot.lua +++ b/lua/cargdev/core/keymaps/copilot.lua @@ -50,16 +50,8 @@ end, { desc = "Copilot: Refresh panel" }) keymap.set("n", "", ":Copilot panel", { desc = "Copilot: Open panel" }) -- Copilot suggestion keymaps (insert mode) -keymap.set("i", "", function() - local suggestion = get_copilot_suggestion() - if suggestion and suggestion.is_visible() then - suggestion.accept() - else - -- Feed Tab through so nvim-cmp can handle it for completion menu/snippets - -- Use 't' flag to avoid remapping, 'n' flag for normal mode keycodes - vim.fn.feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "nt") - end -end, { desc = "Copilot: Accept suggestion" }) +-- Note: Tab mapping is handled in nvim-cmp.lua to avoid conflicts +-- Tab is reserved exclusively for Copilot inline suggestions keymap.set("i", "]", function() local suggestion = get_copilot_suggestion() diff --git a/lua/cargdev/plugins/nvim-cmp.lua b/lua/cargdev/plugins/nvim-cmp.lua index a236f85..dcaf447 100644 --- a/lua/cargdev/plugins/nvim-cmp.lua +++ b/lua/cargdev/plugins/nvim-cmp.lua @@ -47,32 +47,26 @@ return { [""] = cmp.mapping.complete(), -- show completion suggestions [""] = cmp.mapping.abort(), -- close completion window [""] = cmp.mapping.confirm({ select = false }), - -- Tab for completion menu and snippet expansion - -- Note: Copilot suggestion acceptance is handled in keymaps/copilot.lua + -- Tab is reserved for Copilot inline suggestions ONLY + -- Use / to navigate cmp menu, to confirm [""] = cmp.mapping(function(fallback) - -- Handle nvim-cmp completion menu - if cmp.visible() then - local entry = cmp.get_selected_entry() - -- If Copilot suggestion is available and selected, accept it - if entry and entry.source.name == "copilot" then - cmp.confirm({ select = true }) - else - -- Confirm the current selection - cmp.confirm({ select = true }) - end - elseif luasnip.expand_or_jumpable() then - -- Expand snippet or jump to next placeholder + -- Check for Copilot inline suggestion first (highest priority) + local copilot_ok, copilot_suggestion = pcall(require, "copilot.suggestion") + if copilot_ok and copilot_suggestion.is_visible() then + copilot_suggestion.accept() + return + end + -- If no Copilot suggestion, handle snippet jumping + if luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else - -- Fallback to default Tab behavior + -- Default Tab behavior (insert tab character) fallback() end end, { "i", "s" }), -- Shift-Tab to go back in snippets [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then + if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback()