From aca1edb47613a2f41f4b845455a2236b946da197 Mon Sep 17 00:00:00 2001 From: Derek Sifford Date: Mon, 11 Feb 2019 16:24:22 -0500 Subject: [PATCH] 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 --- ale_linters/javascript/tsserver.vim | 2 +- ale_linters/typescript/tsserver.vim | 2 +- autoload/ale/handlers/tsserver.vim | 8 ++++++++ .../test_javascript_tsserver_command_callback.vader | 8 ++++++++ test/command_callback/tsserver_paths/src/file1.ts | 0 test/command_callback/tsserver_paths/src/level-1/file2.ts | 0 .../tsserver_paths/src/level-1/level-2/file3.ts | 0 .../tsserver_paths/src/level-1/tsconfig.json | 0 test/command_callback/tsserver_paths/tsconfig.json | 0 9 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 autoload/ale/handlers/tsserver.vim create mode 100644 test/command_callback/tsserver_paths/src/file1.ts create mode 100644 test/command_callback/tsserver_paths/src/level-1/file2.ts create mode 100644 test/command_callback/tsserver_paths/src/level-1/level-2/file3.ts create mode 100644 test/command_callback/tsserver_paths/src/level-1/tsconfig.json create mode 100644 test/command_callback/tsserver_paths/tsconfig.json 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 +" 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 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 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 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 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