summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Sifford <dereksifford@gmail.com>2019-02-11 16:24:22 -0500
committerw0rp <w0rp@users.noreply.github.com>2019-02-11 21:24:22 +0000
commitaca1edb47613a2f41f4b845455a2236b946da197 (patch)
tree6c135f7d3da9bed5eb47439355ce818c74033c61
parent6ebe24b5ffcd8536c613a4f12d07ccadbfb07cd8 (diff)
downloadale-aca1edb47613a2f41f4b845455a2236b946da197.zip
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
-rw-r--r--ale_linters/javascript/tsserver.vim2
-rw-r--r--ale_linters/typescript/tsserver.vim2
-rw-r--r--autoload/ale/handlers/tsserver.vim8
-rw-r--r--test/command_callback/test_javascript_tsserver_command_callback.vader8
-rw-r--r--test/command_callback/tsserver_paths/src/file1.ts0
-rw-r--r--test/command_callback/tsserver_paths/src/level-1/file2.ts0
-rw-r--r--test/command_callback/tsserver_paths/src/level-1/level-2/file3.ts0
-rw-r--r--test/command_callback/tsserver_paths/src/level-1/tsconfig.json0
-rw-r--r--test/command_callback/tsserver_paths/tsconfig.json0
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