diff --git a/autoload/phpstan.vim b/autoload/phpstan.vim index 1aea3ce..938b17c 100644 --- a/autoload/phpstan.vim +++ b/autoload/phpstan.vim @@ -1,10 +1,38 @@ function! phpstan#PHPStanAnalyse(...) let paths = join(a:000, '\ ') - exe "setlocal makeprg=phpstan\\ analyse\\ --no-progress\\ -l" . g:phpstan_analyse_level . "\\ " . paths - " File: path/to/file.php, line: 12, error: error message - setlocal efm=File%.\ %f%.\ line%.\ %l%.\ error%.\ %m - setlocal efm+=%-G " Ignore empty lines + let phpstan_path = phpstan#_resolvePhpstanPath() - exe "silent make\ \\\|&\ " . g:phpstan_plugin_path . "/phpstan_filter" - exe "cwindow" + let cmd = phpstan_path . ' analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths + let output = system(cmd) + + let list = [] + for line in split(output, "\n") + + " Parse the filename and line number + let parts = split(line, ':') + + " The reset of the string is the description + let description = join(parts[2:], ':') + + " Add to the quickfix List + call add(list, { 'filename': parts[0], 'lnum': parts[1], 'text': description }) + + endfor + + call setqflist(list) + exe 'cwindow' +endfun + +function! phpstan#_resolvePhpstanPath() + for phpstan_path in g:phpstan_paths + if filereadable(phpstan_path) + return phpstan_path + endif + endfor + + if !executable('phpstan') + throw "PHPStan doesn't seem to be globally installed or detected locally" + endif + + return 'phpstan' endfun diff --git a/plugin/phpstan.vim b/plugin/phpstan.vim index a3bef55..1f1abe8 100644 --- a/plugin/phpstan.vim +++ b/plugin/phpstan.vim @@ -1,9 +1,9 @@ if exists('g:phpstan_plugin_loaded') || &cp finish endif -let g:phpstan_plugin_loaded = 1 -let g:phpstan_plugin_path = expand(':p:h') +let g:phpstan_plugin_loaded = 1 +let g:phpstan_paths = [ './vendor/bin/phpstan', './bin/phpstan' ] if !exists('g:phpstan_analyse_level') let g:phpstan_analyse_level = 2 diff --git a/plugin/phpstan_filter b/plugin/phpstan_filter deleted file mode 100755 index 6e24d01..0000000 --- a/plugin/phpstan_filter +++ /dev/null @@ -1,64 +0,0 @@ -#! /usr/bin/php - - 0) { - $output .= "File: " . $currentFile . ", line: " . $lineNumber . ", error: " . implode(' ', $errorMessages) . PHP_EOL; - $errorMessages = []; - } -} - -echo trim($output);