Compare commits
2 commits
4e365962ba
...
9f3fd5449d
Author | SHA1 | Date | |
---|---|---|---|
9f3fd5449d | |||
|
816b62b2ae |
3 changed files with 40 additions and 12 deletions
|
@ -105,7 +105,7 @@ import "./statusline.vim"
|
|||
statusline.Init()
|
||||
|
||||
import "./lsp.vim"
|
||||
lsp.LazyConfigure()
|
||||
lsp.Configure()
|
||||
|
||||
set formatexpr=lsp#lsp#FormatExpr()
|
||||
set keywordprg=:LspHover
|
||||
|
|
|
@ -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,25 +132,22 @@ 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>
|
||||
return MissingServers()->mapnew((_, server): string => server.name)
|
||||
enddef
|
||||
|
||||
export def LazyConfigure(): void
|
||||
augroup lspLazyConfigure
|
||||
autocmd!
|
||||
autocmd VimEnter * ++once Configure()
|
||||
augroup END
|
||||
enddef
|
||||
|
||||
export def Configure(): void
|
||||
# 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.
|
||||
|
@ -154,8 +155,8 @@ export def Configure(): void
|
|||
if len(lspServers) != len(installedServers)
|
||||
echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.'
|
||||
endif
|
||||
g:LspAddServer(installedServers)
|
||||
g:LspOptionsSet(lspOptions)
|
||||
g:lsp#lsp#AddServer(installedServers)
|
||||
g:lsp#options#OptionsSet(lspOptions)
|
||||
enddef
|
||||
|
||||
export def Install(...serverNames: list<string>): void
|
||||
|
|
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