summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/php/langserver.vim6
-rw-r--r--test/command_callback/php-langserver-project/with-composer/composer.json0
-rwxr-xr-xtest/command_callback/php-langserver-project/with-composer/vendor/bin/php-language-server.php0
-rwxr-xr-xtest/command_callback/php-langserver-project/with-git/vendor/bin/php-language-server.php0
-rw-r--r--test/command_callback/test_php_langserver_callbacks.vader15
5 files changed, 14 insertions, 7 deletions
diff --git a/ale_linters/php/langserver.vim b/ale_linters/php/langserver.vim
index c88281c4..fdd1bf2b 100644
--- a/ale_linters/php/langserver.vim
+++ b/ale_linters/php/langserver.vim
@@ -5,6 +5,12 @@ call ale#Set('php_langserver_executable', 'php-language-server.php')
call ale#Set('php_langserver_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale_linters#php#langserver#GetProjectRoot(buffer) abort
+ let l:composer_path = ale#path#FindNearestFile(a:buffer, 'composer.json')
+
+ if (!empty(l:composer_path))
+ return fnamemodify(l:composer_path, ':h')
+ endif
+
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : ''
diff --git a/test/command_callback/php-langserver-project/with-composer/composer.json b/test/command_callback/php-langserver-project/with-composer/composer.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/php-langserver-project/with-composer/composer.json
diff --git a/test/command_callback/php-langserver-project/with-composer/vendor/bin/php-language-server.php b/test/command_callback/php-langserver-project/with-composer/vendor/bin/php-language-server.php
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/php-langserver-project/with-composer/vendor/bin/php-language-server.php
diff --git a/test/command_callback/php-langserver-project/with-git/vendor/bin/php-language-server.php b/test/command_callback/php-langserver-project/with-git/vendor/bin/php-language-server.php
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/php-langserver-project/with-git/vendor/bin/php-language-server.php
diff --git a/test/command_callback/test_php_langserver_callbacks.vader b/test/command_callback/test_php_langserver_callbacks.vader
index 3b0a427e..59c3fe6c 100644
--- a/test/command_callback/test_php_langserver_callbacks.vader
+++ b/test/command_callback/test_php_langserver_callbacks.vader
@@ -2,10 +2,6 @@ Before:
call ale#assert#SetUpLinterTest('php', 'langserver')
After:
- if isdirectory(g:dir . '/.git')
- call delete(g:dir . '/.git', 'd')
- endif
-
call ale#assert#TearDownLinterTest()
Execute(The default executable path should be correct):
@@ -23,7 +19,12 @@ Execute(Vendor executables should be detected):
\ ))
Execute(The project path should be correct for .git directories):
- call ale#test#SetFilename('php-langserver-project/test.php')
- call mkdir(g:dir . '/.git')
+ call ale#test#SetFilename('php-langserver-project/with-git/test.php')
+ silent! call mkdir('php-langserver-project/with-git/.git')
+
+ AssertLSPProject ale#path#Simplify(g:dir . '/php-langserver-project/with-git')
+
+Execute(The project path should be correct for composer.json file):
+ call ale#test#SetFilename('php-langserver-project/with-composer/test.php')
- AssertLSPProject g:dir
+ AssertLSPProject ale#path#Simplify(g:dir . '/php-langserver-project/with-composer')