From 8deffb3adb4c961c19f97ca8148c8121c203b96e Mon Sep 17 00:00:00 2001 From: matt1432 Date: Wed, 8 May 2024 23:04:16 -0400 Subject: [PATCH] feat(nvim): coc -> lspconfig --- common/home/neovim/coc.nix | 97 --------------------------- common/home/neovim/default.nix | 10 ++- common/home/neovim/langs/bash.nix | 5 -- common/home/neovim/langs/clang.nix | 2 - common/home/neovim/langs/default.nix | 46 ++++++++++++- common/home/neovim/langs/java.nix | 18 ----- common/home/neovim/langs/lua.nix | 21 ------ common/home/neovim/langs/markdown.nix | 12 ---- common/home/neovim/langs/nix.nix | 16 +++-- common/home/neovim/langs/python.nix | 1 - common/home/neovim/langs/web.nix | 27 -------- common/home/neovim/theme.nix | 2 +- 12 files changed, 64 insertions(+), 193 deletions(-) delete mode 100644 common/home/neovim/coc.nix diff --git a/common/home/neovim/coc.nix b/common/home/neovim/coc.nix deleted file mode 100644 index 54df1c1..0000000 --- a/common/home/neovim/coc.nix +++ /dev/null @@ -1,97 +0,0 @@ -{ - config, - pkgs, - lib, - ... -}: let - inherit (config.vars) neovimIde; - inherit (pkgs) vimPlugins; -in - lib.mkIf neovimIde { - programs = { - neovim = { - coc = { - enable = true; - settings = { - colors.enable = true; - coc.preferences.formatOnType = true; - diagnostic.checkCurrentLine = true; - inlayHint.enable = false; - }; - }; - - extraLuaConfig = - /* - lua - */ - '' - vim.api.nvim_create_user_command("Format", "call CocAction('format')", {}); - - -- Always show the signcolumn, otherwise it would shift the text each time - -- diagnostics appear/become resolved - vim.opt.signcolumn = 'yes'; - ''; - - plugins = [ - { - plugin = vimPlugins.coc-snippets; - type = "viml"; - config = - /* - vim - */ - '' - " use vscode keybinds for snippets completion - inoremap - \ coc#pum#visible() ? coc#_select_confirm() : - \ coc#expandableOrJumpable() ? "\=coc#rpc#request('doKeymap', ['snippets-expand-jump','''])\" : - \ CheckBackspace() ? "\" : - \ coc#refresh() - - function! CheckBackspace() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' - endfunction - - let g:coc_snippet_next = '' - ''; - } - - ## Fzf - vimPlugins.coc-fzf - - vimPlugins.coc-highlight - vimPlugins.coc-json - vimPlugins.coc-yaml - vimPlugins.coc-toml - - { - plugin = vimPlugins.nvim-autopairs; - type = "lua"; - config = - /* - lua - */ - '' - -- Auto indent when pressing Enter between brackets - local remap = vim.api.nvim_set_keymap - local npairs = require('nvim-autopairs') - npairs.setup({map_cr=false}) - - _G.MUtils= {} - - MUtils.completion_confirm=function() - if vim.fn["coc#pum#visible"]() ~= 0 then - return vim.fn["coc#pum#confirm"]() - else - return npairs.autopairs_cr() - end - end - - remap('i' , '','v:lua.MUtils.completion_confirm()', {expr = true , noremap = true}) - ''; - } - ]; - }; - }; - } diff --git a/common/home/neovim/default.nix b/common/home/neovim/default.nix index afc393d..c0e932c 100644 --- a/common/home/neovim/default.nix +++ b/common/home/neovim/default.nix @@ -6,7 +6,6 @@ inherit (pkgs) vimPlugins; in { imports = [ - ./coc.nix ./git.nix ./langs ./theme.nix @@ -35,8 +34,15 @@ in { vim.opt.undofile = true; vim.opt.undodir = '${config.xdg.cacheHome}/nvim/'; + -- Always show the signcolumn, otherwise it would shift + -- the text each time diagnostics appear/become resolved + vim.opt.signcolumn = 'yes'; + -- remove highlight on words - vim.keymap.set('n', '', ':noh', { noremap = true, silent = true }); + vim.keymap.set('n', '', ':noh', { + noremap = true, + silent = true, + }); ''; plugins = [ diff --git a/common/home/neovim/langs/bash.nix b/common/home/neovim/langs/bash.nix index eea239f..0da0df9 100644 --- a/common/home/neovim/langs/bash.nix +++ b/common/home/neovim/langs/bash.nix @@ -31,12 +31,7 @@ in }); ''; - coc.settings = { - bashIde.shellcheckPath = "${pkgs.shellcheck}/bin/shellcheck"; - }; - plugins = [ - vimPlugins.coc-sh ]; }; }; diff --git a/common/home/neovim/langs/clang.nix b/common/home/neovim/langs/clang.nix index 0dd2f2a..c6e2032 100644 --- a/common/home/neovim/langs/clang.nix +++ b/common/home/neovim/langs/clang.nix @@ -16,8 +16,6 @@ in ]; plugins = [ - vimPlugins.coc-clangd - vimPlugins.coc-cmake ]; }; }; diff --git a/common/home/neovim/langs/default.nix b/common/home/neovim/langs/default.nix index 27595bd..7ff687b 100644 --- a/common/home/neovim/langs/default.nix +++ b/common/home/neovim/langs/default.nix @@ -1,4 +1,12 @@ -{...}: { +{ + config, + lib, + pkgs, + ... +}: let + inherit (config.vars) neovimIde; + inherit (pkgs) vimPlugins; +in { imports = [ ./bash.nix ./clang.nix @@ -10,4 +18,40 @@ ./python.nix ./web.nix ]; + + programs = lib.mkIf neovimIde { + neovim = { + extraLuaConfig = lib.mkBefore + /* + lua + */ + '' + -- Start completion / snippet stuff + vim.g.coq_settings = { auto_start = true }; + + -- Add formatting cmd + vim.api.nvim_create_user_command( + 'Format', + function() + vim.lsp.buf.format({ async = true }); + end, + {} + ); + + -- Remove LSP highlighting to use Treesitter + 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 + end, + }); + ''; + plugins = [ + vimPlugins.nvim-lspconfig + vimPlugins.coq_nvim + vimPlugins.coq-artifacts + vimPlugins.coq-thirdparty + ]; + }; + }; } diff --git a/common/home/neovim/langs/java.nix b/common/home/neovim/langs/java.nix index 2efbae7..0499441 100644 --- a/common/home/neovim/langs/java.nix +++ b/common/home/neovim/langs/java.nix @@ -37,25 +37,7 @@ in }); ''; - coc.settings.java = { - maven.downloadSources = true; - eclipse.downloadSources = true; - - format.settings.url = "eclipse-formatter.xml"; - - jdt.ls = { - java.home = "${javaSdk}"; - statusIcons = { - "busy" = "Busy"; - "ready" = "OK"; - "warning" = "Warning"; - "error" = "Error"; - }; - }; - }; - plugins = [ - vimPlugins.coc-java ]; }; }; diff --git a/common/home/neovim/langs/lua.nix b/common/home/neovim/langs/lua.nix index b66134f..07e5906 100644 --- a/common/home/neovim/langs/lua.nix +++ b/common/home/neovim/langs/lua.nix @@ -10,29 +10,8 @@ in lib.mkIf neovimIde { programs = { neovim = { - coc.settings = { - Lua = { - misc.parameters = [ - "--metapath" - "~/.cache/sumneko_lua/meta" - "--logpath" - "~/.cache/sumneko_lua/log" - ]; - workspace.library = [ - "$\{3rd\}/luv/library" - ]; - }; - sumneko-lua = { - serverDir = "${pkgs.lua-language-server}/share/lua-language-server"; - enableNvimLuaDev = true; - }; - }; - plugins = [ - vimPlugins.coc-sumneko-lua vimPlugins.neodev-nvim - - vimPlugins.coc-vimlsp ]; }; }; diff --git a/common/home/neovim/langs/markdown.nix b/common/home/neovim/langs/markdown.nix index 6435065..0be9fc8 100644 --- a/common/home/neovim/langs/markdown.nix +++ b/common/home/neovim/langs/markdown.nix @@ -17,20 +17,8 @@ in lib.mkIf neovimIde { programs = { neovim = { - coc.settings = { - markdownlint.config = { - no-trailing-spaces = true; - no-multiple-blanks = false; - no-duplicate-heading = false; - line-length = { - tables = false; - }; - }; - }; - plugins = [ vimPlugins.markdown-preview-nvim - vimPlugins.coc-markdownlint { plugin = buildPlugin "easytables-nvim" vimplugin-easytables-src; type = "lua"; diff --git a/common/home/neovim/langs/nix.nix b/common/home/neovim/langs/nix.nix index a78cb8a..1791863 100644 --- a/common/home/neovim/langs/nix.nix +++ b/common/home/neovim/langs/nix.nix @@ -50,12 +50,16 @@ in nixdPkg ]; - coc.settings.languageserver = { - nix = { - command = "nixd"; - filetypes = ["nix"]; - }; - }; + extraLuaConfig = + /* + lua + */ + '' + local lsp = require('lspconfig') + + lsp.nixd.setup({}); + lsp.nixd.setup(require('coq').lsp_ensure_capabilities({})); + ''; }; }; } diff --git a/common/home/neovim/langs/python.nix b/common/home/neovim/langs/python.nix index 1d563fd..fd24cb8 100644 --- a/common/home/neovim/langs/python.nix +++ b/common/home/neovim/langs/python.nix @@ -17,7 +17,6 @@ in ]; plugins = [ - vimPlugins.coc-pyright ]; }; }; diff --git a/common/home/neovim/langs/web.nix b/common/home/neovim/langs/web.nix index acc541b..ce63fdd 100644 --- a/common/home/neovim/langs/web.nix +++ b/common/home/neovim/langs/web.nix @@ -2,13 +2,10 @@ config, pkgs, lib, - coc-stylelintplus, ... }: let inherit (config.vars) neovimIde; inherit (pkgs) vimPlugins; - - coc-stylelintplus-flake = coc-stylelintplus.packages.${pkgs.system}.default; in lib.mkIf neovimIde { programs = { @@ -42,31 +39,7 @@ in }); ''; - coc.settings = { - # ESLint - eslint = { - format.enable = true; - autoFixOnSave = true; - }; - - # Stylelint - stylelintplus = { - enable = true; - cssInJs = true; - autoFixOnSave = true; - autoFixOnFormat = true; - }; - css.validate = false; - less.validate = false; - scss.validate = false; - wxss.validate = false; - }; - plugins = [ - vimPlugins.coc-css - vimPlugins.coc-eslint - coc-stylelintplus-flake - vimPlugins.coc-tsserver ]; }; }; diff --git a/common/home/neovim/theme.nix b/common/home/neovim/theme.nix index 194d3db..bdfd997 100644 --- a/common/home/neovim/theme.nix +++ b/common/home/neovim/theme.nix @@ -95,7 +95,7 @@ in { globalstatus = true, }, sections = { - lualine_x = { 'g:coc_status', 'bo:filetype' }, + lualine_x = { 'bo:filetype' }, }, }); '';