From 51c75e287434a38152b7e5d3aca7cbdac6108309 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 13 Jul 2022 02:15:00 +0000 Subject: [PATCH] fix: nvim-cmp completion bugs --- .gitignore | 1 + hosts/wsl/default.nix | 4 +- modules/darwin/nixpkgs.nix | 2 +- .../editor/neovim/lua/packer/completion.lua | 47 ++++++++++++++++--- modules/editor/neovim/lua/packer/lsp.lua | 2 +- modules/editor/neovim/lua/packer/visuals.lua | 8 ++-- modules/shell/nixpkgs.nix | 2 +- 7 files changed, 51 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 734c056..1afbbd8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.db **/.direnv/** result +.luarc.json diff --git a/hosts/wsl/default.nix b/hosts/wsl/default.nix index f2ba0ab..06730ce 100644 --- a/hosts/wsl/default.nix +++ b/hosts/wsl/default.nix @@ -20,7 +20,9 @@ nixpkgs.lib.nixosSystem { automountPath = "/mnt"; defaultUser = globals.user; startMenuLaunchers = true; - wslConf.network.generateResolvConf = true; + wslConf.network.generateResolvConf = true; # Turn off if breaking VPN + interop.includePath = + false; # Including Windows PATH will slow down Neovim }; } ../common.nix diff --git a/modules/darwin/nixpkgs.nix b/modules/darwin/nixpkgs.nix index 3788398..3f8fbc1 100644 --- a/modules/darwin/nixpkgs.nix +++ b/modules/darwin/nixpkgs.nix @@ -13,7 +13,7 @@ if test "$argv[1]" = "offline" set option "--option substitute false" end - git -C ${config.dotfilesPath} add --all + git -C ${config.dotfilesPath} add --intent-to-add --all commandline -r "darwin-rebuild switch $option --flake ${config.dotfilesPath}#macbook" commandline --function execute ''; diff --git a/modules/editor/neovim/lua/packer/completion.lua b/modules/editor/neovim/lua/packer/completion.lua index c21e69b..ef331a8 100644 --- a/modules/editor/neovim/lua/packer/completion.lua +++ b/modules/editor/neovim/lua/packer/completion.lua @@ -13,6 +13,7 @@ M.packer = function(use) use("hrsh7th/cmp-nvim-lua") --- Nvim lua api completion use("saadparwaiz1/cmp_luasnip") --- Luasnip completion use("lukas-reineke/cmp-rg") --- Ripgrep completion + use("rafamadriz/friendly-snippets") -- Lots of pre-generated snippets -- Completion engine use({ @@ -20,6 +21,35 @@ M.packer = function(use) requires = { "L3MON4D3/LuaSnip" }, config = function() local cmp = require("cmp") + + local kind_icons = { + Text = "", + Method = "m", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", + } + cmp.setup({ -- Setup snippet completion @@ -31,9 +61,11 @@ M.packer = function(use) -- Setup completion keybinds mapping = { + [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), - [""] = function(fallback) + [""] = function(_) cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), @@ -48,7 +80,7 @@ M.packer = function(use) behavior = cmp.ConfirmBehavior.Replace, select = true, }), - [""] = cmp.mapping(function(fallback) + [""] = cmp.mapping(function(_) if require("luasnip").expand_or_jumpable() then require("luasnip").expand_or_jump() end @@ -72,8 +104,9 @@ M.packer = function(use) -- Visual presentation formatting = { - fields = { "abbr", "menu" }, + fields = { "kind", "abbr", "menu" }, format = function(entry, vim_item) + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) vim_item.menu = ({ luasnip = "[Snippet]", buffer = "[Buffer]", @@ -87,10 +120,10 @@ M.packer = function(use) }, -- Docs - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, + -- window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + -- }, -- Extra features experimental = { diff --git a/modules/editor/neovim/lua/packer/lsp.lua b/modules/editor/neovim/lua/packer/lsp.lua index cd8f2a6..981124b 100644 --- a/modules/editor/neovim/lua/packer/lsp.lua +++ b/modules/editor/neovim/lua/packer/lsp.lua @@ -24,7 +24,7 @@ M.packer = function(use) settings = { Lua = { diagnostics = { - globals = { "vim" }, + globals = { "vim", "hs" }, }, }, }, diff --git a/modules/editor/neovim/lua/packer/visuals.lua b/modules/editor/neovim/lua/packer/visuals.lua index 299d196..c83583e 100644 --- a/modules/editor/neovim/lua/packer/visuals.lua +++ b/modules/editor/neovim/lua/packer/visuals.lua @@ -49,11 +49,11 @@ M.packer = function(use) }, }) -- Move buffers - vim.keymap.set("n", "L", ":BufferLineCycleNext") - vim.keymap.set("n", "H", ":BufferLineCyclePrev") + vim.keymap.set("n", "L", ":BufferLineCycleNext", { silent = true }) + vim.keymap.set("n", "H", ":BufferLineCyclePrev", { silent = true }) -- Kill buffer - vim.keymap.set("n", "x", " :Bdelete") + vim.keymap.set("n", "x", " :Bdelete", { silent = true }) -- Shift buffers -- vim.keymap.set("n", "", ":BufferLineMoveNext") @@ -100,7 +100,7 @@ M.packer = function(use) relativenumber = false, }, }) - vim.keymap.set("n", "e", ":NvimTreeFindFileToggle") + vim.keymap.set("n", "e", ":NvimTreeFindFileToggle", { silent = true }) end, }) diff --git a/modules/shell/nixpkgs.nix b/modules/shell/nixpkgs.nix index e36f120..0cf8adf 100644 --- a/modules/shell/nixpkgs.nix +++ b/modules/shell/nixpkgs.nix @@ -37,7 +37,7 @@ if test "$argv[1]" = "offline" set option "--option substitute false" end - git -C ${config.dotfilesPath} add --all + git -C ${config.dotfilesPath} add --intent-to-add --all commandline -r "doas nixos-rebuild switch $option --flake ${config.dotfilesPath}" commandline --function execute '';