From 31dc6a61a07839ea906f6f0b80be713fb8cad1c7 Mon Sep 17 00:00:00 2001 From: Daisuke Shimamoto Date: Mon, 15 Nov 2021 21:17:18 +0900 Subject: Find composer.json when searching for psalm (#3979) * Look for nearest composer.json before .git * Add test for projects with composer.json --- ale_linters/php/psalm.vim | 6 ++++++ test/linter/test_psalm.vader | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/ale_linters/php/psalm.vim b/ale_linters/php/psalm.vim index dbbe9453..f1280057 100644 --- a/ale_linters/php/psalm.vim +++ b/ale_linters/php/psalm.vim @@ -6,6 +6,12 @@ call ale#Set('php_psalm_options', '') call ale#Set('php_psalm_use_global', get(g:, 'ale_use_global_executables', 0)) function! ale_linters#php#psalm#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/linter/test_psalm.vader b/test/linter/test_psalm.vader index 4edb95c8..b79f2724 100644 --- a/test/linter/test_psalm.vader +++ b/test/linter/test_psalm.vader @@ -36,3 +36,8 @@ Execute(User provided options should be used): AssertLinter 'psalm', \ ale#Escape('psalm') \ . ' --language-server --my-user-provided-option my-value' + +Execute(The project path should be correct for composer.json file): + call ale#test#SetFilename('../test-files/php/with-composer/test.php') + + AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/php/with-composer') -- cgit v1.2.3