diff --git a/common/home/neovim/langs/bash.nix b/common/home/neovim/langs/bash.nix index ddd21164..e34bbdd6 100644 --- a/common/home/neovim/langs/bash.nix +++ b/common/home/neovim/langs/bash.nix @@ -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}', }, }, - })); + }); ''; }; }; diff --git a/common/home/neovim/langs/clang.nix b/common/home/neovim/langs/clang.nix index bf635a50..23839fe2 100644 --- a/common/home/neovim/langs/clang.nix +++ b/common/home/neovim/langs/clang.nix @@ -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 = [ diff --git a/common/home/neovim/langs/default.nix b/common/home/neovim/langs/default.nix index 59ba4f72..4b7ee13d 100644 --- a/common/home/neovim/langs/default.nix +++ b/common/home/neovim/langs/default.nix @@ -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,50 +66,38 @@ 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(''); - else - return npairs.esc('') .. npairs.autopairs_cr(); - end - else - return npairs.autopairs_cr(); - end - end - remap('i', '', '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('') .. npairs.autopairs_bs(); - else - return npairs.autopairs_bs(); - end - end - remap('i', '', '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({})"; + } + ]; }; }; } diff --git a/common/home/neovim/langs/java.nix b/common/home/neovim/langs/java.nix index 45c0498c..1f4aa791 100644 --- a/common/home/neovim/langs/java.nix +++ b/common/home/neovim/langs/java.nix @@ -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 diff --git a/common/home/neovim/langs/json.nix b/common/home/neovim/langs/json.nix index 58169694..9429af4a 100644 --- a/common/home/neovim/langs/json.nix +++ b/common/home/neovim/langs/json.nix @@ -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 }, }, }, - })); + }); ''; }; }; diff --git a/common/home/neovim/langs/lua.nix b/common/home/neovim/langs/lua.nix index 09296e03..f0783e3f 100644 --- a/common/home/neovim/langs/lua.nix +++ b/common/home/neovim/langs/lua.nix @@ -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(), + }); ''; } ]; diff --git a/common/home/neovim/langs/markdown.nix b/common/home/neovim/langs/markdown.nix index 49d5df51..b104d856 100644 --- a/common/home/neovim/langs/markdown.nix +++ b/common/home/neovim/langs/markdown.nix @@ -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 = [ diff --git a/common/home/neovim/langs/nix.nix b/common/home/neovim/langs/nix.nix index 3b380b83..f848937b 100644 --- a/common/home/neovim/langs/nix.nix +++ b/common/home/neovim/langs/nix.nix @@ -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 }, }, }, - })); + }); ''; }; }; diff --git a/common/home/neovim/langs/python.nix b/common/home/neovim/langs/python.nix index 190c7a39..1fb9a035 100644 --- a/common/home/neovim/langs/python.nix +++ b/common/home/neovim/langs/python.nix @@ -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(), + }); ''; }; }; diff --git a/common/home/neovim/langs/rust.nix b/common/home/neovim/langs/rust.nix index 15ee5834..393714d8 100644 --- a/common/home/neovim/langs/rust.nix +++ b/common/home/neovim/langs/rust.nix @@ -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(), + }); ''; }; }; diff --git a/common/home/neovim/langs/web.nix b/common/home/neovim/langs/web.nix index 15b04bea..24d9c04c 100644 --- a/common/home/neovim/langs/web.nix +++ b/common/home/neovim/langs/web.nix @@ -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, + }); + ''; + } ]; }; }; diff --git a/common/home/neovim/plugins/cmp.lua b/common/home/neovim/plugins/cmp.lua new file mode 100644 index 00000000..1f903100 --- /dev/null +++ b/common/home/neovim/plugins/cmp.lua @@ -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 = { + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item(); + elseif vim.fn['vsnip#available'](1) == 1 then + feedkey('(vsnip-expand-or-jump)', ''); + elseif has_words_before() then + cmp.complete(); + else + fallback(); + end; + end, { + 'i', + 's', + }), + + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item(); + elseif vim.fn['vsnip#jumpable'](-1) == 1 then + feedkey('(vsnip-jump-prev)', ''); + end; + end, { + 'i', + 's', + }), + }, +});