From 3720e616744ba2f569051944980c893fb4a48ba9 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 9 Oct 2023 12:01:54 +1100 Subject: [PATCH] More idiomatically vim9script the LSP setup --- config/vim/init.vim | 4 ++-- config/vim/lsp.vim | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/config/vim/init.vim b/config/vim/init.vim index 0c0b52d..7ecff4a 100644 --- a/config/vim/init.vim +++ b/config/vim/init.vim @@ -104,6 +104,6 @@ g:mucomplete#can_complete = { } } +import "./lsp.vim" set keywordprg=:LspHover - -source $XDG_CONFIG_HOME/vim/lsp.vim +lsp.LazyConfigure() diff --git a/config/vim/lsp.vim b/config/vim/lsp.vim index b043fbf..20cfa0d 100644 --- a/config/vim/lsp.vim +++ b/config/vim/lsp.vim @@ -65,17 +65,21 @@ const lspOptions = { aleSupport: true, } -autocmd VimEnter * ++once { +export def LazyConfigure(): void + autocmd VimEnter * ++once Configure() +enddef + +export def Configure(): void + g:LspAddServer(lspServers->deepcopy()->filter((_, server) => executable(server.path) == 1)) + g:LspOptionsSet(lspOptions) +enddef + +export def Install(): void # TODO: work out a way nicer approach to automatically installing any # missing language servers. Maybe use a command or something. const missing = lspServers->copy() - ->filter((_, server) => !executable(server.path)) + ->filter((_, server) => executable(server.path) == 0) const jobs = missing->copy() ->mapnew((_, server) => async#job#start(server.install, {normalize: 'raw'})) async#job#wait(jobs) - # :call is required here because these functions from vim-lsp won't be - # loaded yet when this file is parsed by Vim, so you get a "function not - # found" error if you try to call them the short way. - call LspAddServer(lspServers->deepcopy()->filter((_, server) => executable(server.path))) - call LspOptionsSet(lspOptions) -} +enddef