From 29f12680d7cb81b50db551fa1db8a0346e12d770 Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Wed, 27 Mar 2024 09:05:46 -0400 Subject: [PATCH] nvim-cmp & friends --- flake.lock | 16 ++-- nix/home-manager/flake.lock | 12 +-- nix/home-manager/modules/packages/default.nix | 2 +- nix/home-manager/modules/packages/git.nix | 7 +- nix/home-manager/modules/packages/neovim.nix | 91 +++++++++++++++++++ .../modules/packages/neovim/core.lua | 12 +++ .../modules/packages/neovim/pre.lua | 29 +++++- 7 files changed, 149 insertions(+), 20 deletions(-) diff --git a/flake.lock b/flake.lock index 5dbde77..4e47482 100644 --- a/flake.lock +++ b/flake.lock @@ -33,11 +33,11 @@ "pre-commit-hooks": "pre-commit-hooks_2" }, "locked": { - "lastModified": 1711122363, - "narHash": "sha256-Yw/t9HCY9U/EpkXlzW+5o/WEpZKUNgrSbcuHOZFpAXU=", + "lastModified": 1711371145, + "narHash": "sha256-abuKk8NiXO+tMTOtt+4QbSaFsSmN+Vo4UGLDO4+Ncjg=", "owner": "cachix", "repo": "devenv", - "rev": "63c7109f20b5ded0bc07f95ece9518bbb7fdea5b", + "rev": "e0440c5c88ae2a56813402f32377140840203c52", "type": "github" }, "original": { @@ -428,12 +428,12 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1711001935, - "narHash": "sha256-URtGpHue7HHZK0mrHnSf8wJ6OmMKYSsoLmJybrOLFSQ=", - "rev": "20f77aa09916374aa3141cbc605c955626762c9a", - "revCount": 600876, + "lastModified": 1711163522, + "narHash": "sha256-YN/Ciidm+A0fmJPWlHBGvVkcarYWSC+s3NTPk/P+q3c=", + "rev": "44d0940ea560dee511026a53f0e2e2cde489b4d4", + "revCount": 601756, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.600876%2Brev-20f77aa09916374aa3141cbc605c955626762c9a/018e65e3-9c1d-74a8-acde-67868b074670/source.tar.gz" + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.601756%2Brev-44d0940ea560dee511026a53f0e2e2cde489b4d4/018e6c73-b9c2-7b70-a778-9c1546525f10/source.tar.gz" }, "original": { "type": "tarball", diff --git a/nix/home-manager/flake.lock b/nix/home-manager/flake.lock index 0e25683..f9017e1 100644 --- a/nix/home-manager/flake.lock +++ b/nix/home-manager/flake.lock @@ -131,11 +131,11 @@ "nmt": "nmt" }, "locked": { - "lastModified": 1711294978, - "narHash": "sha256-olXsNg5K9Jl76KLCxekxqgczEC10daMeIlyMge4QDoo=", + "lastModified": 1711372234, + "narHash": "sha256-TCQ9+re33P1N5KyzmXM7taQ1d1A2bVsTfrQgE+z5P04=", "owner": "nixneovim", "repo": "nixneovim", - "rev": "2158e2a8b33ad56ebca580769b53c847092c636f", + "rev": "116ae11583c386e5128a16873e79f817e8251d17", "type": "github" }, "original": { @@ -187,11 +187,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1711320233, - "narHash": "sha256-CAFcHr62hp8/7VYAo7jVrpbrjG5/TKPmKE0GIEXJbTw=", + "lastModified": 1711543506, + "narHash": "sha256-2ZZlQscIBmJUJVy6EysvrJzbrzz8ixA3v/scllRIMaQ=", "owner": "nixOS", "repo": "nixpkgs", - "rev": "f7a6bfd64cb1cb3c12203b6cc4c952ab2b802c79", + "rev": "800d3f070b9514ab86906ffd5db4a7c28e833991", "type": "github" }, "original": { diff --git a/nix/home-manager/modules/packages/default.nix b/nix/home-manager/modules/packages/default.nix index ca7b4b1..7487cf5 100644 --- a/nix/home-manager/modules/packages/default.nix +++ b/nix/home-manager/modules/packages/default.nix @@ -62,7 +62,7 @@ in { sqlite tmux # vscode-fhs - yt-dlp + python312Packages.yt-dlp zenith # zoom-us zstd diff --git a/nix/home-manager/modules/packages/git.nix b/nix/home-manager/modules/packages/git.nix index 250703b..68c9f61 100644 --- a/nix/home-manager/modules/packages/git.nix +++ b/nix/home-manager/modules/packages/git.nix @@ -68,10 +68,9 @@ conflictStyle = "zdiff3"; }; - # Commented out until git 2.44.0 makes its way to nixpkgs - # pack = { - # allowPackReuse = "multi"; - # }; + pack = { + allowPackReuse = "multi"; + }; push = { autoSetupRemote = true; diff --git a/nix/home-manager/modules/packages/neovim.nix b/nix/home-manager/modules/packages/neovim.nix index 0ebca83..7621a7d 100644 --- a/nix/home-manager/modules/packages/neovim.nix +++ b/nix/home-manager/modules/packages/neovim.nix @@ -19,6 +19,9 @@ fugitive = { enable = true; }; + luasnip = { + enable = true; + }; lspconfig = { enable = true; servers = { @@ -32,6 +35,10 @@ terraform-ls.enable = true; }; }; + lspkind = { + enable = true; + mode = "symbol"; + }; mini = { enable = true; ai.enable = true; @@ -50,6 +57,84 @@ splitjoin.enable = true; surround.enable = true; }; + nvim-cmp = { + enable = true; + formatting = { + format = '' + function(entry, vim_item) + vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind) + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[LaTeX]", + })[entry.source.name] + return vim_item + end + ''; + }; + mappingPresets = ["insert"]; + mapping = { + "" = "cmp.mapping.confirm({ select = true})"; + "" = "cmp.mapping.complete()"; + "" = { + modes = ["i" "s" "c"]; + action = '' + function(fallback) + local entry = cmp.get_selected_entry() + if not entry then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + cmp.confirm() + elseif entry then + cmp.confirm() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end + ''; + }; + "" = { + modes = ["i" "s" "c"]; + action = '' + function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end + ''; + }; + }; + + snippet = { + luasnip.enable = true; + }; + sources = { + cmdline = { + enable = true; + }; + emoji.enable = true; + fuzzy_path.enable = true; + luasnip.enable = true; + nvim_lsp.enable = true; + nvim_lsp_document_symbol.enable = true; + nvim_lsp_signature_help.enable = true; + treesitter.enable = true; + }; + view = { + entries = "custom"; + }; + }; project-nvim = { enable = true; }; @@ -67,6 +152,9 @@ enable = true; }; }; + trouble = { + enable = true; + }; undotree = { enable = true; }; @@ -84,6 +172,7 @@ extraPlugins = ( with pkgs.vimPlugins; [ + fuzzy-nvim nvim-ts-context-commentstring telescope-zf-native-nvim vim-ReplaceWithRegister @@ -97,6 +186,8 @@ rainbow-delimiters-nvim gitlinker-linrongbin16 telescope-symbols-nvim + nvim-web-devicons + lsp-signature-nvim ]); mappings = { normal = { diff --git a/nix/home-manager/modules/packages/neovim/core.lua b/nix/home-manager/modules/packages/neovim/core.lua index 2c60320..d6882a0 100644 --- a/nix/home-manager/modules/packages/neovim/core.lua +++ b/nix/home-manager/modules/packages/neovim/core.lua @@ -40,3 +40,15 @@ vim.api.nvim_create_autocmd("TextYankPost", { }) require("gitlinker").setup() + +local cmp = require("cmp") + +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), + matching = { disallow_symbol_nonprefix_matching = false }, +}) diff --git a/nix/home-manager/modules/packages/neovim/pre.lua b/nix/home-manager/modules/packages/neovim/pre.lua index 13ebd67..5f62d47 100644 --- a/nix/home-manager/modules/packages/neovim/pre.lua +++ b/nix/home-manager/modules/packages/neovim/pre.lua @@ -1,3 +1,30 @@ - vim.g.mapleader = " " vim.g.maplocalleader = "," + +local kind_icons = { + Text = "", + Method = "", + Function = "⨐", + Constructor = "", + Field = "", + Variable = "μ", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "፨", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +}