summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/php/intelephense.vim32
-rw-r--r--doc/ale-php.txt35
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/command_callback/php-intelephense-project/with-composer/composer.json0
-rw-r--r--test/command_callback/test_php_intelephense_command_callback.vader26
7 files changed, 96 insertions, 0 deletions
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 <eric@ericstern.com>,
+" Arnold Chand <creativenull@outlook.com>
+" 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
@@ -244,4 +244,39 @@ 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 b95c3a9b..469f5fc9 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -326,6 +326,7 @@ Notes:
* Perl6
* `perl6 -c`
* PHP
+ * `intelephense`
* `langserver`
* `phan`
* `phpcbf`
diff --git a/doc/ale.txt b/doc/ale.txt
index 1a2938ee..95634171 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2796,6 +2796,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 4567bf10..0aa25761 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -335,6 +335,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
--- /dev/null
+++ b/test/command_callback/php-intelephense-project/with-composer/composer.json
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..dd6adb3d
--- /dev/null
+++ b/test/command_callback/test_php_intelephense_command_callback.vader
@@ -0,0 +1,26 @@
+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-intelephense-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 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')