diff --git a/ale_linters/php/phpactor.vim b/ale_linters/php/phpactor.vim index b137eaf150..f788d7e7c4 100644 --- a/ale_linters/php/phpactor.vim +++ b/ale_linters/php/phpactor.vim @@ -1,23 +1,51 @@ " Author: Arizard " Description: PHPactor integration for ALE +" Note: initial code has been copied from langserver.vim + +call ale#Set('php_phpactor_executable', 'phpactor') +call ale#Set('php_phpactor_use_global', get(g:, 'ale_use_global_executables', 0)) -" Copied from langserver.vim function! ale_linters#php#phpactor#GetProjectRoot(buffer) abort let l:composer_path = ale#path#FindNearestFile(a:buffer, 'composer.json') + let l:file_mappings = ale#GetFilenameMappings(a:buffer, 'phpactor') if (!empty(l:composer_path)) - return fnamemodify(l:composer_path, ':h') + let l:mapped_path = ale_linters#php#phpactor#Mapping(l:composer_path, l:file_mappings ) + + return fnamemodify(l:mapped_path, ':h') endif let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git') + let l:mapped_path = ale_linters#php#phpactor#Mapping(l:git_path, l:file_mappings ) + + return !empty(l:mapped_path) ? fnamemodify(l:mapped_path, ':h:h') : '' +endfunction + +function! ale_linters#php#phpactor#Mapping(filename, filename_mappings) abort + if empty(a:filename_mappings) + " No mapping found to return + return a:filename + endif + + for [l:mapping_from, l:mapping_to] in a:filename_mappings + let l:mapping_from = ale#path#Simplify(l:mapping_from) + + if a:filename[:len(l:mapping_from) - 1] is# l:mapping_from + return l:mapping_to + endif + endfor - return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : '' + " No entry found to return + return a:filename endfunction call ale#linter#Define('php', { \ 'name': 'phpactor', \ 'lsp': 'stdio', -\ 'executable': 'phpactor', +\ 'executable': {b -> ale#path#FindExecutable(b, 'php_phpactor', [ +\ 'vendor/bin/phpactor', +\ 'phpactor' +\ ])}, \ 'command': '%e language-server', \ 'project_root': function('ale_linters#php#phpactor#GetProjectRoot'), \}) diff --git a/doc/ale-php.txt b/doc/ale-php.txt index 2750a319f9..b12b67adc2 100644 --- a/doc/ale-php.txt +++ b/doc/ale-php.txt @@ -66,6 +66,25 @@ g:ale_php_phan_use_client *g:ale_php_phan_use_client* instead of the phan standalone. +=============================================================================== +phpactor *ale-php-phpactor* + +g:ale_php_phpactor_executable *g:ale_php_phpactor_executable* + *b:ale_php_phpactor_executable* + Type: |String| + Default: `'phpactor'` + + See |ale-integrations-local-executables| + + +g:ale_php_phpactor_use_global *g:ale_php_phpactor_use_global* + *b:ale_php_phpactor_use_global* + Type: |Number| + Default: `get(g:, 'ale_use_global_executables', 0)` + + See |ale-integrations-local-executables| + + =============================================================================== phpcbf *ale-php-phpcbf* diff --git a/doc/ale.txt b/doc/ale.txt index 756735f703..8a3bb97a44 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3245,6 +3245,7 @@ documented in additional help files. cspell................................|ale-php-cspell| langserver............................|ale-php-langserver| phan..................................|ale-php-phan| + phpactor..............................|ale-php-phpactor| phpcbf................................|ale-php-phpcbf| phpcs.................................|ale-php-phpcs| phpmd.................................|ale-php-phpmd|