From f9cdfb390fee74614d0d1cb8d4c6dcc2a021a965 Mon Sep 17 00:00:00 2001 From: Haak Saxberg Date: Tue, 24 Aug 2021 00:25:17 +0000 Subject: [PATCH] refinement of LSP options and vim packages for TS/JS development --- nix/home.nix | 41 +++++++++++++-------- nix/vim/init.vim | 8 +---- nix/vim/nvim-lspconfig.lua | 74 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 99 insertions(+), 24 deletions(-) diff --git a/nix/home.nix b/nix/home.nix index 0847a04..d975660 100644 --- a/nix/home.nix +++ b/nix/home.nix @@ -38,6 +38,15 @@ let }; }; + vim-catppuccino = pkgs.vimUtils.buildVimPlugin { + name = "vim-catppuccino"; + src = pkgs.fetchFromGitHub { + owner = "Pocco81"; + repo = "Catppuccino.nvim"; + rev = "014d8575acdd19ecef4ecb12fc82a2e21794b548"; + sha256 = "0i0p21jkrx99n3dnm5xvnw8n963c67l4lgl4iwngz0psdzwxphkw"; + }; + }; in { home.packages = with pkgs; [ @@ -127,7 +136,7 @@ in plugins = with pkgs.vimPlugins; [ vim-sensible vim-startify - papercolor-theme + vim-catppuccino vim-elixir alchemist-vim @@ -150,7 +159,13 @@ in ''; } vim-signify - vim-indent-guides + { + plugin = vim-indent-guides; + config = '' + let g:indent_guides_enable_on_vim_startup = 1 + let g:indent_guides_start_level = 2 + ''; + } vim-surround fugitive { @@ -165,19 +180,6 @@ in } vinegar undotree - { - plugin = vim-test; - config = '' - nmap t :TestNearest - nmap T :TestFile - nmap a :TestSuite - nmap l :TestLast - nmap g :TestVisit - let test#strategy = "neovim" - ''; - } - fzf-vim - fzfWrapper { plugin = nvim-compe; config = '' @@ -226,6 +228,15 @@ in EOF ''; } + { + plugin = telescope-nvim; + config = '' + nnoremap ff lua require('telescope.builtin').find_files() + nnoremap fg lua require('telescope.builtin').live_grep() + nnoremap fb lua require('telescope.builtin').buffers() + nnoremap fh lua require('telescope.builtin').help_tags() + ''; + } ]; extraConfig = readFile ./vim/init.vim; diff --git a/nix/vim/init.vim b/nix/vim/init.vim index 2d8e4e4..d9fac86 100644 --- a/nix/vim/init.vim +++ b/nix/vim/init.vim @@ -1,22 +1,16 @@ filetype plugin indent on -nnoremap t :call LanguageClient_textDocument_hover() -nnoremap y :call LanguageClient_textDocument_definition() - " Indent guides -let g:indent_guides_enable_on_vim_startup = 1 -let g:indent_guides_start_level = 2 " let netrw look like NERDTree let g:netrw_liststyle = 3 -let mapleader="," set nobackup set noswapfile set pastetoggle= set nowrap set background=dark -colorscheme PaperColor +colorscheme catppuccino set nocompatible set number relativenumber diff --git a/nix/vim/nvim-lspconfig.lua b/nix/vim/nvim-lspconfig.lua index 91e7378..ced4cb5 100644 --- a/nix/vim/nvim-lspconfig.lua +++ b/nix/vim/nvim-lspconfig.lua @@ -53,7 +53,77 @@ local on_attach = function(client, bufnr) end nvim_lsp.diagnosticls.setup { - on_attach = on_attach + on_attach = on_attach; + filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'css', 'scss', 'markdown', 'pandoc' }, + init_options = { + linters = { + eslint = { + command = 'eslint', + rootPatterns = { '.git' }, + debounce = 100, + args = { '--stdin', '--stdin-filename', '%filepath', '--format', 'json' }, + sourceName = 'eslint', + parseJson = { + errorsRoot = '[0].messages', + line = 'line', + column = 'column', + endLine = 'endLine', + endColumn = 'endColumn', + message = '[eslint] ${message} [${ruleId}]', + security = 'severity' + }, + securities = { + [2] = 'error', + [1] = 'warning' + } + }, + markdownlint = { + command = 'markdownlint', + rootPatterns = { '.git' }, + isStderr = true, + debounce = 100, + args = { '--stdin' }, + offsetLine = 0, + offsetColumn = 0, + sourceName = 'markdownlint', + securities = { + undefined = 'hint' + }, + formatLines = 1, + formatPattern = { + '^.*:(\\d+)\\s+(.*)$', + { + line = 1, + column = -1, + message = 2, + } + } + } + }, + filetypes = { + javascript = 'eslint', + javascriptreact = 'eslint', + typescript = 'eslint', + typescriptreact = 'eslint', + markdown = 'markdownlint', + pandoc = 'markdownlint' + }, + formatters = { + prettier = { + command = 'prettier', + args = { '--stdin-filepath', '%filename' } + } + }, + formatFiletypes = { + css = 'prettier', + javascript = 'prettier', + javascriptreact = 'prettier', + json = 'prettier', + scss = 'prettier', + typescript = 'prettier', + typescriptreact = 'prettier' + } + } } nvim_lsp.elmls.setup{ @@ -61,7 +131,7 @@ nvim_lsp.elmls.setup{ } nvim_lsp.tsserver.setup { on_attach = function(client) - -- Avoid conflict with prettier + -- Avoid conflict with prettier and eslint client.resolved_capabilities.document_formatting = false on_attach(client) end