Skip to content

Commit a6d0ac0

Browse files
author
cos
committed
Add support for PerlNavigator
1 parent a083d58 commit a6d0ac0

File tree

8 files changed

+163
-18
lines changed

8 files changed

+163
-18
lines changed

ale_linters/perl/languageserver.vim

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@
55
call ale#Set('perl_perl_executable', 'perl')
66
" Please note that perl_perl_options does not exist here.
77

8-
function! ale_linters#perl#languageserver#GetProjectRoot(buffer) abort
9-
" Makefile.PL, https://perldoc.perl.org/ExtUtils::MakeMaker
10-
" Build.PL, https://metacpan.org/pod/Module::Build
11-
" dist.ini, https://metacpan.org/pod/Dist::Zilla
12-
let l:potential_roots = [ 'Makefile.PL', 'Build.PL', 'dist.ini', '.git' ]
13-
14-
for l:root in l:potential_roots
15-
let l:project_root = ale#path#FindNearestFile(a:buffer, l:root)
16-
17-
if !empty(l:project_root)
18-
return fnamemodify(l:project_root . '/', ':p:h:h')
19-
endif
20-
endfor
21-
22-
return fnamemodify(expand('#' . a:buffer . ':p:h'), ':p:h')
23-
endfunction
24-
258
call ale#Set('perl_languageserver_config', {})
269

2710
function! s:get_lsp_config(buffer) abort
@@ -39,5 +22,5 @@ call ale#linter#Define('perl', {
3922
\ 'executable': {b -> ale#Var(b, 'perl_perl_executable')},
4023
\ 'command': '%e -MPerl::LanguageServer -ePerl::LanguageServer::run',
4124
\ 'lsp_config': {b -> s:get_lsp_config(b)},
42-
\ 'project_root': function('ale_linters#perl#languageserver#GetProjectRoot'),
25+
\ 'project_root': function('ale#handlers#perl#GetProjectRoot'),
4326
\ })

ale_linters/perl/perlnavigator.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
" Author: rymdbar <https://rymdbar.x20.se/>
2+
" Description: Perl Navigator Language Server
3+
" See: https://github.com/bscan/PerlNavigator
4+
5+
call ale#Set('perl_perlnavigator_config', {})
6+
call ale#Set('perl_perlnavigator_executable', 'perlnavigator')
7+
8+
call ale#linter#Define('perl', {
9+
\ 'name': 'perlnavigator',
10+
\ 'lsp': 'stdio',
11+
\ 'executable': {b -> ale#Var(b, 'perl_perlnavigator_executable')},
12+
\ 'command': '%e --stdio',
13+
\ 'lsp_config': {b -> ale#Var(b, 'perl_perlnavigator_config')},
14+
\ 'project_root': function('ale#handlers#perl#GetProjectRoot'),
15+
\ })

autoload/ale/handlers/perl.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
" Author: rymdbar <https://rymdbar.x20.se/>
2+
3+
function! ale#handlers#perl#GetProjectRoot(buffer) abort
4+
" Makefile.PL, https://perldoc.perl.org/ExtUtils::MakeMaker
5+
" Build.PL, https://metacpan.org/pod/Module::Build
6+
" dist.ini, https://metacpan.org/pod/Dist::Zilla
7+
let l:potential_roots = [ 'Makefile.PL', 'Build.PL', 'dist.ini', '.git' ]
8+
9+
for l:root in l:potential_roots
10+
let l:project_root = ale#path#FindNearestFile(a:buffer, l:root)
11+
12+
if !empty(l:project_root)
13+
return fnamemodify(l:project_root . '/', ':p:h:h')
14+
endif
15+
endfor
16+
17+
return fnamemodify(expand('#' . a:buffer . ':p:h'), ':p:h')
18+
endfunction
19+

doc/ale-perl.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,53 @@ g:ale_perl_languageserver_config
7171
https://metacpan.org/pod/Perl::LanguageServer#Extension-Settings
7272

7373

74+
===============================================================================
75+
perlnavigator *ale-perl-perlnavigator*
76+
77+
*ale-options.perl_perlnavigator_executable*
78+
*g:perl_perlnavigator_executable*
79+
*b:perl_perlnavigator_executable*
80+
perl_perlnavigator_executable
81+
g:perl_perlnavigator_executable
82+
Type: |String|
83+
Default: `'perlnavigator'`
84+
85+
This variable can be changed to modify the perlnavigator executable used for
86+
linting perl.
87+
88+
*ale-options.perl_perlnavigator_config*
89+
*g:perl_perlnavigator_config*
90+
*b:perl_perlnavigator_config*
91+
perl_perlnavigator_config
92+
g:perl_perlnavigator_config
93+
Type: |Dictionary|
94+
Default: `'{}'`
95+
96+
This variable can be changed to customize the lsp_config (sent as a
97+
workspace/didChangeConfiguration command) for perlnavigator.
98+
For example: >
99+
100+
let g:ale_perl_perlnavigator_config = {
101+
\ 'perlnavigator': {
102+
\ 'enableWarnings': 1,
103+
\ 'includePaths': [ $HOME . '/MyPerlStuff/lib', '/tmp/tmp.7qSgUo34e' ],
104+
\ 'perlEnvAdd': 1,
105+
\ 'perlEnv': {
106+
\ 'PERL_DL_NONLAZY': 1,
107+
\ },
108+
\ 'perlPath': substitute(g:ale_perl_perl_executable, '/perl$', '', ''),
109+
\ 'perlcriticEnabled': 1,
110+
\ 'perlcriticProfile': '$workspaceFolder/.perlcriticrc',
111+
\ 'perltidyProfile': '$workspaceFolder/.perltidyrc',
112+
\ 'perlcriticSeverity': 2,
113+
\ },
114+
\ }
115+
\}
116+
117+
<
118+
For all available options and explanations, visit
119+
https://github.com/bscan/PerlNavigator?tab=readme-ov-file
120+
74121
===============================================================================
75122
perlcritic *ale-perl-perlcritic*
76123

doc/ale-supported-languages-and-tools.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ Notes:
476476
* `languageserver`
477477
* `perl -c`
478478
* `perl-critic`
479+
* `perlnavigator`
479480
* `perltidy`
480481
* Perl6
481482
* `perl6 -c`

doc/ale.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,6 +3752,7 @@ documented in additional help files.
37523752
perl....................................|ale-perl-options|
37533753
perl..................................|ale-perl-perl|
37543754
perl language server..................|ale-perl-languageserver|
3755+
perlnavigator.........................|ale-perl-perlnavigator|
37553756
perlcritic............................|ale-perl-perlcritic|
37563757
perltidy..............................|ale-perl-perltidy|
37573758
perl6...................................|ale-perl6-options|

supported-tools.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ formatting.
486486
* [languageserver](https://metacpan.org/pod/Perl::LanguageServer)
487487
* [perl -c](https://perl.org/) :warning:
488488
* [perl-critic](https://metacpan.org/pod/Perl::Critic)
489+
* [languagenavigator](https://github.com/bscan/PerlNavigator)
489490
* [perltidy](https://metacpan.org/pod/distribution/Perl-Tidy/bin/perltidy)
490491
* Perl6
491492
* [perl6 -c](https://perl6.org) :warning:
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
" Author: rymdbar <https://rymdbar.x20.se/>
2+
3+
Before:
4+
call ale#assert#SetUpLinterTest('perl', 'perlnavigator')
5+
6+
After:
7+
call ale#assert#TearDownLinterTest()
8+
9+
Execute(The default Perl command callback should be correct):
10+
AssertLinter 'perlnavigator',
11+
\ ale#Escape('perlnavigator') . ' --stdio'
12+
13+
Execute(Overriding the executable should work):
14+
let b:ale_perl_perlnavigator_executable = 'plnav'
15+
16+
AssertLinter 'plnav', ale#Escape('plnav') . ' --stdio'
17+
unlet b:ale_perl_perlnavigator_executable
18+
19+
Execute(The project root should be detected correctly in from build files):
20+
for mod in ['extutils-makemaker', 'module-build', 'dist-zilla']
21+
call ale#test#SetFilename('../test-files/perl/' . mod . '/subdir/empty.pl')
22+
23+
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl/' . mod)
24+
endfor
25+
26+
Execute(The project root should be globally configurable):
27+
for mod in ['extutils-makemaker', 'module-build', 'dist-zilla']
28+
call ale#test#SetFilename('../test-files/perl/'. mod . '/subdir/empty.pl')
29+
" Configuring g:ale_root using a Dictionary works.
30+
let g:ale_root.perlnavigator =
31+
\ ale#path#Simplify(g:dir . '/../test-files/perl')
32+
33+
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
34+
unlet g:ale_root.perlnavigator
35+
" As tracked by <https://github.com/dense-analysis/ale/issues/5002>, there
36+
" is a bug with g:ale_root which is thus missing here.
37+
endfor
38+
39+
Execute(The project root should be per buffer configurable):
40+
for mod in ['extutils-makemaker', 'module-build', 'dist-zilla']
41+
call ale#test#SetFilename('../test-files/perl/'. mod . '/subdir/empty.pl')
42+
" Configuring b:ale_root using a String works.
43+
let b:ale_root = ale#path#Simplify(g:dir . '/../test-files/perl')
44+
45+
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
46+
unlet b:ale_root
47+
48+
" Configuring b:ale_root using a Dictionary works.
49+
let b:ale_root = {
50+
\ 'perlnavigator': ale#path#Simplify(g:dir . '/../test-files/perl')
51+
\ }
52+
53+
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/perl')
54+
unlet b:ale_root.perlnavigator
55+
endfor
56+
57+
Execute(The LSP values should be set correctly):
58+
59+
AssertLSPLanguage 'perl'
60+
61+
AssertLSPOptions {}
62+
63+
AssertLSPConfig {}
64+
65+
Execute(Should accept configuration settings):
66+
let b:ale_perl_perlnavigator_config = {
67+
\ 'perlnavigator': {
68+
\ 'perlcriticEnabled': 1,
69+
\ 'perlcriticProfile': '$workspaceFolder/.perlcriticrc',
70+
\ },
71+
\ }
72+
73+
AssertLSPConfig {
74+
\ 'perlnavigator': {
75+
\ 'perlcriticEnabled': 1,
76+
\ 'perlcriticProfile': '$workspaceFolder/.perlcriticrc',
77+
\ },
78+
\ }

0 commit comments

Comments
 (0)