diff options
9 files changed, 18 insertions, 2 deletions
diff --git a/ale_linters/javascript/tsserver.vim b/ale_linters/javascript/tsserver.vim index 6cf08dd6..63509022 100644 --- a/ale_linters/javascript/tsserver.vim +++ b/ale_linters/javascript/tsserver.vim @@ -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': '', \}) diff --git a/ale_linters/typescript/tsserver.vim b/ale_linters/typescript/tsserver.vim index bac63229..7dc8fa85 100644 --- a/ale_linters/typescript/tsserver.vim +++ b/ale_linters/typescript/tsserver.vim @@ -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': '', \}) diff --git a/autoload/ale/handlers/tsserver.vim b/autoload/ale/handlers/tsserver.vim new file mode 100644 index 00000000..f78499ac --- /dev/null +++ b/autoload/ale/handlers/tsserver.vim @@ -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 diff --git a/test/command_callback/test_javascript_tsserver_command_callback.vader b/test/command_callback/test_javascript_tsserver_command_callback.vader index 638dd873..04230238 100644 --- a/test/command_callback/test_javascript_tsserver_command_callback.vader +++ b/test/command_callback/test_javascript_tsserver_command_callback.vader @@ -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') diff --git a/test/command_callback/tsserver_paths/src/file1.ts b/test/command_callback/tsserver_paths/src/file1.ts new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tsserver_paths/src/file1.ts diff --git a/test/command_callback/tsserver_paths/src/level-1/file2.ts b/test/command_callback/tsserver_paths/src/level-1/file2.ts new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tsserver_paths/src/level-1/file2.ts diff --git a/test/command_callback/tsserver_paths/src/level-1/level-2/file3.ts b/test/command_callback/tsserver_paths/src/level-1/level-2/file3.ts new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tsserver_paths/src/level-1/level-2/file3.ts diff --git a/test/command_callback/tsserver_paths/src/level-1/tsconfig.json b/test/command_callback/tsserver_paths/src/level-1/tsconfig.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tsserver_paths/src/level-1/tsconfig.json diff --git a/test/command_callback/tsserver_paths/tsconfig.json b/test/command_callback/tsserver_paths/tsconfig.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/tsserver_paths/tsconfig.json |