From 1f328d26633aeddbf2c70c23b33337c0d7f9d163 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 23 Aug 2025 12:38:45 +0200 Subject: [PATCH] nvim: Add copilot suggestions to blink Suggestions are given at the top of the completion menu. Additionally, since that can get really annoying really quick there have been some changes specifically for copilot.lua: We start with it disabled. It can be enabled with `ap` and disabled again with `aP` for Ai>coPilot. If the plugin at some point exposes functionality to toggle itself on/off completely I would gladly switch to that. The current toggle command only attaches/detaches the buffer but still runs the client in the background. This is less desirable for me, plus it means the completions are still done automatically in blink. --- nvim/.config/nvim/lazy-lock.json | 1 + nvim/.config/nvim/lua/plugins/llm.lua | 67 +++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 77a53ba..17a3aec 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -3,6 +3,7 @@ "FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" }, "Navigator.nvim": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" }, "bats.vim": { "branch": "master", "commit": "6a5d2ef22b0ede503d867770afd02ebb1f97b709" }, + "blink-copilot": { "branch": "main", "commit": "41e91a659bd9b8cba9ba2ea68a69b52ba5a9ebd8" }, "blink.cmp": { "branch": "main", "commit": "9bcb14b43852a6f2bfd5ac9ef29cb5cf09b1b39b" }, "blink.compat": { "branch": "main", "commit": "2ed6d9a28b07fa6f3bface818470605f8896408c" }, "cmp-calc": { "branch": "main", "commit": "5947b412da67306c5b68698a02a846760059be2e" }, diff --git a/nvim/.config/nvim/lua/plugins/llm.lua b/nvim/.config/nvim/lua/plugins/llm.lua index 38a90ba..7d90eaa 100644 --- a/nvim/.config/nvim/lua/plugins/llm.lua +++ b/nvim/.config/nvim/lua/plugins/llm.lua @@ -2,22 +2,79 @@ return { { -- NOTE: Requires manual auth with ':Copilot auth' or 'GH_COPILOT_TOKEN' set as envvar "zbirenbaum/copilot.lua", - dependencies = { "AndreM222/copilot-lualine" }, + dependencies = { + "AndreM222/copilot-lualine", + { -- show completions in blink + "saghen/blink.cmp", + optional = true, + dependencies = { + { + "fang2hou/blink-copilot", + opts = { + auto_refresh = { + backward = false, + forward = false, + }, + }, + }, + }, + opts = { + sources = { + default = { "copilot" }, + providers = { + copilot = { + name = "copilot", + module = "blink-copilot", + score_offset = 100, + async = true, + }, + }, + }, + }, + }, + }, cmd = "Copilot", - event = "InsertEnter", + event = { "InsertEnter", "VeryLazy" }, opts = { panel = { layout = { position = "bottom" } }, suggestion = { keymap = { accept = "" } }, + logger = { print_log_level = vim.log.levels.ERROR }, }, + config = function(_, opts) + require("copilot").setup(opts) + -- TODO: See also https://github.com/zbirenbaum/copilot.lua/issues/302 for potential + -- better solutions. + -- TODO: also Find way of having a 'toggle' for mapping below. + -- Current copilot.lua exposed 'toggle' command does NOT do the same. + require("copilot.command").disable() + end, keys = { { - "ap", + "aC", function() - -- FIXME: If opening before lazy-loaded, errors + require("copilot.panel").setup() require("copilot.panel").open({}) require("copilot.panel").refresh() end, - desc = "Refresh Copilot Panel", + desc = "Open copilot panel", + silent = true, + mode = { "n" }, + }, + { + "ap", + function() + require("copilot.command").enable() + end, + desc = "Enable copilot", + silent = true, + mode = { "n" }, + }, + { + "aP", + function() + require("copilot.command").disable() + end, + desc = "Disable copilot", silent = true, mode = { "n" }, },