vim-syntastic / syntastic

Syntax checking hacks for vim
Do What The F*ck You Want To Public License
11.31k stars 1.14k forks source link

Default fname option does not resolve to current file name #2192

Closed palsivertsen closed 6 years ago

palsivertsen commented 6 years ago

According to syntastic_<filetype>_<checker>_<option> the fname option is automatically set to the name of the current file. When running checkers with syntastic_debug = 1 I see that the fname option is set to the directory of the file, instead of the filename itself. See line 9:

syntastic: 18.479733: g:syntastic_version = '3.9.0-9 (Vim 704, Linux)'
syntastic: 18.480149: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1',
 &shelltemp = 1, &shellxquote = '', &autochdir = 0, &shellxescape = ''
syntastic: 18.481300: UpdateErrors (auto): default checkers
syntastic: 18.481832: CacheErrors: default checkers
syntastic: 18.482822: g:syntastic_aggregate_errors = 0
syntastic: 18.483018: getcwd() = '/home/pal/projects/go/src/test'
syntastic: 18.483501: CacheErrors: Invoking checker: go/gometalinter
syntastic: 18.484045: SyntasticMake: called with options: {'errorformat': '%f:%l:%c:%trror: %m,%f:%l:%c:%tarning: %m,%f:%l::%trror: %m,
%f:%l::%tarning: %m', 'makeprg': 'gometalinter --fast /home/pal/projects/go/src/test', 'returns': [0, 1]}
syntastic: 18.666698: system: command run in 0.182250s
syntastic: 18.683883: getLocList: checker go/gometalinter returned 1
syntastic: 18.684139: getLocList: checker go/gometalinter run in 0.200532s
lcd047 commented 6 years ago

According to syntastic_<filetype>_<checker>_<option> the fname option is automatically set to the name of the current file.

No. What the manual says is that you can override the default fname by setting the variable syntastic_<filetype>_<checker>_<option>. Most of the time the variable itself is left unset by syntastic.

When running checkers with syntastic_debug = 1 I see that the fname option is set to the directory of the file, instead of the filename itself.

Yes, some checkers expect a directory name instead of a filename. gometalinter is one of these checkers. Is there a problem you're actually trying to solve?

palsivertsen commented 6 years ago

No. What the manual says is that you can override the default fname by setting the variable syntastic_

Oh, sorry, my mistake

Is there a problem you're actually trying to solve?

I'm running gometalinter using test and testify. Since these linters is slow, I was hoping to only run linters on the current file and the associated test file.

lcd047 commented 6 years ago

I'm running gometalinter using test and testify. Since these linters is slow, I was hoping to only run linters on the current file and the associated test file.

Well you could set fname to point to the current file, but IIRC gometalinter won't accept that. In the mean time there are better options: the recently added checker golangci_lint is supposed to be faster than gometalinter; Vim plugin vim-go has better support for go than syntastic and supports gometalinter; and Vim plugin ale can run checks asynchronously.

palsivertsen commented 6 years ago

Thanks! I'll check it out

gometalinter accepts files as far as I can see. If anyone is interested I got fname working with the following autocmd:

autocmd BufEnter * silent! let g:syntastic_go_gometalinter_fname = split(globpath(expand("%:h"), expand("%:t:r") . "*"))

It will set the g:syntastic_go_gometalinter_fname variable to the current file and associated test file (if exists)

lcd047 commented 6 years ago

This sets g:syntastic_go_gometalinter_fname for all files in the project. You probably want to use b:... instead of g:..., and restrict the autocmd pattern to test files. You also probably want to set do it only once. But this is general Vim-fu, not directly related to syntastic.