From e7f933823dc51db3f761df62b49503f06989c6ad Mon Sep 17 00:00:00 2001 From: dantleech Date: Sat, 31 Mar 2018 19:03:01 +0200 Subject: [PATCH 1/3] Refactored to use VIMScript --- autoload/phpstan.vim | 16 +++++++---- plugin/phpstan_filter | 64 ------------------------------------------- 2 files changed, 10 insertions(+), 70 deletions(-) delete mode 100755 plugin/phpstan_filter diff --git a/autoload/phpstan.vim b/autoload/phpstan.vim index 1aea3ce..c5b6a81 100644 --- a/autoload/phpstan.vim +++ b/autoload/phpstan.vim @@ -1,10 +1,14 @@ 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 cmd = './vendor/bin/phpstan analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths + let result = system(cmd) - exe "silent make\ \\\|&\ " . g:phpstan_plugin_path . "/phpstan_filter" - exe "cwindow" + let list = [] + for line in split(result, "\n") + let parts = split(line, ':') + call add(list, { 'filename': parts[0], 'lnum': parts[1], 'text': parts[2] }) + endfor + + call setqflist(list) + execute ':cwindow' endfun 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); From 979a961e1e20cc7d75c66596c12189212552af95 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sat, 31 Mar 2018 19:25:28 +0200 Subject: [PATCH 2/3] Configure phpstan paths --- README.md | 13 ++++++++++++- autoload/phpstan.vim | 20 +++++++++++++++++++- plugin/phpstan.vim | 3 +-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4da2e03..830bedb 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,18 @@ Using [vim-plug](https://github.com/junegunn/vim-plug): You can configure the level PHPStan uses. By default the level is 2. -`let g:phpstan_analyse_level = 4` in your `.vimrc` file to change the level to fit your needs. +``` +let g:phpstan_analyse_level = 4 +``` + +By default the plugin will look for PHPStan in `./vendor/bin/phpstan`, then +`./bin/phpstan` and fallback to the global `phpstan` global executable if it exists. + +You can override the path with + +``` +let g:phpstan_path = '/path//to/phpstan' +``` # Assumptions diff --git a/autoload/phpstan.vim b/autoload/phpstan.vim index c5b6a81..320232d 100644 --- a/autoload/phpstan.vim +++ b/autoload/phpstan.vim @@ -1,6 +1,9 @@ function! phpstan#PHPStanAnalyse(...) let paths = join(a:000, '\ ') - let cmd = './vendor/bin/phpstan analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths + + let phpstan_path = phpstan#_resolvePhpstanPath() + + let cmd = phpstan_path . ' analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths let result = system(cmd) let list = [] @@ -12,3 +15,18 @@ function! phpstan#PHPStanAnalyse(...) call setqflist(list) execute ':cwindow' endfun + +function! phpstan#_resolvePhpstanPath() + echo g:phpstan_paths + 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..5d549b9 100644 --- a/plugin/phpstan.vim +++ b/plugin/phpstan.vim @@ -2,8 +2,7 @@ if exists('g:phpstan_plugin_loaded') || &cp finish endif let g:phpstan_plugin_loaded = 1 - -let g:phpstan_plugin_path = expand(':p:h') +let phpstan_paths = [ './vendor/bin/phpstan', './bin/phpstan' ] if !exists('g:phpstan_analyse_level') let g:phpstan_analyse_level = 2 From 2b0eb477cd17991fe8415fbcbac8c741cd120b17 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sat, 31 Mar 2018 20:26:56 +0200 Subject: [PATCH 3/3] Do not trunacte description --- README.md | 13 +------------ autoload/phpstan.vim | 20 +++++++++++++------- plugin/phpstan.vim | 3 ++- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 830bedb..4da2e03 100644 --- a/README.md +++ b/README.md @@ -26,18 +26,7 @@ Using [vim-plug](https://github.com/junegunn/vim-plug): You can configure the level PHPStan uses. By default the level is 2. -``` -let g:phpstan_analyse_level = 4 -``` - -By default the plugin will look for PHPStan in `./vendor/bin/phpstan`, then -`./bin/phpstan` and fallback to the global `phpstan` global executable if it exists. - -You can override the path with - -``` -let g:phpstan_path = '/path//to/phpstan' -``` +`let g:phpstan_analyse_level = 4` in your `.vimrc` file to change the level to fit your needs. # Assumptions diff --git a/autoload/phpstan.vim b/autoload/phpstan.vim index 320232d..938b17c 100644 --- a/autoload/phpstan.vim +++ b/autoload/phpstan.vim @@ -1,23 +1,29 @@ function! phpstan#PHPStanAnalyse(...) let paths = join(a:000, '\ ') - let phpstan_path = phpstan#_resolvePhpstanPath() let cmd = phpstan_path . ' analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths - let result = system(cmd) + let output = system(cmd) let list = [] - for line in split(result, "\n") + for line in split(output, "\n") + + " Parse the filename and line number let parts = split(line, ':') - call add(list, { 'filename': parts[0], 'lnum': parts[1], 'text': parts[2] }) + + " 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) - execute ':cwindow' + exe 'cwindow' endfun function! phpstan#_resolvePhpstanPath() - echo g:phpstan_paths for phpstan_path in g:phpstan_paths if filereadable(phpstan_path) return phpstan_path @@ -25,7 +31,7 @@ function! phpstan#_resolvePhpstanPath() endfor if !executable('phpstan') - throw 'PHPStan doesn't seem to be globally installed or detected locally' + throw "PHPStan doesn't seem to be globally installed or detected locally" endif return 'phpstan' diff --git a/plugin/phpstan.vim b/plugin/phpstan.vim index 5d549b9..1f1abe8 100644 --- a/plugin/phpstan.vim +++ b/plugin/phpstan.vim @@ -1,8 +1,9 @@ if exists('g:phpstan_plugin_loaded') || &cp finish endif + let g:phpstan_plugin_loaded = 1 -let phpstan_paths = [ './vendor/bin/phpstan', './bin/phpstan' ] +let g:phpstan_paths = [ './vendor/bin/phpstan', './bin/phpstan' ] if !exists('g:phpstan_analyse_level') let g:phpstan_analyse_level = 2