Skip to content

Commit 6719322

Browse files
authored
Merge pull request #1 from dantleech/vimscript
Vimscript implementation
2 parents 1f1618c + 2b0eb47 commit 6719322

File tree

3 files changed

+36
-72
lines changed

3 files changed

+36
-72
lines changed

autoload/phpstan.vim

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
function! phpstan#PHPStanAnalyse(...)
22
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()
74

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'
1038
endfun

plugin/phpstan.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
if exists('g:phpstan_plugin_loaded') || &cp
22
finish
33
endif
4-
let g:phpstan_plugin_loaded = 1
54

6-
let g:phpstan_plugin_path = expand('<sfile>:p:h')
5+
let g:phpstan_plugin_loaded = 1
6+
let g:phpstan_paths = [ './vendor/bin/phpstan', './bin/phpstan' ]
77

88
if !exists('g:phpstan_analyse_level')
99
let g:phpstan_analyse_level = 2

plugin/phpstan_filter

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)