feat(nvim): switch to cmp and add package-info
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-07-28 02:54:34 -04:00
parent b09cceb259
commit d4d98bba73
12 changed files with 165 additions and 73 deletions

View file

@ -32,13 +32,15 @@ in {
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
require('lspconfig').bashls.setup(require('coq').lsp_ensure_capabilities({
require('lspconfig').bashls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
settings = {
bashIde = {
shellcheckPath = '${lib.getExe pkgs.shellcheck}',
},
},
}));
});
'';
};
};

View file

@ -25,17 +25,20 @@ in
});
local lsp = require('lspconfig');
local coq = require('coq');
lsp.cmake.setup(coq.lsp_ensure_capabilities({}));
lsp.cmake.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
});
lsp.clangd.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
lsp.clangd.setup(coq.lsp_ensure_capabilities({
handlers = require('lsp-status').extensions.clangd.setup(),
on_attach = function(_, bufnr)
require("clangd_extensions.inlay_hints").setup_autocmd()
require("clangd_extensions.inlay_hints").set_inlay_hints()
end,
}));
});
'';
plugins = [

View file

@ -6,6 +6,7 @@
}: let
inherit (config.vars) neovimIde;
inherit (pkgs) vimPlugins;
inherit (lib) fileContents;
in {
imports = [
./bash.nix
@ -51,7 +52,7 @@ in {
lsp_status.register_progress();
-- Remove LSP highlighting to use Treesitter
vim.api.nvim_create_autocmd("LspAttach", {
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id);
client.server_capabilities.semanticTokensProvider = nil;
@ -65,49 +66,37 @@ in {
});
require('lsp_lines').setup();
-- Autopairs with coq
local remap = vim.api.nvim_set_keymap
local npairs = require('nvim-autopairs')
npairs.setup({ map_bs = false, map_cr = false })
_G.MUtils= {}
MUtils.CR = function()
if vim.fn.pumvisible() ~= 0 then
if vim.fn.complete_info({ 'selected' }).selected ~= -1 then
return npairs.esc('<c-y>');
else
return npairs.esc('<c-e>') .. npairs.autopairs_cr();
end
else
return npairs.autopairs_cr();
end
end
remap('i', '<cr>', 'v:lua.MUtils.CR()', { expr = true, noremap = true });
MUtils.BS = function()
if vim.fn.pumvisible() ~= 0 and vim.fn.complete_info({ 'mode' }).mode == 'eval' then
return npairs.esc('<c-e>') .. npairs.autopairs_bs();
else
return npairs.autopairs_bs();
end
end
remap('i', '<bs>', 'v:lua.MUtils.BS()', { expr = true, noremap = true });
'';
plugins = [
vimPlugins.nvim-lspconfig
plugins =
(with vimPlugins; [
nvim-lspconfig
lsp-status-nvim
lsp_lines-nvim
vimPlugins.coq_nvim
vimPlugins.coq-artifacts
vimPlugins.coq-thirdparty
cmp-buffer
cmp-nvim-lsp
cmp-path
cmp-spell
cmp-treesitter
cmp-vsnip
vim-vsnip
friendly-snippets
])
++ [
{
plugin = vimPlugins.nvim-cmp;
type = "lua";
config = fileContents ../plugins/cmp.lua;
}
vimPlugins.nvim-autopairs
vimPlugins.lsp-status-nvim
vimPlugins.lsp_lines-nvim
{
plugin = vimPlugins.nvim-autopairs;
type = "lua";
config =
# lua
"require('nvim-autopairs').setup({})";
}
];
};
};

View file

@ -45,7 +45,9 @@ in
''
--
local startJdtls = function()
local config = require('coq').lsp_ensure_capabilities({
local config = {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
cmd = { '${lib.getExe pkgs.jdt-language-server}' },
root_dir = vim.fs.dirname(vim.fs.find(
{ 'gradlew', '.git', 'mvnw', 'pom.xml' },
@ -64,7 +66,7 @@ in
},
},
},
});
};
require('jdtls').start_or_attach(config);
end

View file

@ -27,11 +27,14 @@ in
});
local lsp = require('lspconfig');
local coq = require('coq');
lsp.jsonls.setup(coq.lsp_ensure_capabilities({}));
lsp.jsonls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
});
lsp.yamlls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
lsp.yamlls.setup(coq.lsp_ensure_capabilities({
settings = {
yaml = {
schemas = {
@ -41,7 +44,7 @@ in
},
},
},
}));
});
'';
};
};

View file

@ -38,8 +38,9 @@ in
end,
});
require('lspconfig').lua_ls.setup(
require('coq').lsp_ensure_capabilities({}));
require('lspconfig').lua_ls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
});
'';
}
];

View file

@ -26,9 +26,10 @@ in
# lua
''
local lsp = require('lspconfig');
local coq = require('coq');
lsp.texlab.setup(coq.lsp_ensure_capabilities({
lsp.texlab.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
settings = {
texlab = {
formatterLineLength = 100,
@ -39,7 +40,7 @@ in
},
},
},
}));
});
'';
plugins = [

View file

@ -52,7 +52,9 @@ in
extraLuaConfig =
# lua
''
require('lspconfig').nixd.setup(require('coq').lsp_ensure_capabilities({
require('lspconfig').nixd.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
filetypes = { 'nix', 'in.nix' },
settings = {
nixd = {
@ -62,7 +64,7 @@ in
},
},
},
}));
});
'';
};
};

View file

@ -18,8 +18,9 @@ in
extraLuaConfig =
# lua
''
require('lspconfig').basedpyright.setup(
require('coq').lsp_ensure_capabilities({}));
require('lspconfig').basedpyright.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
});
'';
};
};

View file

@ -24,10 +24,9 @@ in
command = 'setlocal ts=4 sw=4 sts=0 expandtab',
});
local lsp = require('lspconfig');
local coq = require('coq');
lsp.rust_analyzer.setup(coq.lsp_ensure_capabilities({}));
require('lspconfig').rust_analyzer.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
});
'';
};
};

View file

@ -42,10 +42,11 @@ in
});
local lsp = require('lspconfig');
local coq = require('coq');
local tsserver = require('typescript-tools');
tsserver.setup(coq.lsp_ensure_capabilities({
tsserver.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
handlers = {
-- format error code with better error message
['textDocument/publishDiagnostics'] = function(err, result, ctx, config)
@ -53,9 +54,11 @@ in
vim.lsp.diagnostic.on_publish_diagnostics(err, result, ctx, config)
end,
},
}));
});
lsp.eslint.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
lsp.eslint.setup(coq.lsp_ensure_capabilities({
-- auto-save
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd('BufWritePre', {
@ -63,9 +66,11 @@ in
command = 'EslintFixAll',
});
end,
}));
});
lsp.cssls.setup({
capabilities = require('cmp_nvim_lsp').default_capabilities(),
lsp.cssls.setup(coq.lsp_ensure_capabilities({
settings = {
css = {
validate = false,
@ -77,12 +82,33 @@ in
validate = false,
},
},
}));
});
'';
plugins = [
vimPlugins.typescript-tools-nvim
(buildPlugin "ts-error-translator" vimplugin-ts-error-translator-src)
{
plugin = vimPlugins.package-info-nvim;
type = "lua";
config =
# lua
''
local packageInfo = require('package-info');
packageInfo.setup({
hide_up_to_date = true,
package_manager = 'npm',
});
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
pattern = { 'package.json' },
callback = function()
packageInfo.show({ force = true });
end,
});
'';
}
];
};
};

View file

@ -0,0 +1,63 @@
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0));
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil;
end;
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true);
end;
local cmp = require('cmp');
-- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
cmp.setup({
sources = {
{ name = 'nvim_lsp' },
{ name = 'cmp_tabnine' },
{ name = 'treesitter' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'vsnip' },
},
snippet = {
expand = function(args)
vim.fn['vsnip#anonymous'](args.body);
end,
},
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item();
elseif vim.fn['vsnip#available'](1) == 1 then
feedkey('<Plug>(vsnip-expand-or-jump)', '');
elseif has_words_before() then
cmp.complete();
else
fallback();
end;
end, {
'i',
's',
}),
['<S-Tab>'] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item();
elseif vim.fn['vsnip#jumpable'](-1) == 1 then
feedkey('<Plug>(vsnip-jump-prev)', '');
end;
end, {
'i',
's',
}),
},
});