From 0ed07a9ef52b5f8ac528eadb5252ed091db53265 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Fri, 19 Oct 2018 15:51:16 -0400 Subject: [PATCH 1/2] Update Psalm plugin to use LSP mode --- ale_linters/php/psalm.vim | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/ale_linters/php/psalm.vim b/ale_linters/php/psalm.vim index cd20ab81..dce59178 100644 --- a/ale_linters/php/psalm.vim +++ b/ale_linters/php/psalm.vim @@ -1,28 +1,21 @@ -" Author: richard marmorstein +" Author: Matt Brown " Description: plugin for Psalm, static analyzer for PHP -call ale#Set('php_psalm_executable', 'psalm') +call ale#Set('psalm_langserver_executable', 'psalm-language-server') +call ale#Set('psalm_langserver_use_global', get(g:, 'ale_use_global_executables', 0)) -function! ale_linters#php#psalm#Handle(buffer, lines) abort - " Matches patterns like the following: - let l:pattern = '^.*:\(\d\+\):\(\d\+\):\(\w\+\) - \(.*\)$' - let l:output = [] +function! ale_linters#php#psalm#GetProjectRoot(buffer) abort + let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git') - for l:match in ale#util#GetMatches(a:lines, l:pattern) - call add(l:output, { - \ 'lnum': l:match[1] + 0, - \ 'text': l:match[4], - \ 'type': l:match[3][:0] is# 'e' ? 'E' : 'W', - \}) - endfor - - return l:output + return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : '' endfunction call ale#linter#Define('php', { \ 'name': 'psalm', -\ 'command': '%e --diff --output-format=emacs %s', -\ 'executable_callback': ale#VarFunc('php_psalm_executable'), -\ 'callback': 'ale_linters#php#psalm#Handle', -\ 'lint_file': 1, +\ 'lsp': 'stdio', +\ 'executable_callback': ale#node#FindExecutableFunc('psalm_langserver', [ +\ 'vendor/bin/psalm-language-server', +\ ]), +\ 'command': '%e', +\ 'project_root_callback': 'ale_linters#php#psalm#GetProjectRoot', \}) From 7fa0d3dcc47a03c54c4450377ef8053b32e0139a Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Fri, 19 Oct 2018 16:31:12 -0400 Subject: [PATCH 2/2] Add tests for updated Psalm plugin --- .../vendor/bin/psalm-language-server | 0 .../test_psalm_command_callbacks.vader | 25 ++++++++++++++++--- test/handler/test_php_psalm_handler.vader | 24 ------------------ 3 files changed, 21 insertions(+), 28 deletions(-) create mode 100755 test/command_callback/psalm-project/vendor/bin/psalm-language-server delete mode 100644 test/handler/test_php_psalm_handler.vader diff --git a/test/command_callback/psalm-project/vendor/bin/psalm-language-server b/test/command_callback/psalm-project/vendor/bin/psalm-language-server new file mode 100755 index 00000000..e69de29b diff --git a/test/command_callback/test_psalm_command_callbacks.vader b/test/command_callback/test_psalm_command_callbacks.vader index 4c31b7b4..d731054f 100644 --- a/test/command_callback/test_psalm_command_callbacks.vader +++ b/test/command_callback/test_psalm_command_callbacks.vader @@ -2,11 +2,28 @@ Before: call ale#assert#SetUpLinterTest('php', 'psalm') After: + if isdirectory(g:dir . '/.git') + call delete(g:dir . '/.git', 'd') + endif + call ale#assert#TearDownLinterTest() -Execute(Custom executables should be used for the executable and command): - let g:ale_php_psalm_executable = 'psalm_test' +Execute(The default executable path should be correct): + AssertLinter 'psalm-language-server', + \ ale#Escape('psalm-language-server') - AssertLinter 'psalm_test', - \ ale#Escape('psalm_test') . ' --diff --output-format=emacs %s' +Execute(Vendor executables should be detected): + call ale#test#SetFilename('psalm-project/test.php') + AssertLinter + \ ale#path#Simplify(g:dir . '/psalm-project/vendor/bin/psalm-language-server'), + \ ale#Escape(ale#path#Simplify( + \ g:dir + \ . '/psalm-project/vendor/bin/psalm-language-server' + \ )) + +Execute(The project path should be correct for .git directories): + call ale#test#SetFilename('psalm-project/test.php') + call mkdir(g:dir . '/.git') + + AssertLSPProject g:dir \ No newline at end of file diff --git a/test/handler/test_php_psalm_handler.vader b/test/handler/test_php_psalm_handler.vader deleted file mode 100644 index fd62a467..00000000 --- a/test/handler/test_php_psalm_handler.vader +++ /dev/null @@ -1,24 +0,0 @@ -Before: - runtime ale_linters/php/psalm.vim - -After: - call ale#linter#Reset() - -Execute(The php static analyzer handler should parse errors from psalm): - AssertEqual - \ [ - \ { - \ 'lnum': 1, - \ 'type': 'W', - \ 'text': 'somewarning', - \ }, - \ { - \ 'lnum': 11, - \ 'type': 'E', - \ 'text': 'someerror', - \ }, - \ ], - \ ale_linters#php#psalm#Handle(347, [ - \ "/file:1:3:warning - somewarning", - \ "/file:11:33:error - someerror", - \ ])