From a6c2877b0df2ce58b407a41965556a76507617f0 Mon Sep 17 00:00:00 2001 From: Felix Tenley Date: Thu, 27 Aug 2020 13:33:29 +0200 Subject: [PATCH] feat: replace coc-nvim with nvim-lsp --- home/editors/coc.vim | 105 ---------------------- home/editors/lsp.vim | 173 ++++++++++++++++++++++++++++++++++--- home/editors/neovim.nix | 42 +++------ home/editors/omnisharp.nix | 15 ++++ 4 files changed, 188 insertions(+), 147 deletions(-) delete mode 100644 home/editors/coc.vim diff --git a/home/editors/coc.vim b/home/editors/coc.vim deleted file mode 100644 index 13950dd..0000000 --- a/home/editors/coc.vim +++ /dev/null @@ -1,105 +0,0 @@ -" You will have bad experience for diagnostic messages when it's default 4000. -set updatetime=300 - -" don't give |ins-completion-menu| messages. -set shortmess+=c - -" Use tab for trigger completion with characters ahead and navigate. -" Use command ':verbose imap ' to make sure tab is not mapped by other plugin. -inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : - \ coc#refresh() -inoremap pumvisible() ? "\" : "\" - -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Use to trigger completion. -inoremap coc#refresh() - -" Use to confirm completion, `u` means break undo chain at current position. -inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" - -" Use `[g` and `]g` to navigate diagnostics -nmap [g (coc-diagnostic-prev) -nmap ]g (coc-diagnostic-next) - -" Remap keys for gotos -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -" Use K to show documentation in preview window -nnoremap K :call show_documentation() - -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - else - call CocAction('doHover') - endif -endfunction - -" Highlight symbol under cursor on CursorHold -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Remap for rename current word -nmap rn (coc-rename) - -" Remap for format selected region -xmap f (coc-format-selected) -nmap f (coc-format-selected) - -augroup mygroup - autocmd! - " Setup formatexpr specified filetype(s). - autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') - " Update signature help on jump placeholder - autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') -augroup end - -" Remap for do codeAction of selected region, ex: `aap` for current paragraph -xmap a (coc-codeaction-selected) -nmap a (coc-codeaction-selected) - -" Remap for do codeAction of current line -nmap ac (coc-codeaction) -" Fix autofix problem of current line -nmap qf (coc-fix-current) - -" Create mappings for function text object, requires document symbols feature of languageserver. -xmap if (coc-funcobj-i) -xmap af (coc-funcobj-a) -omap if (coc-funcobj-i) -omap af (coc-funcobj-a) - -" Use `:Format` to format current buffer -command! -nargs=0 Format :call CocAction('format') - -" Use `:Fold` to fold current buffer -command! -nargs=? Fold :call CocAction('fold', ) - -" use `:OR` for organize import of current buffer -command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') - -" Using CocList -" Show all diagnostics -nnoremap a :CocList diagnostics -" Manage extensions -nnoremap e :CocList extensions -" Show commands -nnoremap c :CocList commands -" Find symbol of current document -nnoremap o :CocList outline -" Search workspace symbols -nnoremap s :CocList -I symbols -" Do default action for next item. -nnoremap j :CocNext -" Do default action for previous item. -nnoremap k :CocPrev -" Resume latest coc list -nnoremap p :CocListResume diff --git a/home/editors/lsp.vim b/home/editors/lsp.vim index bd59e4d..9cb420f 100644 --- a/home/editors/lsp.vim +++ b/home/editors/lsp.vim @@ -3,14 +3,12 @@ set completeopt=menu,preview,menuone,noinsert set omnifunc=v:lua.vim.lsp.omnifunc let g:deoplete#enable_at_startup = 1 -" let g:deoplete#auto_refresh_delay = 10 " TODO disable it again if it doesn't make a difference let g:deoplete#smart_case = 1 -let g:deoplete#min_pattern_length = 1 " Use to trigger completion. inoremap deoplete#manual_complete() -"Autocomplete and cycle from top-to-bottom of suggestions using . +" Autocomplete and cycle from top-to-bottom of suggestions using . inoremap pumvisible() ? "\" : "\" " : completion. @@ -25,19 +23,170 @@ function! s:check_back_space() abort return !col || getline('.')[col - 1] =~# '\s' endfunction -" these will likely interfere with coc.vim maps -nnoremap gd lua vim.lsp.buf.declaration() -nnoremap lua vim.lsp.buf.definition() -nnoremap K lua vim.lsp.buf.hover() -nnoremap gD lua vim.lsp.buf.implementation() -nnoremap lua vim.lsp.buf.signature_help() -nnoremap 1gD lua vim.lsp.buf.type_definition() -nnoremap gr lua vim.lsp.buf.references() -nnoremap g0 lua vim.lsp.buf.document_symbol() +" maps +nnoremap gd lua vim.lsp.buf.declaration() +nnoremap lua vim.lsp.buf.definition() +nnoremap K lua vim.lsp.buf.hover() +nnoremap gD lua vim.lsp.buf.implementation() +nnoremap lua vim.lsp.buf.signature_help() +nnoremap 1gD lua vim.lsp.buf.type_definition() +nnoremap gr lua vim.lsp.buf.references() +nnoremap g0 lua vim.lsp.buf.document_symbol() +nnoremap f lua vim.lsp.buf.formatting() +nnoremap a lua vim.lsp.buf.code_action() +nnoremap r lua vim.lsp.buf.rename() " nvim-lsp config packloadall " https://github.com/neovim/neovim/issues/11407 lua << EOF local nvim_lsp = require'nvim_lsp' +local configs = require'nvim_lsp/configs' +local util = require'nvim_lsp/util' + +-- remove once omnisharp support is merged +configs.omnisharp_lsp = { + default_config = { + cmd = {"omnisharp","-lsp"}; + filetypes = {"cs"}; + root_dir = util.root_pattern("*.csproj", "*.sln", ".git"); + settings = {}; + }; +} + nvim_lsp.tsserver.setup{} +nvim_lsp.omnisharp_lsp.setup{} + +-- TODO install globally or use :LspInstall +nvim_lsp.bashls.setup{} +nvim_lsp.html.setup{} +nvim_lsp.cssls.setup{} +nvim_lsp.yamlls.setup{} +nvim_lsp.jsonls.setup{} +nvim_lsp.vimls.setup{} +nvim_lsp.dockerls.setup{} + +-- based on: https://github.com/mikew/vimrc/blob/master/src/nvim/coc-settings.json +nvim_lsp.diagnosticls.setup{ + filetypes = { + "javascript", + "javascript.jsx", + "javascriptreact", + "typescript", + "typescript.jsx", + "typescriptreact", + "json", + "yaml", + "markdown", + "html", + "css" + }; + init_options = { + linters = { + eslint = { + command = "eslint"; + args = { + "--stdin", + "--stdin-filename", + "%filepath", + "--format", + "json" + }; + rootPatterns = {".git"}; + debounce = 50; + sourceName = "eslint"; + parseJson = { + errorsRoot = "[0].messages"; + line = "line"; + column = "column"; + endLine = "endLine"; + endColumn = "endColumn"; + message = "${message} [${ruleId}]"; + security = "severity"; + }; + securities = { + ["2"] = "error"; + ["1"] = "warning"; + }; + }; + stylelint = { + command = "stylelint"; + args = { + "--stdin", + "--formatter", + "json", + "--file", + "%filepath" + }; + rootPatterns = {".git"}; + debounce = 50; + sourceName = "stylelint"; + parseJson = { + errorsRoot = "[0].warnings"; + line = "line"; + column = "column"; + message = "${text}"; + security = "severity"; + }; + securities = { + error = "error"; + warning = "warning"; + }; + }; + }; + filetypes = { + javascript = {"eslint"}; + ["javascript.jsx"] = {"eslint"}; + javascriptreact = {"eslint"}; + typescript = {"eslint"}; + ["typescript.jsx"] = {"eslint"}; + typescriptreact = {"eslint"}; + css = {"stylelint"}; + }; + formatters = { + eslint = { + command = "eslint"; + args = { + "--fix", + "%file" + }; + rootPatterns = {".git"}; + isStdout = 1; + doesWriteToFile = 1; + }; + stylelint = { + command = "stylelint"; + args = { + "--stdin", + "--fix", + "--file", + "%filepath" + }; + rootPatterns = {".git"}; + }; + prettier = { + command = "prettier"; + args = { + "--stdin", + "--stdin-filepath", + "%filepath" + }; + rootPatterns = {".git"}; + }; + }; + formatFiletypes = { + javascript = {"eslint"}; + ["javascript.jsx"] = {"eslint"}; + javascriptreact = {"eslint"}; + typescript = {"eslint"}; + ["typescript.jsx"] = {"eslint"}; + typescriptreact = {"eslint"}; + json = {"prettier"}; + yaml = {"prettier"}; + markdown = {"prettier"}; + html = {"prettier"}; + css = {"stylelint"}; + }; + }; +} + EOF diff --git a/home/editors/neovim.nix b/home/editors/neovim.nix index fb2fb58..aa3eee2 100644 --- a/home/editors/neovim.nix +++ b/home/editors/neovim.nix @@ -2,12 +2,12 @@ let neovim-unwrapped = pkgs.neovim-unwrapped.overrideAttrs (oldAttrs: rec { - version = "2020-08-13"; + version = "2020-08-26"; src = pkgs.fetchFromGitHub { owner = "neovim"; repo = "neovim"; - rev = "6a8dcfab4b2bada9c68379ee17235974fa8ad411"; - sha256 = "1hlfcxjmp3xihqb5z90bih4j2lvzypgdbqh7w3y3qvxgsaz07bzv"; + rev = "91109ffda23d0ce61cec245b1f4ffb99e7591b62"; + sha256 = "1rq7j6r1hfkxwmbf688fkwy9j86zam8rywy4796fwkb3imxw64rs"; }; nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.utf8proc @@ -35,14 +35,14 @@ let rev = "fc9d94ef006e082596c2e8724eb3f1c92ff203c7"; sha256 = "1byji4p0xigyp8y71s00fs2vrhgz3xkf51mmyz489pp52c7nfx4v"; }; + # required until omnisharp support is merged + patches = with pkgs; [ + (fetchpatch { url = "https://patch-diff.githubusercontent.com/raw/neovim/nvim-lsp/pull/296.patch"; + sha256 = "084ryddj0j7jialx91z6iqawf4s2hhn5d7wpd19cg1sl18vlyzp4"; }) + ]; }; in { - home.packages = with pkgs; [ - # nodejs-12_x - # haskellPackages.ghcide - ]; - programs.neovim = { enable = true; package = neovim-unwrapped; @@ -71,39 +71,21 @@ in argtextobj-vim nvim-lsp + + # might require :UpdateRemotePlugins deoplete-nvim deoplete-lsp vim-orgmode vim-nix - - coc-nvim - coc-pairs - coc-emmet - coc-snippets - coc-highlight - coc-html - coc-css - coc-tsserver - coc-json - coc-yaml - coc-eslint - coc-stylelint - coc-prettier - # not yet in nixpkgs: - # coc-angular - # coc-omnisharp # not really maintained - - ale # only used for omnisharp-vim - omnisharp-vim ]; extraConfig = with builtins; readFile ./init.vim + readFile ./vim-surround-fix.vim + readFile ./which-key.vim + - readFile ./coc.vim; - # readFile ./lsp.vim; + readFile ./lsp.vim; withNodeJs = true; + withPython = false; }; xdg.configFile."nvim/coc-settings.json".source = ./coc-settings.json; diff --git a/home/editors/omnisharp.nix b/home/editors/omnisharp.nix index 1e4228d..f1e9396 100644 --- a/home/editors/omnisharp.nix +++ b/home/editors/omnisharp.nix @@ -1,13 +1,28 @@ { config, pkgs, ... }: +let + omnisharp-roslyn = pkgs.omnisharp-roslyn.overrideAttrs(oldAttrs: rec { + pname = "omnisharp-roslyn"; + version = "1.37.0"; + + src = pkgs.fetchurl { + url = "https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v${version}/omnisharp-mono.tar.gz"; + sha256 = "1lbwfx1nn1bjgbm8pjmr89kbvf69lwj237np3m52r3qw7pfrmqc9"; + }; + }); +in { home.packages = with pkgs; [ omnisharp-roslyn ]; + # UseLegacySdkResolver: true is currently required home.file.".omnisharp/omnisharp.json" = { text = '' { + "MsBuild": { + "UseLegacySdkResolver": true + }, "FormattingOptions": { "EnableEditorConfigSupport": true },