Add Perl::LanguageServer to config
This commit is contained in:
parent
816b62b2ae
commit
9f3fd5449d
2 changed files with 37 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
vim9script
|
||||
|
||||
import './tools/perl.vim'
|
||||
|
||||
const lspServers = [
|
||||
{
|
||||
name: 'dockerfile-langserver',
|
||||
|
@ -25,6 +27,8 @@ const lspServers = [
|
|||
install: 'npm install -g perlnavigator-server',
|
||||
},
|
||||
|
||||
perl.Lsp('Perl::LanguageServer', ['-e', 'Perl::LanguageServer::run']),
|
||||
|
||||
{
|
||||
name: 'taplo',
|
||||
filetype: 'toml',
|
||||
|
@ -128,12 +132,16 @@ def ToStringSet(stringList: list<string>): dict<bool>
|
|||
return stringSet
|
||||
enddef
|
||||
|
||||
def IsInstalled(server: dict<any>): bool
|
||||
return server->has_key('installed') ? server.installed() : executable(server.path) == 1
|
||||
enddef
|
||||
|
||||
def InstalledServers(): list<dict<any>>
|
||||
return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 1)
|
||||
return lspServers->deepcopy()->filter((_, server): bool => server->IsInstalled())
|
||||
enddef
|
||||
|
||||
def MissingServers(): list<dict<any>>
|
||||
return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 0)
|
||||
return lspServers->deepcopy()->filter((_, server): bool => !server->isInstalled())
|
||||
enddef
|
||||
|
||||
def ListMissingServers(argLead: string, cmdLine: string, cursorPos: number): list<string>
|
||||
|
|
27
dot-config/vim/tools/perl.vim
Normal file
27
dot-config/vim/tools/perl.vim
Normal file
|
@ -0,0 +1,27 @@
|
|||
vim9script
|
||||
|
||||
export def Lsp(module: string, args: list<string>): dict<any>
|
||||
const lsp = {
|
||||
name: module,
|
||||
filetype: 'perl',
|
||||
path: exepath('perl'),
|
||||
args: [$'-M{module}']->extend(args),
|
||||
install: $'cpanm {module}',
|
||||
installed: (): bool => HasModule(module),
|
||||
}
|
||||
return lsp
|
||||
enddef
|
||||
|
||||
export def HasModule(module: string): bool
|
||||
# This can more reliably be tested by calling `perl -MModule::Name -E ''`
|
||||
# and checking the exit status, but simply looking for a matching file on
|
||||
# disk is much faster and works fine for my purposes.
|
||||
const libs = $PERL5LIB->split(';')
|
||||
const filename = module->substitute('::', '/', 'g') .. '.pm'
|
||||
for lib in libs
|
||||
if filereadable($'{lib}/{filename}')
|
||||
return true
|
||||
endif
|
||||
endfor
|
||||
return false
|
||||
enddef
|
Loading…
Reference in a new issue