Skip to content

Commit

Permalink
cwd: default to buffer's dir in stdin mode
Browse files Browse the repository at this point in the history
This is necessary at least with flake8, which does not use
`--stdin-display-name` to find its configuration.
  • Loading branch information
blueyed committed Feb 22, 2018
1 parent fecbba4 commit d719f58
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
23 changes: 14 additions & 9 deletions autoload/neomake.vim
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,19 @@ function! s:MakeJob(make_id, options) abort
\ 'buffer_output': a:options.maker.buffer_output,
\ }, 'keep')

let [cd_error, cwd, cd_back_cmd] = s:cd_to_jobs_cwd(jobinfo)
if !empty(cd_error)
throw printf("Neomake: %s: could not change to maker's cwd (%s): %s.",
\ maker.name, cwd, cd_error)
endif

let error = ''
let cd_back_cmd = ''
try
let error = ''
let jobinfo.argv = maker._get_argv(jobinfo)
call neomake#utils#hook('NeomakeJobInit', {'jobinfo': jobinfo})

" Change to job's cwd (after args, which may use uses_stdin to set it).
let [cd_error, cwd, cd_back_cmd] = s:cd_to_jobs_cwd(jobinfo)
if !empty(cd_error)
throw printf("Neomake: %s: could not change to maker's cwd (%s): %s.",
\ maker.name, cwd, cd_error)
endif

call neomake#utils#hook('NeomakeJobInit', {'jobinfo': jobinfo})
if s:async
call neomake#utils#LoudMessage(printf('Starting async job: %s.', string(jobinfo.argv)), jobinfo)
else
Expand Down Expand Up @@ -1702,12 +1704,15 @@ function! s:cd_to_jobs_cwd(jobinfo) abort
let cwd = expand(cwd, 1)
endif
let a:jobinfo.cwd = substitute(fnamemodify(cwd, ':p'), '[\/]$', '', '')
elseif get(a:jobinfo, 'uses_stdin', 0)
call neomake#utils#DebugMessage("Using buffer's directory for cwd with uses_stdin.", a:jobinfo)
let a:jobinfo.cwd = neomake#utils#fnamemodify(a:jobinfo.bufnr, ':h')
else
let a:jobinfo.cwd = s:make_info[a:jobinfo.make_id].cwd
endif
endif
let cwd = a:jobinfo.cwd
if empty(cwd)
if empty(cwd) || cwd ==# '.'
return ['', '', '']
endif
let cwd = substitute(fnamemodify(cwd, ':p'), '[\/]$', '', '')
Expand Down
3 changes: 2 additions & 1 deletion doc/neomake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ You can specify the default for this via |g:neomake_remove_invalid_entries|.

*neomake-makers-cwd*
The working directory of a maker defaults to the current working directory
of the make run (|getcwd()|).
of the make run (|getcwd()|), or the buffer's directory in case of using stdin
(see |neomake-makers-supports_stdin|).
The `cwd` property overrides this, and gets expanded in the context of the
current buffer. Special buffers (like fugitive blobs) get handled for values
starting with `%:` (typically used in this context), falling back to
Expand Down
19 changes: 19 additions & 0 deletions tests/stdin.vader
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Execute (stdin maker):
normal! ifile1.test:line1
normal! ofile1.test:line2
call neomake#Make(1, [maker])
AssertNeomakeMessage "Using buffer's directory for cwd with uses_stdin.", 3
if neomake#has_async_support()
AssertNeomakeMessage "Starting async job: ['cat', '-'].", 2
NeomakeTestsWaitForFinishedJobs
endif
AssertNeomakeMessage 'cwd: .', 3
AssertNeomakeMessage '\mstdout: unnamed_maker: [''file1.test:line1.*'
AssertEqual map(getloclist(0), 'v:val.text'), ['line1', 'line2']
bwipe!
Expand Down Expand Up @@ -167,3 +169,20 @@ Execute (stdin maker: uses neomake#utils#get_buffer_lines for buffer_lines):
CallNeomake 1, [maker]
AssertEqual map(getloclist(0), 'v:val.text'), ['', '']
bwipe

Execute (stdin maker: uses buffer's cwd by default):
let maker = {'exe': 'true', 'supports_stdin': 1}
let fname = tempname()
new
exe 'file '.fname

CallNeomake 1, [maker]
AssertNeomakeMessage printf('cwd: %s (changed).', fnamemodify(fname, ':h')), 3

CallNeomake 0, [extend(copy(maker), {'uses_filename': 1})]
AssertNeomakeMessage printf('cwd: %s (changed).', fnamemodify(fname, ':h')), 3

let maker.cwd = '.'
CallNeomake 1, [maker]
AssertNeomakeMessage printf('cwd: %s.', getcwd()), 3
bwipe

0 comments on commit d719f58

Please sign in to comment.