From fec6b63494b4f491279c7a01c0d61e515b8d0f46 Mon Sep 17 00:00:00 2001 From: Arnold Chand Date: Tue, 15 Sep 2020 19:14:12 -0400 Subject: [PATCH 1/3] feat: add intelephense support for php --- ale_linters/php/intelephense.vim | 32 +++++++++++++++++ doc/ale-php.txt | 35 +++++++++++++++++++ doc/ale-supported-languages-and-tools.txt | 1 + doc/ale.txt | 1 + supported-tools.md | 1 + .../with-composer/composer.json | 0 ...st_php_intelephense_command_callback.vader | 23 ++++++++++++ 7 files changed, 93 insertions(+) create mode 100644 ale_linters/php/intelephense.vim create mode 100644 test/command_callback/php-intelephense-project/with-composer/composer.json create mode 100644 test/command_callback/test_php_intelephense_command_callback.vader diff --git a/ale_linters/php/intelephense.vim b/ale_linters/php/intelephense.vim new file mode 100644 index 00000000..e9e07d1f --- /dev/null +++ b/ale_linters/php/intelephense.vim @@ -0,0 +1,32 @@ +" Author: Eric Stern , +" Arnold Chand +" Description: Intelephense language server integration for ALE + +call ale#Set('php_intelephense_executable', 'intelephense') +call ale#Set('php_intelephense_use_global', 1) +call ale#Set('php_intelephense_config', {}) + +function! ale_linters#php#intelephense#GetProjectRoot(buffer) abort + let l:composer_path = ale#path#FindNearestFile(a:buffer, 'composer.json') + + if (!empty(l:composer_path)) + return fnamemodify(l:composer_path, ':h') + endif + + let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git') + + return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : '' +endfunction + +function! ale_linters#php#intelephense#GetInitializationOptions() abort + return ale#Get('php_intelephense_config') +endfunction + +call ale#linter#Define('php', { +\ 'name': 'intelephense', +\ 'lsp': 'stdio', +\ 'initialization_options': function('ale_linters#php#intelephense#GetInitializationOptions'), +\ 'executable': {b -> ale#node#FindExecutable(b, 'php_intelephense', [])}, +\ 'command': '%e --stdio', +\ 'project_root': function('ale_linters#php#intelephense#GetProjectRoot'), +\}) diff --git a/doc/ale-php.txt b/doc/ale-php.txt index 9fe868f8..79d9a033 100644 --- a/doc/ale-php.txt +++ b/doc/ale-php.txt @@ -243,5 +243,40 @@ g:ale_php_php_executable *g:ale_php_php_executable* This variable sets the executable used for php. +=============================================================================== +intelephense *ale-php-intelephense* + +g:ale_php_intelephense_executable *g:ale_php_intelephense_executable* + *b:ale_php_intelephense_executable* + Type: |String| + Default: `'intelephense'` + + The variable can be set to configure the executable that will be used for + running the intelephense language server. `node_modules` directory + executable will be preferred instead of this setting if + |g:ale_php_intelephense_use_global| is `0`. + + See: |ale-integrations-local-executables| + + +g:ale_php_intelephense_use_global *g:ale_php_intelephense_use_global* + *b:ale_php_intelephense_use_global* + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + This variable can be set to `1` to force the language server to be run with + the executable set for |g:ale_php_intelephense_executable|. + + See: |ale-integrations-local-executables| + +g:ale_php_intelephense_config *g:ale_php_intelephense_config* + *b:ale_php_intelephense_config* + Type: |Dictionary| + Default: `{}` + + The initialization options config specified by Intelephense. Refer to the + installation docs provided by intelephense (github.com/bmewburn/intelephense + -docs). + =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index c6bcf421..7c8c9bac 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -324,6 +324,7 @@ Notes: * Perl6 * `perl6 -c` * PHP + * `intelephense` * `langserver` * `phan` * `phpcbf` diff --git a/doc/ale.txt b/doc/ale.txt index 6ef137c1..67ef531c 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2752,6 +2752,7 @@ documented in additional help files. psalm.................................|ale-php-psalm| php-cs-fixer..........................|ale-php-php-cs-fixer| php...................................|ale-php-php| + intelephense..........................|ale-php-intelephense| po......................................|ale-po-options| write-good............................|ale-po-write-good| pod.....................................|ale-pod-options| diff --git a/supported-tools.md b/supported-tools.md index 66e46348..559f841a 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -333,6 +333,7 @@ formatting. * Perl6 * [perl6 -c](https://perl6.org) :warning: * PHP + * [intelephense](https://github.com/bmewburn/intelephense-docs) * [langserver](https://github.com/felixfbecker/php-language-server) * [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions * [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) diff --git a/test/command_callback/php-intelephense-project/with-composer/composer.json b/test/command_callback/php-intelephense-project/with-composer/composer.json new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/test_php_intelephense_command_callback.vader b/test/command_callback/test_php_intelephense_command_callback.vader new file mode 100644 index 00000000..283fd615 --- /dev/null +++ b/test/command_callback/test_php_intelephense_command_callback.vader @@ -0,0 +1,23 @@ +Before: + call ale#assert#SetUpLinterTest('php', 'intelephense') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default executable path should be correct): + AssertLinter 'intelephense', + \ ale#Escape('intelephense') . ' --stdio' + +Execute(The project path should be correct for .git directories): + call ale#test#SetFilename('php-intelephense-project/with-git/test.php') + silent! call mkdir('php-langserver-project/with-git/.git', 'p') + AssertLSPProject ale#path#Simplify(g:dir . '/php-intelephense-project/with-git') + +Execute(The project path should be correct for composer.json file): + call ale#test#SetFilename('php-intelephense-project/with-composer/test.php') + AssertLSPProject ale#path#Simplify(g:dir . '/php-intelephense-project/with-composer') + +Execute(The project should save to a temp dir): + call ale#test#SetFilename('php-intelephense-project/with-composer/test.php') + let g:ale_php_intelephense_config = { 'storagePath': '/tmp/intelephense' } + AssertLSPProject ale#path#Simplify(g:dir . '/php-intelephense-project/with-composer') From 8a855e3e6442a3b1384a07098d166c114a3e01f3 Mon Sep 17 00:00:00 2001 From: Arnold Chand Date: Thu, 17 Sep 2020 09:35:06 -0400 Subject: [PATCH 2/3] fix: tests --- .../test_php_intelephense_command_callback.vader | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/command_callback/test_php_intelephense_command_callback.vader b/test/command_callback/test_php_intelephense_command_callback.vader index 283fd615..164ca26e 100644 --- a/test/command_callback/test_php_intelephense_command_callback.vader +++ b/test/command_callback/test_php_intelephense_command_callback.vader @@ -10,14 +10,17 @@ Execute(The default executable path should be correct): Execute(The project path should be correct for .git directories): call ale#test#SetFilename('php-intelephense-project/with-git/test.php') - silent! call mkdir('php-langserver-project/with-git/.git', 'p') + silent! call mkdir('php-intelephense-project/with-git/.git') + AssertLSPProject ale#path#Simplify(g:dir . '/php-intelephense-project/with-git') Execute(The project path should be correct for composer.json file): call ale#test#SetFilename('php-intelephense-project/with-composer/test.php') + AssertLSPProject ale#path#Simplify(g:dir . '/php-intelephense-project/with-composer') -Execute(The project should save to a temp dir): +Execute(The project cache should be saved in a temp dir): call ale#test#SetFilename('php-intelephense-project/with-composer/test.php') let g:ale_php_intelephense_config = { 'storagePath': '/tmp/intelephense' } + AssertLSPProject ale#path#Simplify(g:dir . '/php-intelephense-project/with-composer') From f8351c1b22d02f194235388779ad47028d5e7a25 Mon Sep 17 00:00:00 2001 From: Arnold Chand Date: Thu, 17 Sep 2020 09:58:45 -0400 Subject: [PATCH 3/3] fix: test: mkdir should create if it doesn't exist --- .../test_php_intelephense_command_callback.vader | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/command_callback/test_php_intelephense_command_callback.vader b/test/command_callback/test_php_intelephense_command_callback.vader index 164ca26e..dd6adb3d 100644 --- a/test/command_callback/test_php_intelephense_command_callback.vader +++ b/test/command_callback/test_php_intelephense_command_callback.vader @@ -10,7 +10,7 @@ Execute(The default executable path should be correct): Execute(The project path should be correct for .git directories): call ale#test#SetFilename('php-intelephense-project/with-git/test.php') - silent! call mkdir('php-intelephense-project/with-git/.git') + silent! call mkdir('php-intelephense-project/with-git/.git', 'p') AssertLSPProject ale#path#Simplify(g:dir . '/php-intelephense-project/with-git')