Compare commits

..

No commits in common. "6d7037d88ecaaf0c67569ef5963e23fc1c6b0d07" and "e41768aa343bb0c9ea81e0f213219857eb497ec0" have entirely different histories.

3 changed files with 40 additions and 68 deletions

View file

@ -1,6 +1,5 @@
vim9script vim9script
import './tools/strings.vim'
import './tools/perl.vim' import './tools/perl.vim'
const lspServers = [ const lspServers = [
@ -122,6 +121,17 @@ const lspOptions = {
command! -nargs=* -complete=customlist,ListMissingServers -bar LspInstall Install(<f-args>) command! -nargs=* -complete=customlist,ListMissingServers -bar LspInstall Install(<f-args>)
# 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<string>): dict<bool>
var stringSet: dict<bool>
for string in stringList
stringSet[string] = true
endfor
return stringSet
enddef
def IsInstalled(server: dict<any>): bool def IsInstalled(server: dict<any>): bool
return server->has_key('installed') ? server.installed() : executable(server.path) == 1 return server->has_key('installed') ? server.installed() : executable(server.path) == 1
enddef enddef
@ -143,17 +153,8 @@ export def Configure(): void
# 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.
final installedServers = InstalledServers() final installedServers = InstalledServers()
if len(lspServers) != len(installedServers) if len(lspServers) != len(installedServers)
# Since this code runs during Vim initialisation, this message would echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.'
# 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
endif endif
g:lsp#lsp#AddServer(installedServers) g:lsp#lsp#AddServer(installedServers)
g:lsp#options#OptionsSet(lspOptions) g:lsp#options#OptionsSet(lspOptions)
enddef enddef
@ -166,7 +167,7 @@ export def Install(...serverNames: list<string>): void
return return
endif endif
const serverNamesSet = strings.ToStringSet(serverNames) const serverNamesSet = ToStringSet(serverNames)
const serversToInstall = empty(serverNamesSet) const serversToInstall = empty(serverNamesSet)
? missingServers ? missingServers
: missingServers->copy()->filter((_, server): bool => serverNamesSet->has_key(server.name)) : missingServers->copy()->filter((_, server): bool => serverNamesSet->has_key(server.name))

View file

@ -1,7 +1,27 @@
vim9script vim9script
import autoload ($XDG_CACHE_HOME .. '/vim/pack/minpac/start/vim-crystalline/autoload/crystalline.vim') as cr 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>): string def StatuslineSection(seps: number, group: string, components: list<string>): string
const hiGroup = cr.ModeGroup(group) const hiGroup = cr.ModeGroup(group)
@ -14,21 +34,21 @@ def GitStatus(): string
return '' return ''
endif endif
const branch = g:FugitiveHead()->st.PrependIfVisible("\ue0a0 ") # nf-pl-branch const branch = g:FugitiveHead()->PrependIfVisible("\ue0a0 ") # nf-pl-branch
if !empty(branch) if !empty(branch)
return branch return branch
endif endif
return g:FugitiveHead(7) return g:FugitiveHead(7)
->st.PrependIfVisible("\Uf135e (") # nf-md-head ->PrependIfVisible("\Uf135e (") # nf-md-head
->st.AppendIfVisible(")") ->AppendIfVisible(")")
enddef enddef
def StatuslineLeft(window: number, inactive: bool): string def StatuslineLeft(window: number, inactive: bool): string
const bufnr = window->winbufnr() const bufnr = window->winbufnr()
const b = bufnr->getbufvar('&') const b = bufnr->getbufvar('&')
const fileName = [ 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.buftype == '' ? '%t' : '%f',
b.modifiable && b.modified ? cr.ModeHiItem('Modified') .. '+' .. cr.ModeHiItem('Fill') : '', b.modifiable && b.modified ? cr.ModeHiItem('Modified') .. '+' .. cr.ModeHiItem('Fill') : '',
b.readonly ? " \uf023" : '', # nf-fa-lock b.readonly ? " \uf023" : '', # nf-fa-lock
@ -40,7 +60,7 @@ def StatuslineLeft(window: number, inactive: bool): string
const info = StatuslineSection(0, 'B', [ const info = StatuslineSection(0, 'B', [
GitStatus(), GitStatus(),
g:battery#component_escaped(), 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') const vimMode = cr.ModeSection(0, 'A', empty(info) ? 'Fill' : 'B')
return join([vimMode, info, fileName]) return join([vimMode, info, fileName])
@ -93,7 +113,7 @@ def InitTab()
width += 2 width += 2
endif 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) const iconWidth = strchars(icon)
if width + iconWidth >= maxWidth if width + iconWidth >= maxWidth
return [tabDisplay, width] return [tabDisplay, width]

View file

@ -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<string>): dict<bool>
var stringSet: dict<bool>
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