Compare commits

..

No commits in common. "9f3fd5449d02d84c21ae7cfbffa0246ad38a2136" and "4e365962baf5ee455c1b9946d550927f8a35d0c3" have entirely different histories.

3 changed files with 12 additions and 40 deletions

View file

@ -105,7 +105,7 @@ import "./statusline.vim"
statusline.Init() statusline.Init()
import "./lsp.vim" import "./lsp.vim"
lsp.Configure() lsp.LazyConfigure()
set formatexpr=lsp#lsp#FormatExpr() set formatexpr=lsp#lsp#FormatExpr()
set keywordprg=:LspHover set keywordprg=:LspHover

View file

@ -1,7 +1,5 @@
vim9script vim9script
import './tools/perl.vim'
const lspServers = [ const lspServers = [
{ {
name: 'dockerfile-langserver', name: 'dockerfile-langserver',
@ -27,8 +25,6 @@ const lspServers = [
install: 'npm install -g perlnavigator-server', install: 'npm install -g perlnavigator-server',
}, },
perl.Lsp('Perl::LanguageServer', ['-e', 'Perl::LanguageServer::run']),
{ {
name: 'taplo', name: 'taplo',
filetype: 'toml', filetype: 'toml',
@ -132,22 +128,25 @@ def ToStringSet(stringList: list<string>): dict<bool>
return stringSet return stringSet
enddef enddef
def IsInstalled(server: dict<any>): bool
return server->has_key('installed') ? server.installed() : executable(server.path) == 1
enddef
def InstalledServers(): list<dict<any>> def InstalledServers(): list<dict<any>>
return lspServers->deepcopy()->filter((_, server): bool => server->IsInstalled()) return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 1)
enddef enddef
def MissingServers(): list<dict<any>> def MissingServers(): list<dict<any>>
return lspServers->deepcopy()->filter((_, server): bool => !server->isInstalled()) return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 0)
enddef enddef
def ListMissingServers(argLead: string, cmdLine: string, cursorPos: number): list<string> def ListMissingServers(argLead: string, cmdLine: string, cursorPos: number): list<string>
return MissingServers()->mapnew((_, server): string => server.name) return MissingServers()->mapnew((_, server): string => server.name)
enddef enddef
export def LazyConfigure(): void
augroup lspLazyConfigure
autocmd!
autocmd VimEnter * ++once Configure()
augroup END
enddef
export def Configure(): void export def Configure(): void
# We have to use final rather than const because LspAddServer() assumes it can # We have to use final rather than const because LspAddServer() assumes it can
# modify the dicts it gets, rather than making a fresh copy to mess with. # modify the dicts it gets, rather than making a fresh copy to mess with.
@ -155,8 +154,8 @@ export def Configure(): void
if len(lspServers) != len(installedServers) if len(lspServers) != len(installedServers)
echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.' echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.'
endif endif
g:lsp#lsp#AddServer(installedServers) g:LspAddServer(installedServers)
g:lsp#options#OptionsSet(lspOptions) g:LspOptionsSet(lspOptions)
enddef enddef
export def Install(...serverNames: list<string>): void export def Install(...serverNames: list<string>): void

View file

@ -1,27 +0,0 @@
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