From a39f1f796752f7abaf29205af941b8331779c515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Fri, 13 Feb 2026 16:57:11 +0100 Subject: [PATCH] neovim: copilot in cmp --- packages/vim/default.nix | 55 +++++++++++++++++++++++++--------------- packages/vim/init.lua | 31 ++++++++++++++-------- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/packages/vim/default.nix b/packages/vim/default.nix index 199485e..68a8098 100644 --- a/packages/vim/default.nix +++ b/packages/vim/default.nix @@ -14,28 +14,40 @@ neovim.override { configure = { vimAlias = true; viAlias = true; - customRC = '' - source ${./shared.vim} - source ${./init.vim} - let g:snippet_directory = '${vimPlugins.friendly-snippets}' - luafile ${./init.lua} - '' - + lib.optionalString (stylixColors != null) ( - with stylixColors.withHashtag; - '' - luafile ${writeText "colors.lua" '' - require('base16-colorscheme').setup({ - base00 = '${base00}', base01 = '${base01}', base02 = '${base02}', base03 = '${base03}', - base04 = '${base04}', base05 = '${base05}', base06 = '${base06}', base07 = '${base07}', - base08 = '${base08}', base09 = '${base09}', base0A = '${base0A}', base0B = '${base0B}', - base0C = '${base0C}', base0D = '${base0D}', base0E = '${base0E}', base0F = '${base0F}' + customRC = + + lib.optionalString withCopilot ('' + luafile ${writeText "copilot.lua" '' + require("copilot").setup({ + suggestion = { enabled = false }, + panel = { enabled = false } }) + + require("copilot_cmp").setup() ''} + '') + + '' + source ${./shared.vim} + source ${./init.vim} + let g:snippet_directory = '${vimPlugins.friendly-snippets}' + luafile ${./init.lua} '' - ) - + lib.optionalString (colorscheme != null) '' - colorscheme ${colorscheme} - ''; + + lib.optionalString (stylixColors != null) ( + with stylixColors.withHashtag; + '' + luafile ${writeText "colors.lua" '' + require('base16-colorscheme').setup({ + base00 = '${base00}', base01 = '${base01}', base02 = '${base02}', base03 = '${base03}', + base04 = '${base04}', base05 = '${base05}', base06 = '${base06}', base07 = '${base07}', + base08 = '${base08}', base09 = '${base09}', base0A = '${base0A}', base0B = '${base0B}', + base0C = '${base0C}', base0D = '${base0D}', base0E = '${base0E}', base0F = '${base0F}' + }) + ''} + '' + ) + + lib.optionalString (colorscheme != null) '' + colorscheme ${colorscheme} + ''; packages.nvim = with vimPlugins; { start = [ base16-nvim @@ -81,7 +93,10 @@ neovim.override { } ) ] - ++ lib.optional withCopilot vimPlugins.copilot-vim; + ++ lib.optionals withCopilot [ + vimPlugins.copilot-lua + vimPlugins.copilot-cmp + ]; opt = [ csv dhall-vim diff --git a/packages/vim/init.lua b/packages/vim/init.lua index a8b4715..36ebe19 100644 --- a/packages/vim/init.lua +++ b/packages/vim/init.lua @@ -19,17 +19,23 @@ cmp.setup({ luasnip.lsp_expand(args.body) end, }, + completion = { + autocomplete = { require("cmp.types").cmp.TriggerEvent.TextChanged }, + }, mapping = { - -- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#super-tab-like-mapping + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else - fallback() + cmp.complete() end end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() @@ -41,8 +47,11 @@ cmp.setup({ end, { "i", "s" }), }, sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, + { name = "copilot", priority = 1000 }, + { name = "nvim_lsp", priority = 800 }, + { name = "luasnip", priority = 700 }, + { name = "path", priority = 500 }, + { name = "buffer", priority = 300 }, }), }) @@ -92,8 +101,8 @@ local language_servers = { pyright = {}, -- pyright -- tsserver = {}, -- typescript-language-server cssls = {}, - elmls = {}, -- elm-language-server - gopls = {}, -- gopls + elmls = {}, -- elm-language-server + gopls = {}, -- gopls denols = {}, -- deno built in bashls = {}, -- bash-language-server lua_ls = { @@ -112,9 +121,9 @@ local language_servers = { }, }, }, - hls = {}, -- haskell-language-server - html = {}, -- vscode-langservers-extracted - jsonls = {}, -- vscode-langservers-extracted + hls = {}, -- haskell-language-server + html = {}, -- vscode-langservers-extracted + jsonls = {}, -- vscode-langservers-extracted lemminx = {}, -- lemminx (for xml) nil_ls = { ["nil"] = { @@ -122,10 +131,10 @@ local language_servers = { command = { "nixfmt" }, }, }, - }, -- github:oxalica/nil + }, -- github:oxalica/nil dhall_lsp_server = {}, -- dhall-lsp-server -- rnix = {}, -- rnix-lsp - jqls = {}, -- jq-lsp + jqls = {}, -- jq-lsp rust_analyzer = { ["rust-analyzer"] = {} }, -- eslint = {}, -- volar? vls?