diff --git a/dot-config/vim/lsp.vim b/dot-config/vim/lsp.vim index 7aa7efb..3cfdbfa 100644 --- a/dot-config/vim/lsp.vim +++ b/dot-config/vim/lsp.vim @@ -1,6 +1,5 @@ vim9script -import './tools/strings.vim' import './tools/perl.vim' const lspServers = [ @@ -122,6 +121,17 @@ const lspOptions = { command! -nargs=* -complete=customlist,ListMissingServers -bar LspInstall Install() +# Convert a list of strings to a dictionary containing those same strings as +# keys, approximating a set type. You can use has_key() to test set membership +# on the result, rather than index(). +def ToStringSet(stringList: list): dict + var stringSet: dict + for string in stringList + stringSet[string] = true + endfor + return stringSet +enddef + def IsInstalled(server: dict): bool return server->has_key('installed') ? server.installed() : executable(server.path) == 1 enddef @@ -143,17 +153,8 @@ export def Configure(): void # modify the dicts it gets, rather than making a fresh copy to mess with. final installedServers = InstalledServers() if len(lspServers) != len(installedServers) - # Since this code runs during Vim initialisation, this message would - # normally pause Vim's startup so the user can read it. We don't want - # that, so we're gonna delay it using an autocmd. - const missingCount = len(lspServers) - len(installedServers) - const warn = $'{missingCount} language server{missingCount > 1 ? "s are" : " is"} configured, but not installed. You may want to run :LspInstall.' - augroup dot/vim/lsp.vim - autocmd! - exe $'autocmd VimEnter * ++once echo {strings.Quote(warn)}' - augroup END + echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.' endif - g:lsp#lsp#AddServer(installedServers) g:lsp#options#OptionsSet(lspOptions) enddef @@ -166,7 +167,7 @@ export def Install(...serverNames: list): void return endif - const serverNamesSet = strings.ToStringSet(serverNames) + const serverNamesSet = ToStringSet(serverNames) const serversToInstall = empty(serverNamesSet) ? missingServers : missingServers->copy()->filter((_, server): bool => serverNamesSet->has_key(server.name)) diff --git a/dot-config/vim/statusline.vim b/dot-config/vim/statusline.vim index e0705c9..33d9531 100644 --- a/dot-config/vim/statusline.vim +++ b/dot-config/vim/statusline.vim @@ -1,7 +1,27 @@ vim9script import autoload ($XDG_CACHE_HOME .. '/vim/pack/minpac/start/vim-crystalline/autoload/crystalline.vim') as cr -import './tools/strings.vim' as st + +def DropIfDefault(status: string, default: string): string + if status == default + return '' + endif + return status +enddef + +def PrependIfVisible(status: string, prefix: string): string + if empty(status) + return '' + endif + return prefix .. status +enddef + +def AppendIfVisible(status: string, affix: string): string + if empty(status) + return '' + endif + return status .. affix +enddef def StatuslineSection(seps: number, group: string, components: list): string const hiGroup = cr.ModeGroup(group) @@ -14,21 +34,21 @@ def GitStatus(): string return '' endif - const branch = g:FugitiveHead()->st.PrependIfVisible("\ue0a0 ") # nf-pl-branch + const branch = g:FugitiveHead()->PrependIfVisible("\ue0a0 ") # nf-pl-branch if !empty(branch) return branch endif return g:FugitiveHead(7) - ->st.PrependIfVisible("\Uf135e (") # nf-md-head - ->st.AppendIfVisible(")") + ->PrependIfVisible("\Uf135e (") # nf-md-head + ->AppendIfVisible(")") enddef def StatuslineLeft(window: number, inactive: bool): string const bufnr = window->winbufnr() const b = bufnr->getbufvar('&') const fileName = [ - bufname(bufnr)->g:nerdfont#find()->st.DropIfDefault(g:nerdfont#default)->st.AppendIfVisible(' '), + bufname(bufnr)->g:nerdfont#find()->DropIfDefault(g:nerdfont#default)->AppendIfVisible(' '), b.buftype == '' ? '%t' : '%f', b.modifiable && b.modified ? cr.ModeHiItem('Modified') .. '+' .. cr.ModeHiItem('Fill') : '', b.readonly ? " \uf023" : '', # nf-fa-lock @@ -40,7 +60,7 @@ def StatuslineLeft(window: number, inactive: bool): string const info = StatuslineSection(0, 'B', [ GitStatus(), g:battery#component_escaped(), - ])->st.AppendIfVisible(' ' .. cr.Sep(0, cr.ModeGroup('B'), cr.ModeGroup('Fill'))) + ])->AppendIfVisible(' ' .. cr.Sep(0, cr.ModeGroup('B'), cr.ModeGroup('Fill'))) const vimMode = cr.ModeSection(0, 'A', empty(info) ? 'Fill' : 'B') return join([vimMode, info, fileName]) @@ -93,7 +113,7 @@ def InitTab() width += 2 endif - const icon = bufname(bufnr)->g:nerdfont#find()->st.DropIfDefault(g:nerdfont#default)->st.PrependIfVisible(' ') + const icon = bufname(bufnr)->g:nerdfont#find()->DropIfDefault(g:nerdfont#default)->PrependIfVisible(' ') const iconWidth = strchars(icon) if width + iconWidth >= maxWidth return [tabDisplay, width] diff --git a/dot-config/vim/tools/strings.vim b/dot-config/vim/tools/strings.vim deleted file mode 100644 index 36b2840..0000000 --- a/dot-config/vim/tools/strings.vim +++ /dev/null @@ -1,49 +0,0 @@ -vim9script - -# Convert a list of strings to a dictionary containing those same strings as -# keys, approximating a set type. You can use has_key() to test set membership -# on the result, rather than index(). -export def ToStringSet(stringList: list): dict - var stringSet: dict - for string in stringList - stringSet[string] = true - endfor - return stringSet -enddef - - -# Returns the given status if it's not the same string as the provided -# 'default'. Otherwise returns an empty string. -export def DropIfDefault(status: string, default: string): string - if status == default - return '' - endif - return status -enddef - -# Prepends the given prefix to the status, but only when the status is -# non-empty. Very useful for constructing a statusline with optional segments. -export def PrependIfVisible(status: string, prefix: string): string - if empty(status) - return '' - endif - return prefix .. status -enddef - -# Appends the given affix to the status, but only when the status is -# non-empty. Quite similar to PrependIfVisible, and useful in the same sorts -# of situations. -export def AppendIfVisible(status: string, affix: string): string - if empty(status) - return '' - endif - return status .. affix -enddef - -# Double-quotes a string, so it can safely be substituted into a Vim command -# with :execute or eval() and be interpreted as the same string. -export def Quote(str: string): string - return '"' .. escape(str, '"\\') .. '"' -enddef - -defcompile