Skip to content
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
25 changes: 1 addition & 24 deletions ale_linters/perl/languageserver.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,6 @@
call ale#Set('perl_perl_executable', 'perl')
" Please note that perl_perl_options does not exist here.

function! ale_linters#perl#languageserver#GetProjectRoot(buffer) abort
" Makefile.PL, https://perldoc.perl.org/ExtUtils::MakeMaker
" Build.PL, https://metacpan.org/pod/Module::Build
" dist.ini, https://metacpan.org/pod/Dist::Zilla
let l:potential_roots = [ 'Makefile.PL', 'Build.PL', 'dist.ini' ]

for l:root in l:potential_roots
let l:project_root = ale#path#FindNearestFile(a:buffer, l:root)

if !empty(l:project_root)
return fnamemodify(l:project_root . '/', ':p:h:h')
endif
endfor

let l:project_root = ale#path#FindNearestFileOrDirectory(a:buffer, '.git')

if !empty(l:project_root)
return fnamemodify(l:project_root . '/', ':p:h:h')
endif

return fnamemodify(expand('#' . a:buffer . ':p:h'), ':p:h')
endfunction

call ale#Set('perl_languageserver_config', {})

function! s:get_lsp_config(buffer) abort
Expand All @@ -45,5 +22,5 @@ call ale#linter#Define('perl', {
\ 'executable': {b -> ale#Var(b, 'perl_perl_executable')},
\ 'command': '%e -MPerl::LanguageServer -ePerl::LanguageServer::run',
\ 'lsp_config': {b -> s:get_lsp_config(b)},
\ 'project_root': function('ale_linters#perl#languageserver#GetProjectRoot'),
\ 'project_root': function('ale#handlers#perl#GetProjectRoot'),
\ })
15 changes: 15 additions & 0 deletions ale_linters/perl/perlnavigator.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
" Author: rymdbar <https://rymdbar.x20.se/>
" Description: Perl Navigator Language Server
" See: https://github.com/bscan/PerlNavigator

call ale#Set('perl_perlnavigator_config', {})
call ale#Set('perl_perlnavigator_executable', 'perlnavigator')

call ale#linter#Define('perl', {
\ 'name': 'perlnavigator',
\ 'lsp': 'stdio',
\ 'executable': {b -> ale#Var(b, 'perl_perlnavigator_executable')},
\ 'command': '%e --stdio',
\ 'lsp_config': {b -> ale#Var(b, 'perl_perlnavigator_config')},
\ 'project_root': function('ale#handlers#perl#GetProjectRoot'),
\ })
24 changes: 24 additions & 0 deletions autoload/ale/handlers/perl.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
" Author: rymdbar <https://rymdbar.x20.se/>

function! ale#handlers#perl#GetProjectRoot(buffer) abort
" Makefile.PL, https://perldoc.perl.org/ExtUtils::MakeMaker
" Build.PL, https://metacpan.org/pod/Module::Build
" dist.ini, https://metacpan.org/pod/Dist::Zilla
let l:potential_roots = [ 'Makefile.PL', 'Build.PL', 'dist.ini' ]

for l:root in l:potential_roots
let l:project_root = ale#path#FindNearestFile(a:buffer, l:root)

if !empty(l:project_root)
return fnamemodify(l:project_root . '/', ':p:h:h')
endif
endfor

let l:project_root = ale#path#FindNearestFileOrDirectory(a:buffer, '.git')

if !empty(l:project_root)
return fnamemodify(l:project_root . '/', ':p:h:h')
endif

return fnamemodify(expand('#' . a:buffer . ':p:h'), ':p:h')
endfunction
49 changes: 48 additions & 1 deletion doc/ale-perl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ g:ale_perl_languageserver_config
For all available options and explanations, visit
https://metacpan.org/pod/Perl::LanguageServer#Extension-Settings


===============================================================================
perlcritic *ale-perl-perlcritic*

Expand Down Expand Up @@ -127,6 +126,54 @@ g:ale_perl_perlcritic_showrules
Defaults to off to reduce length of message.



===============================================================================
perlnavigator *ale-perl-perlnavigator*

*ale-options.perl_perlnavigator_executable*
*g:ale_perl_perlnavigator_executable*
*b:ale_perl_perlnavigator_executable*
perl_perlnavigator_executable
g:ale_perl_perlnavigator_executable
Type: |String|
Default: `'perlnavigator'`

This variable can be changed to modify the perlnavigator executable used for
linting perl.

*ale-options.perl_perlnavigator_config*
*g:ale_perl_perlnavigator_config*
*b:ale_perl_perlnavigator_config*
perl_perlnavigator_config
g:ale_perl_perlnavigator_config
Type: |Dictionary|
Default: `'{}'`

This variable can be changed to customize the lsp_config (sent as a
workspace/didChangeConfiguration command) for perlnavigator.
For example: >

let g:ale_perl_perlnavigator_config = {
\ 'perlnavigator': {
\ 'enableWarnings': 1,
\ 'includePaths': [ $HOME . '/MyPerlStuff/lib', '/tmp/tmp.7qSgUo34e' ],
\ 'perlEnvAdd': 1,
\ 'perlEnv': {
\ 'PERL_DL_NONLAZY': 1,
\ },
\ 'perlPath': substitute(g:ale_perl_perl_executable, '/perl$', '', ''),
\ 'perlcriticEnabled': 1,
\ 'perlcriticProfile': '$workspaceFolder/.perlcriticrc',
\ 'perltidyProfile': '$workspaceFolder/.perltidyrc',
\ 'perlcriticSeverity': 2,
\ },
\ }
\}

<
For all available options and explanations, visit
https://github.com/bscan/PerlNavigator?tab=readme-ov-file

===============================================================================
perltidy *ale-perl-perltidy*

Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ Notes:
* `languageserver`
* `perl -c`
* `perl-critic`
* `perlnavigator`
* `perltidy`
* Perl6
* `perl6 -c`
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3756,6 +3756,7 @@ documented in additional help files.
perl..................................|ale-perl-perl|
perl language server..................|ale-perl-languageserver|
perlcritic............................|ale-perl-perlcritic|
perlnavigator.........................|ale-perl-perlnavigator|
perltidy..............................|ale-perl-perltidy|
perl6...................................|ale-perl6-options|
perl6.................................|ale-perl6-perl6|
Expand Down
3 changes: 2 additions & 1 deletion supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,10 @@ formatting.
* Pawn
* [uncrustify](https://github.com/uncrustify/uncrustify)
* Perl
* [languageserver](https://metacpan.org/pod/Perl::LanguageServer)
* [languageserver](https://metacpan.org/pod/Perl::LanguageServer) :speech_balloon:
* [perl -c](https://perl.org/) :warning:
* [perl-critic](https://metacpan.org/pod/Perl::Critic)
* [perlnavigator](https://github.com/bscan/PerlNavigator) :speech_balloon:
* [perltidy](https://metacpan.org/pod/distribution/Perl-Tidy/bin/perltidy)
* Perl6
* [perl6 -c](https://perl6.org) :warning:
Expand Down
78 changes: 78 additions & 0 deletions test/linter/test_perl_perlnavigator.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
" Author: rymdbar <https://rymdbar.x20.se/>

Before:
call ale#assert#SetUpLinterTest('perl', 'perlnavigator')

After:
call ale#assert#TearDownLinterTest()

Execute(The default Perl command callback should be correct):
AssertLinter 'perlnavigator',
\ ale#Escape('perlnavigator') . ' --stdio'

Execute(Overriding the executable should work):
let b:ale_perl_perlnavigator_executable = 'plnav'

AssertLinter 'plnav', ale#Escape('plnav') . ' --stdio'
unlet b:ale_perl_perlnavigator_executable

Execute(The project root should be detected correctly in from build files):
for mod in ['extutils-makemaker', 'module-build', 'dist-zilla']
call ale#test#SetFilename('../test-files/perl/' . mod . '/subdir/empty.pl')

AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl/' . mod)
endfor

Execute(The project root should be globally configurable):
for mod in ['extutils-makemaker', 'module-build', 'dist-zilla']
call ale#test#SetFilename('../test-files/perl/'. mod . '/subdir/empty.pl')
" Configuring g:ale_root using a Dictionary works.
let g:ale_root.perlnavigator =
\ ale#path#Simplify(g:dir . '/../test-files/perl')

AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
unlet g:ale_root.perlnavigator
" As tracked by <https://github.com/dense-analysis/ale/issues/5002>, there
" is a bug with g:ale_root which is thus missing here.
endfor

Execute(The project root should be per buffer configurable):
for mod in ['extutils-makemaker', 'module-build', 'dist-zilla']
call ale#test#SetFilename('../test-files/perl/'. mod . '/subdir/empty.pl')
" Configuring b:ale_root using a String works.
let b:ale_root = ale#path#Simplify(g:dir . '/../test-files/perl')

AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
unlet b:ale_root

" Configuring b:ale_root using a Dictionary works.
let b:ale_root = {
\ 'perlnavigator': ale#path#Simplify(g:dir . '/../test-files/perl')
\ }

AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
unlet b:ale_root.perlnavigator
endfor

Execute(The LSP values should be set correctly):

AssertLSPLanguage 'perl'

AssertLSPOptions {}

AssertLSPConfig {}

Execute(Should accept configuration settings):
let b:ale_perl_perlnavigator_config = {
\ 'perlnavigator': {
\ 'perlcriticEnabled': 1,
\ 'perlcriticProfile': '$workspaceFolder/.perlcriticrc',
\ },
\ }

AssertLSPConfig {
\ 'perlnavigator': {
\ 'perlcriticEnabled': 1,
\ 'perlcriticProfile': '$workspaceFolder/.perlcriticrc',
\ },
\ }