Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPactor works with file mapping #4717

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions ale_linters/php/phpactor.vim
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
" Author: Arizard <https://github.com/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'),
\})
19 changes: 19 additions & 0 deletions doc/ale-php.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down