2018-07-27 20:50:59 +00:00
|
|
|
" Author: Fred Emmott <fe@fb.com>
|
|
|
|
" Description: Hack support via `hhast lsp`
|
|
|
|
|
|
|
|
call ale#Set('hack_hhast_executable', 'vendor/bin/hhast-lint')
|
|
|
|
|
|
|
|
function! ale_linters#hack#hhast#GetProjectRoot(buffer) abort
|
2018-08-02 19:59:04 +00:00
|
|
|
" Find the hack root, then figure out if it's also an HHAST root.
|
|
|
|
" Don't try to use lint configurations from vendor/foo/bar/hhast-lint.json
|
|
|
|
let l:hhconfig = ale#path#FindNearestFile(a:buffer, '.hhconfig')
|
2018-08-02 18:44:17 +00:00
|
|
|
|
2018-08-02 19:59:04 +00:00
|
|
|
if empty(l:hhconfig)
|
2018-07-27 20:50:59 +00:00
|
|
|
return ''
|
|
|
|
endif
|
2018-08-02 18:44:17 +00:00
|
|
|
|
2018-08-02 19:59:04 +00:00
|
|
|
let l:root = fnamemodify(l:hhconfig, ':h')
|
2018-07-27 20:50:59 +00:00
|
|
|
let l:hhast_config = findfile('hhast-lint.json', l:root)
|
2018-08-02 18:44:17 +00:00
|
|
|
|
2018-07-27 20:50:59 +00:00
|
|
|
return !empty(l:hhast_config) ? l:root : ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#hack#hhast#GetExecutable(buffer) abort
|
|
|
|
let l:root = ale_linters#hack#hhast#GetProjectRoot(a:buffer)
|
|
|
|
let l:relative = ale#Var(a:buffer, 'hack_hhast_executable')
|
|
|
|
let l:absolute = findfile(l:relative, l:root)
|
2018-08-02 18:44:17 +00:00
|
|
|
|
2018-07-27 20:50:59 +00:00
|
|
|
return !empty(l:absolute) ? l:absolute : ''
|
|
|
|
endfunction
|
|
|
|
|
2018-08-02 21:23:03 +00:00
|
|
|
function! ale_linters#hack#hhast#GetInitializationOptions(buffer) abort
|
|
|
|
return {'lintMode': 'open-files'}
|
|
|
|
endfunction
|
|
|
|
|
2018-07-27 20:50:59 +00:00
|
|
|
call ale#linter#Define('hack', {
|
|
|
|
\ 'name': 'hhast',
|
|
|
|
\ 'lsp': 'stdio',
|
|
|
|
\ 'executable_callback': 'ale_linters#hack#hhast#GetExecutable',
|
2018-08-02 19:59:04 +00:00
|
|
|
\ 'command': '%e --mode lsp --from vim-ale',
|
2018-07-27 20:50:59 +00:00
|
|
|
\ 'project_root_callback': 'ale_linters#hack#hhast#GetProjectRoot',
|
2018-08-02 21:23:03 +00:00
|
|
|
\ 'initialization_options_callback': 'ale_linters#hack#hhast#GetInitializationOptions',
|
2018-07-27 20:50:59 +00:00
|
|
|
\})
|