add project_root_callback for tsserver (#2290)

* add project_root_callback for tsserver
* add tests for tsserver project root
* Update test/command_callback/test_javascript_tsserver_command_callback.vader
This commit is contained in:
Derek Sifford 2019-02-11 16:24:22 -05:00 committed by w0rp
parent 6ebe24b5ff
commit aca1edb476
9 changed files with 18 additions and 2 deletions

View file

@ -12,6 +12,6 @@ call ale#linter#Define('javascript', {
\ 'node_modules/.bin/tsserver',
\ ]),
\ 'command': '%e',
\ 'project_root_callback': {-> ''},
\ 'project_root_callback': 'ale#handlers#tsserver#GetProjectRoot',
\ 'language': '',
\})

View file

@ -12,6 +12,6 @@ call ale#linter#Define('typescript', {
\ 'node_modules/.bin/tsserver',
\ ]),
\ 'command': '%e',
\ 'project_root_callback': {-> ''},
\ 'project_root_callback': 'ale#handlers#tsserver#GetProjectRoot',
\ 'language': '',
\})

View file

@ -0,0 +1,8 @@
" Author: Derek Sifford <dereksifford@gmail.com>
" Description: Handlers for tsserver
function! ale#handlers#tsserver#GetProjectRoot(buffer) abort
let l:tsconfig_file = ale#path#FindNearestFile(a:buffer, 'tsconfig.json')
return !empty(l:tsconfig_file) ? fnamemodify(l:tsconfig_file, ':h') : ''
endfunction

View file

@ -6,3 +6,11 @@ After:
Execute(The default command should be correct):
AssertLinter 'tsserver', ale#Escape('tsserver')
Execute(should resolve correct path when nested 1):
call ale#test#SetFilename('tsserver_paths/src/level-1/level-2/file3.ts')
AssertLSPProject ale#path#Simplify(g:dir . '/tsserver_paths/src/level-1')
Execute(should resolve correct path when nested 2):
call ale#test#SetFilename('tsserver_paths/src/file1.ts')
AssertLSPProject ale#path#Simplify(g:dir . '/tsserver_paths')