Closed samhh closed 3 years ago
Might help:
set secure
set exrc
Then can have .nvimrc
in any project dir.
Or not?: https://vi.stackexchange.com/questions/5055/why-is-set-exrc-dangerous :confused:
This adds support for easily testing JS projects (and others that are pseudostandardly formatted): https://github.com/samhh/dotfiles/commit/1bb8a2ae6bb73b8cfa0928fa0729d1d53968da68
No errorformat/quickfix support yet.
I'd like vim-test to output failures to quickfix. Per here, it's useful to have vim-dispatch installed as it can be used to automatically determine the vim "compiler". Of note is that vim proper, but not neovim, includes a Jest compiler here that needs only minimal tweaking to theoretically be compatible. Alas, placing that into my dotfiles didn't work - either the pattern is outdated, or it's just not being picked up like the ftplugin directory is.
Probably worth trying jest-quickfix-reporter again, though installation is a bit of a pain.
Patch of my attempt:
diff --git a/home/.config/nvim/compiler/jest.vim b/home/.config/nvim/compiler/jest.vim
new file mode 100644
index 0000000..8005a87
--- /dev/null
+++ b/home/.config/nvim/compiler/jest.vim
@@ -0,0 +1,25 @@
+if exists("current_compiler")
+ finish
+endif
+let current_compiler = "jest"
+
+if exists(":CompilerSet") != 2
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+CompilerSet makeprg=./node_modules/.bin/jest\ --no-colors
+
+CompilerSet errorformat=%E\ \ ●\ %m,
+ \%Z\ %\\{4}%.%#Error:\ %f:\ %m\ (%l:%c):%\\=,
+ \%Z\ %\\{6}at\ %\\S%#\ (%f:%l:%c),
+ \%+C\ %\\{4}%\\w%.%#,
+ \%+C\ %\\{4}%[-+]%.%#,
+ \%-C%.%#,
+ \%-G%.%#
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
diff --git a/home/.config/nvim/ftplugin/typescript.vim b/home/.config/nvim/ftplugin/typescript.vim
index 3c312fb..5433fa5 100644
--- a/home/.config/nvim/ftplugin/typescript.vim
+++ b/home/.config/nvim/ftplugin/typescript.vim
@@ -1,6 +1,7 @@
setlocal foldenable
setlocal foldmethod=indent
setlocal makeprg=yarn
+let g:test#strategy = 'dispatch'
let g:test#javascript#jest#file_pattern = '\v(tests?\/.+|\.test\.)(j|t)sx?$'
let b:ale_fixers = ['prettier']
diff --git a/home/.config/nvim/plugins.vim b/home/.config/nvim/plugins.vim
index 117f25a..57b8c0b 100644
--- a/home/.config/nvim/plugins.vim
+++ b/home/.config/nvim/plugins.vim
@@ -14,6 +14,7 @@ call minpac#add('tpope/vim-commentary')
call minpac#add('tpope/vim-surround')
call minpac#add('rstacruz/vim-closer')
call minpac#add('moll/vim-bbye')
+call minpac#add('tpope/vim-dispatch')
call minpac#add('vim-test/vim-test')
call minpac#add('dense-analysis/ale')
call minpac#add('neoclide/coc.nvim', {'branch': 'release'})
If/when this is revisited this commit may need reverting: https://github.com/samhh/dotfiles/commit/f700f3df77f8f8fc7882b1d4a38664574c33e357
This patch, using estream, works with both Rust/Cargo (bukubrow-host) and Haskell/Cabal (tshm), but not with JavaScript/Jest (fp-ts-std).
Note that the estream binary was installed into the $PATH for this. Probably worth making an AUR package for it if I commit this:
diff --git a/home/.config/nvim/keybinds.vim b/home/.config/nvim/keybinds.vim
index 79d89e3..b2854ba 100644
--- a/home/.config/nvim/keybinds.vim
+++ b/home/.config/nvim/keybinds.vim
@@ -78,6 +78,16 @@ nnoremap <silent> <Leader>e <cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<
" Offer code actions
nnoremap <silent> <Leader>g <cmd>lua vim.lsp.buf.code_action()<cr>
+command -nargs=1 Async execute "AsyncRun bash -c '<args> |& estream'"
+nnoremap <Leader>a :Async
+nnoremap <Leader>A :AsyncStop<CR>
+
+command -nargs=1 Watch augroup watch | exe "autocmd! BufWritePost * <args>" | augroup END
+command NoWatch autocmd! watch
+
+nnoremap <Leader>w :Watch Async
+nnoremap <Leader>W :NoWatch<CR>
+
" Digraphs
dig NN 8469 " ℕ
dig fi 8718 " ∎
diff --git a/home/.config/nvim/plugins.vim b/home/.config/nvim/plugins.vim
index 500ef52..120912d 100644
--- a/home/.config/nvim/plugins.vim
+++ b/home/.config/nvim/plugins.vim
@@ -1,5 +1,8 @@
let g:ale_disable_lsp = 1
+set errorformat=%f\|%l\|%c,%f\|%l\|,%f\|\|
+let g:asyncrun_local = 0
+
packadd minpac
call minpac#init()
call minpac#add('k-takata/minpac', {'type': 'opt'})
@@ -14,6 +17,8 @@ call minpac#add('tpope/vim-commentary')
call minpac#add('tpope/vim-surround')
" call minpac#add('rstacruz/vim-closer')
call minpac#add('moll/vim-bbye')
+call minpac#add('skywind3000/asyncrun.vim')
+call minpac#add('joshmcguigan/estream')
call minpac#add('dense-analysis/ale')
call minpac#add('junegunn/fzf.vim')
call minpac#add('nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'})
Not Rust/Cargo yet, but here's Jest, Cabal build, and Cabal test:
diff --git a/home/.config/nvim/compiler/cabal_build.vim b/home/.config/nvim/compiler/cabal_build.vim
new file mode 100644
index 0000000..5548fa4
--- /dev/null
+++ b/home/.config/nvim/compiler/cabal_build.vim
@@ -0,0 +1,12 @@
+let current_compiler = "cabal_build"
+
+CompilerSet makeprg=cabal\ build
+
+CompilerSet efm =%W%f:%l:%c:\ Warning:%m
+CompilerSet efm+=%W%f:%l:%c:\ Warning:
+CompilerSet efm+=%E%f:%l:%c:%m
+CompilerSet efm+=%E%f:%l:%c:
+CompilerSet efm+=%C\ \ %#%m
+CompilerSet efm+=%-G%.%#
+CompilerSet efm+=%-G%.%#
+
diff --git a/home/.config/nvim/compiler/cabal_test.vim b/home/.config/nvim/compiler/cabal_test.vim
new file mode 100644
index 0000000..785715b
--- /dev/null
+++ b/home/.config/nvim/compiler/cabal_test.vim
@@ -0,0 +1,15 @@
+let current_compiler = "cabal_test"
+
+CompilerSet makeprg=cabal\ test
+
+"" In actuality this first line will always end with `error: %m` where the %m
+"" is optional, and with two %E one of the two possibilities will break
+"" depending upon their order... /shrug
+CompilerSet efm =%E%f:%l:%c:\ %m
+CompilerSet efm+=%Z\ %*[\ ]\|\ %*[\ ]^^%#
+CompilerSet efm+=%-G%[0-9]+\ \|%.%#
+CompilerSet efm+=%-G\ %*[\ ]\|
+CompilerSet efm+=%C\ %*[\ ]•\ %m
+CompilerSet efm+=%C%m
+CompilerSet efm+=%-G%.%#
+
diff --git a/home/.config/nvim/compiler/jest.vim b/home/.config/nvim/compiler/jest.vim
new file mode 100644
index 0000000..b9fe3b9
--- /dev/null
+++ b/home/.config/nvim/compiler/jest.vim
@@ -0,0 +1,12 @@
+let current_compiler = "jest"
+
+CompilerSet makeprg=./node_modules/.bin/jest\ --no-colors\ --collectCoverage=false
+
+CompilerSet efm =%E\ \ ●\ %m
+CompilerSet efm+=%Z\ %\\{4}%.%#Error:\ %f:\ %m\ (%l:%c):%\\=
+CompilerSet efm+=%Z\ %\\{6}at\ %\\S%#\ (%f:%l:%c),
+CompilerSet efm+=%+C\ %\\{4}%\\w%.%#
+CompilerSet efm+=%+C\ %\\{4}%[-+]%.%#
+CompilerSet efm+=%-C%.%#
+CompilerSet efm+=%-G%.%#
+
Errorformats are painful but I can't find anything better with broad enough support.
Some initial compilers, notably missing Rust/Cargo: https://github.com/samhh/dotfiles/commit/1fdeda9eaa39c579fd66cd15427be2cb8be492b4
Crucially made useful per-project with a secure exrc plugin: https://github.com/samhh/dotfiles/commit/aa8b593efca1d93fb36ce1abbd653cccc26a8ea4
Where there might for example be /path/to/project/.exrc
:
comp! jest
Challenge here is the differing formats per-project, even if each use the same underlying compiler.