mirror of
https://github.com/dense-analysis/ale.git
synced 2026-04-15 04:07:43 +08:00
Add support for PerlNavigator (#5028)
* Add support for PerlNavigator * fixup! Add support for PerlNavigator * fixup! fixup! Add support for PerlNavigator * fixup! fixup! fixup! Add support for PerlNavigator --------- Co-authored-by: cos <cos>
This commit is contained in:
@@ -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
|
||||
@@ -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
ale_linters/perl/perlnavigator.vim
Normal file
15
ale_linters/perl/perlnavigator.vim
Normal file
@@ -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
autoload/ale/handlers/perl.vim
Normal file
24
autoload/ale/handlers/perl.vim
Normal file
@@ -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
|
||||
@@ -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*
|
||||
|
||||
@@ -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*
|
||||
|
||||
|
||||
@@ -482,6 +482,7 @@ Notes:
|
||||
* `languageserver`
|
||||
* `perl -c`
|
||||
* `perl-critic`
|
||||
* `perlnavigator`
|
||||
* `perltidy`
|
||||
* Perl6
|
||||
* `perl6 -c`
|
||||
|
||||
@@ -3807,6 +3807,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|
|
||||
|
||||
@@ -489,9 +489,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:
|
||||
|
||||
78
test/linter/test_perl_perlnavigator.vader
Normal file
78
test/linter/test_perl_perlnavigator.vader
Normal file
@@ -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',
|
||||
\ },
|
||||
\ }
|
||||
Reference in New Issue
Block a user