From 88998315d3e4282689ff89780286af9366b9273a Mon Sep 17 00:00:00 2001 From: Leonhard Kost Date: Mon, 7 Jul 2025 00:39:19 +0200 Subject: [PATCH] Add completion and basic lsp config to nixvim --- flake.lock | 24 +++---- modules/home-manager/nixvim/plugins/cmp.nix | 66 +++++++++++++++++++ .../home-manager/nixvim/plugins/default.nix | 2 + modules/home-manager/nixvim/plugins/lsp.nix | 31 +++++++++ 4 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 modules/home-manager/nixvim/plugins/cmp.nix create mode 100644 modules/home-manager/nixvim/plugins/lsp.nix diff --git a/flake.lock b/flake.lock index 3cef34c..2148df3 100644 --- a/flake.lock +++ b/flake.lock @@ -46,11 +46,11 @@ ] }, "locked": { - "lastModified": 1749154018, - "narHash": "sha256-gjN3j7joRvT3a8Zgcylnd4NFsnXeDBumqiu4HmY1RIg=", + "lastModified": 1751810233, + "narHash": "sha256-kllkNbIqQi3VplgTMeGzuh1t8Gk8TauvkTRt93Km+tQ=", "owner": "nix-community", "repo": "home-manager", - "rev": "7aae0ee71a17b19708b93b3ed448a1a0952bf111", + "rev": "9b0873b46c9f9e4b7aa01eb634952c206af53068", "type": "github" }, "original": { @@ -90,11 +90,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1750400657, - "narHash": "sha256-3vkjFnxCOP6vm5Pm13wC/Zy6/VYgei/I/2DWgW4RFeA=", + "lastModified": 1751741127, + "narHash": "sha256-t75Shs76NgxjZSgvvZZ9qOmz5zuBE8buUaYD28BMTxg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "b2485d56967598da068b5a6946dadda8bfcbcd37", + "rev": "29e290002bfff26af1db6f64d070698019460302", "type": "github" }, "original": { @@ -106,11 +106,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1750365781, - "narHash": "sha256-XE/lFNhz5lsriMm/yjXkvSZz5DfvKJLUjsS6pP8EC50=", + "lastModified": 1751637120, + "narHash": "sha256-xVNy/XopSfIG9c46nRmPaKfH1Gn/56vQ8++xWA8itO4=", "owner": "nixos", "repo": "nixpkgs", - "rev": "08f22084e6085d19bcfb4be30d1ca76ecb96fe54", + "rev": "5c724ed1388e53cc231ed98330a60eb2f7be4be3", "type": "github" }, "original": { @@ -130,11 +130,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1750149910, - "narHash": "sha256-M0WNjAy2FCHJAb1hEp+J2gnMk707K5/iTA24amEu/s8=", + "lastModified": 1751479430, + "narHash": "sha256-ub1Pj+oSrt2bE1tzTRYEwzCFewsc9F7X7RIJooM94MU=", "owner": "nix-community", "repo": "nixvim", - "rev": "1252966779a5632a3cd5238e442d55a1d2f56660", + "rev": "13cc4d84572c5f5d469a3a3454fa2028f78a3137", "type": "github" }, "original": { diff --git a/modules/home-manager/nixvim/plugins/cmp.nix b/modules/home-manager/nixvim/plugins/cmp.nix new file mode 100644 index 0000000..6494b64 --- /dev/null +++ b/modules/home-manager/nixvim/plugins/cmp.nix @@ -0,0 +1,66 @@ +{ + programs.nixvim = { + opts.completeopt = ["menu" "menuone" "noselect"]; + + plugins = { + luasnip.enable = true; + cmp-nvim-lsp.enable = true; + cmp-nvim-lsp-signature-help.enable = true; + + lspkind = { + enable = true; + + cmp = { + enable = true; + menu = { + nvim_lsp = "[LSP]"; + nvim_lua = "[api]"; + path = "[path]"; + luasnip = "[snip]"; + buffer = "[buffer]"; + }; + }; + + extraOptions = { + mode = "symbol"; + }; + }; + + cmp = { + enable = true; + autoEnableSources = true; + + settings = { + snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end"; + + mapping = { + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = "cmp.mapping.close()"; + "" = "cmp.mapping.confirm({ select = true })"; + "" = "cmp.mapping.confirm({ select = true })"; + "" = "cmp.mapping.complete()"; + "" = ''cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, {'i', 's'})''; + "" = ''cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, {'i', 's'})''; + }; + + sources = [ + { name = "nvim_lsp"; } + { name = "luasnip"; } + { name = "path"; } + ]; + }; + }; + }; + }; +} diff --git a/modules/home-manager/nixvim/plugins/default.nix b/modules/home-manager/nixvim/plugins/default.nix index 34dcacd..da77697 100644 --- a/modules/home-manager/nixvim/plugins/default.nix +++ b/modules/home-manager/nixvim/plugins/default.nix @@ -1,5 +1,7 @@ { pkgs, ... }: { imports = [ + ./cmp.nix + ./lsp.nix ./treesitter.nix ./lualine.nix ./nvim-autopairs.nix diff --git a/modules/home-manager/nixvim/plugins/lsp.nix b/modules/home-manager/nixvim/plugins/lsp.nix new file mode 100644 index 0000000..2b63b70 --- /dev/null +++ b/modules/home-manager/nixvim/plugins/lsp.nix @@ -0,0 +1,31 @@ +{ + programs.nixvim = { + plugins = { + lsp = { + enable = true; + + keymaps = { + silent = true; + lspBuf = { + "gd" = "definition"; + "gD" = "declaration"; + "gr" = "references"; + "gI" = "implementation"; + "ca" = "code_action"; + "D" = "type_definition"; + "rn" = "rename"; + }; + }; + + servers = { + lua_ls.enable = true; + nil_ls.enable = true; + pyright.enable = true; + }; + }; + lsp-format = { + enable = true; + }; + }; + }; +}