fix: nvim-cmp completion bugs

This commit is contained in:
Noah Masur 2022-07-13 02:15:00 +00:00
parent a22acac57d
commit 51c75e2874
7 changed files with 51 additions and 15 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
*.db *.db
**/.direnv/** **/.direnv/**
result result
.luarc.json

View File

@ -20,7 +20,9 @@ nixpkgs.lib.nixosSystem {
automountPath = "/mnt"; automountPath = "/mnt";
defaultUser = globals.user; defaultUser = globals.user;
startMenuLaunchers = true; 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 ../common.nix

View File

@ -13,7 +13,7 @@
if test "$argv[1]" = "offline" if test "$argv[1]" = "offline"
set option "--option substitute false" set option "--option substitute false"
end 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 -r "darwin-rebuild switch $option --flake ${config.dotfilesPath}#macbook"
commandline --function execute commandline --function execute
''; '';

View File

@ -13,6 +13,7 @@ M.packer = function(use)
use("hrsh7th/cmp-nvim-lua") --- Nvim lua api completion use("hrsh7th/cmp-nvim-lua") --- Nvim lua api completion
use("saadparwaiz1/cmp_luasnip") --- Luasnip completion use("saadparwaiz1/cmp_luasnip") --- Luasnip completion
use("lukas-reineke/cmp-rg") --- Ripgrep completion use("lukas-reineke/cmp-rg") --- Ripgrep completion
use("rafamadriz/friendly-snippets") -- Lots of pre-generated snippets
-- Completion engine -- Completion engine
use({ use({
@ -20,6 +21,35 @@ M.packer = function(use)
requires = { "L3MON4D3/LuaSnip" }, requires = { "L3MON4D3/LuaSnip" },
config = function() config = function()
local cmp = require("cmp") 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({ cmp.setup({
-- Setup snippet completion -- Setup snippet completion
@ -31,9 +61,11 @@ M.packer = function(use)
-- Setup completion keybinds -- Setup completion keybinds
mapping = { mapping = {
["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), ["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
["<Esc>"] = function(fallback) ["<Esc>"] = function(_)
cmp.mapping({ cmp.mapping({
i = cmp.mapping.abort(), i = cmp.mapping.abort(),
c = cmp.mapping.close(), c = cmp.mapping.close(),
@ -48,7 +80,7 @@ M.packer = function(use)
behavior = cmp.ConfirmBehavior.Replace, behavior = cmp.ConfirmBehavior.Replace,
select = true, select = true,
}), }),
["<C-l>"] = cmp.mapping(function(fallback) ["<C-l>"] = cmp.mapping(function(_)
if require("luasnip").expand_or_jumpable() then if require("luasnip").expand_or_jumpable() then
require("luasnip").expand_or_jump() require("luasnip").expand_or_jump()
end end
@ -72,8 +104,9 @@ M.packer = function(use)
-- Visual presentation -- Visual presentation
formatting = { formatting = {
fields = { "abbr", "menu" }, fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item) format = function(entry, vim_item)
vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
vim_item.menu = ({ vim_item.menu = ({
luasnip = "[Snippet]", luasnip = "[Snippet]",
buffer = "[Buffer]", buffer = "[Buffer]",
@ -87,10 +120,10 @@ M.packer = function(use)
}, },
-- Docs -- Docs
window = { -- window = {
completion = cmp.config.window.bordered(), -- completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(),
}, -- },
-- Extra features -- Extra features
experimental = { experimental = {

View File

@ -24,7 +24,7 @@ M.packer = function(use)
settings = { settings = {
Lua = { Lua = {
diagnostics = { diagnostics = {
globals = { "vim" }, globals = { "vim", "hs" },
}, },
}, },
}, },

View File

@ -49,11 +49,11 @@ M.packer = function(use)
}, },
}) })
-- Move buffers -- Move buffers
vim.keymap.set("n", "L", ":BufferLineCycleNext<CR>") vim.keymap.set("n", "L", ":BufferLineCycleNext<CR>", { silent = true })
vim.keymap.set("n", "H", ":BufferLineCyclePrev<CR>") vim.keymap.set("n", "H", ":BufferLineCyclePrev<CR>", { silent = true })
-- Kill buffer -- Kill buffer
vim.keymap.set("n", "<Leader>x", " :Bdelete<CR>") vim.keymap.set("n", "<Leader>x", " :Bdelete<CR>", { silent = true })
-- Shift buffers -- Shift buffers
-- vim.keymap.set("n", "<C-L>", ":BufferLineMoveNext<CR>") -- vim.keymap.set("n", "<C-L>", ":BufferLineMoveNext<CR>")
@ -100,7 +100,7 @@ M.packer = function(use)
relativenumber = false, relativenumber = false,
}, },
}) })
vim.keymap.set("n", "<Leader>e", ":NvimTreeFindFileToggle<CR>") vim.keymap.set("n", "<Leader>e", ":NvimTreeFindFileToggle<CR>", { silent = true })
end, end,
}) })

View File

@ -37,7 +37,7 @@
if test "$argv[1]" = "offline" if test "$argv[1]" = "offline"
set option "--option substitute false" set option "--option substitute false"
end 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 -r "doas nixos-rebuild switch $option --flake ${config.dotfilesPath}"
commandline --function execute commandline --function execute
''; '';