Skip to content

Vimscript implementation #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions autoload/phpstan.vim
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions plugin/phpstan.vim
Original file line number Diff line number Diff line change
@@ -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('<sfile>: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
Expand Down
64 changes: 0 additions & 64 deletions plugin/phpstan_filter

This file was deleted.