|
1 | 1 | function! phpstan#PHPStanAnalyse(...)
|
2 | 2 | let paths = join(a:000, '\ ')
|
3 |
| - exe "setlocal makeprg=phpstan\\ analyse\\ --no-progress\\ -l" . g:phpstan_analyse_level . "\\ " . paths |
4 |
| - " File: path/to/file.php, line: 12, error: error message |
5 |
| - setlocal efm=File%.\ %f%.\ line%.\ %l%.\ error%.\ %m |
6 |
| - setlocal efm+=%-G " Ignore empty lines |
| 3 | + let phpstan_path = phpstan#_resolvePhpstanPath() |
7 | 4 |
|
8 |
| - exe "silent make\ \\\|&\ " . g:phpstan_plugin_path . "/phpstan_filter" |
9 |
| - exe "cwindow" |
| 5 | + let cmd = phpstan_path . ' analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths |
| 6 | + let output = system(cmd) |
| 7 | + |
| 8 | + let list = [] |
| 9 | + for line in split(output, "\n") |
| 10 | + |
| 11 | + " Parse the filename and line number |
| 12 | + let parts = split(line, ':') |
| 13 | + |
| 14 | + " The reset of the string is the description |
| 15 | + let description = join(parts[2:], ':') |
| 16 | + |
| 17 | + " Add to the quickfix List |
| 18 | + call add(list, { 'filename': parts[0], 'lnum': parts[1], 'text': description }) |
| 19 | + |
| 20 | + endfor |
| 21 | + |
| 22 | + call setqflist(list) |
| 23 | + exe 'cwindow' |
| 24 | +endfun |
| 25 | + |
| 26 | +function! phpstan#_resolvePhpstanPath() |
| 27 | + for phpstan_path in g:phpstan_paths |
| 28 | + if filereadable(phpstan_path) |
| 29 | + return phpstan_path |
| 30 | + endif |
| 31 | + endfor |
| 32 | + |
| 33 | + if !executable('phpstan') |
| 34 | + throw "PHPStan doesn't seem to be globally installed or detected locally" |
| 35 | + endif |
| 36 | + |
| 37 | + return 'phpstan' |
10 | 38 | endfun
|
0 commit comments