Add Perl::LanguageServer to config

This commit is contained in:
Danielle McLean 2023-10-24 15:01:43 +11:00 committed by Danielle McLean
parent 816b62b2ae
commit 9f3fd5449d
Signed by: 00dani
GPG key ID: 52C059C3B22A753E
2 changed files with 37 additions and 2 deletions

View file

@ -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>

View 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