Report LSP status without autoload false negatives (#20)

This commit is contained in:
m1ngsama 2026-05-13 12:38:32 +08:00 committed by GitHub
parent 1c54077487
commit 097c8abcd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 97 additions and 5 deletions

View file

@ -147,12 +147,58 @@ function! s:Off(name, reason) abort
return ' off ' . a:name . ' (' . a:reason . ')' return ' off ' . a:name . ' (' . a:reason . ')'
endfunction endfunction
function! s:LspCheck(ft, server) abort function! s:PlugDir(name) abort
if !get(g:, 'chopsticks_enable_lsp', 1) if !exists('g:plugs') || !has_key(g:plugs, a:name)
return s:Off(a:ft, 'LSP disabled by profile') return ''
endif endif
if !exists('*lsp#get_server_names') return fnamemodify(get(g:plugs[a:name], 'dir', ''), ':p')
return ' -- ' . a:ft . ' (vim-lsp not loaded)' endfunction
function! s:PlugInstalled(name) abort
let l:dir = s:PlugDir(a:name)
return !empty(l:dir) && isdirectory(l:dir)
endfunction
function! s:LspStackIssue() abort
if !get(g:, 'chopsticks_enable_lsp', 1)
return 'LSP disabled by profile'
endif
if empty(s:PlugDir('vim-lsp'))
return 'vim-lsp not declared by this profile'
endif
if !s:PlugInstalled('vim-lsp')
return 'vim-lsp not installed; run :PlugInstall'
endif
if empty(s:PlugDir('vim-lsp-settings'))
return 'vim-lsp-settings not declared by this profile'
endif
if !s:PlugInstalled('vim-lsp-settings')
return 'vim-lsp-settings not installed; run :PlugInstall'
endif
return ''
endfunction
function! s:LspStackCheck() abort
let l:issue = s:LspStackIssue()
if l:issue ==# 'LSP disabled by profile'
return s:Off('vim-lsp stack', l:issue)
endif
if !empty(l:issue)
return ' -- vim-lsp stack (' . l:issue . ')'
endif
if exists(':LspStatus') == 2 || exists(':LspInstallServer') == 2
return ' OK vim-lsp stack (installed)'
endif
return ' OK vim-lsp stack (installed; not loaded yet)'
endfunction
function! s:LspCheck(ft, server) abort
let l:issue = s:LspStackIssue()
if l:issue ==# 'LSP disabled by profile'
return s:Off(a:ft, l:issue)
endif
if !empty(l:issue)
return ' -- ' . a:ft . ' (' . l:issue . ')'
endif endif
let l:dir = expand('~/.local/share/vim-lsp-settings/servers/' . a:server) let l:dir = expand('~/.local/share/vim-lsp-settings/servers/' . a:server)
if isdirectory(l:dir) if isdirectory(l:dir)
@ -178,6 +224,7 @@ function! s:ChopsticksStatus() abort
call add(l:lines, '') call add(l:lines, '')
call add(l:lines, '── lsp servers ── (:LspInstallServer to install)') call add(l:lines, '── lsp servers ── (:LspInstallServer to install)')
call add(l:lines, s:LspStackCheck())
call add(l:lines, s:LspCheck('python', 'pylsp')) call add(l:lines, s:LspCheck('python', 'pylsp'))
call add(l:lines, s:LspCheck('go', 'gopls')) call add(l:lines, s:LspCheck('go', 'gopls'))
call add(l:lines, s:LspCheck('rust', 'rust-analyzer')) call add(l:lines, s:LspCheck('rust', 'rust-analyzer'))

View file

@ -186,6 +186,51 @@ check_vim() {
-c 'if g:chopsticks_profile !=# "minimal" || has_key(g:plugs, "ale") || has_key(g:plugs, "vim-lsp") | cquit | endif' \ -c 'if g:chopsticks_profile !=# "minimal" || has_key(g:plugs, "ale") || has_key(g:plugs, "vim-lsp") | cquit | endif' \
-c 'qa!' 2>&1 -c 'qa!' 2>&1
XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \
-c 'ChopsticksStatus' \
-c "redir! > $TMP_ROOT/status-default.txt" \
-c 'silent %print' \
-c 'redir END' \
-c 'qa!' 2>&1
if grep -Fq 'vim-lsp not loaded' "$TMP_ROOT/status-default.txt"; then
cat "$TMP_ROOT/status-default.txt"
exit 1
fi
grep -Fq 'OK vim-lsp stack (installed)' "$TMP_ROOT/status-default.txt"
grep -Fq 'python (:LspInstallServer in a python file)' "$TMP_ROOT/status-default.txt"
XDG_CONFIG_HOME="$EMPTY_XDG" vim -u .vimrc -i NONE -es -N \
-c 'silent! delcommand LspStatus' \
-c 'silent! delcommand LspInstallServer' \
-c 'ChopsticksStatus' \
-c "redir! > $TMP_ROOT/status-lsp-not-loaded.txt" \
-c 'silent %print' \
-c 'redir END' \
-c 'qa!' 2>&1
grep -Fq 'OK vim-lsp stack (installed; not loaded yet)' "$TMP_ROOT/status-lsp-not-loaded.txt"
vim -u NONE -i NONE -es -N \
-c 'let g:chopsticks_profile = "minimal"' \
-c 'source .vimrc' \
-c 'ChopsticksStatus' \
-c "redir! > $TMP_ROOT/status-minimal.txt" \
-c 'silent %print' \
-c 'redir END' \
-c 'qa!' 2>&1
grep -Fq 'off vim-lsp stack (LSP disabled by profile)' "$TMP_ROOT/status-minimal.txt"
grep -Fq 'off python (LSP disabled by profile)' "$TMP_ROOT/status-minimal.txt"
mkdir -p "$TMP_ROOT/missing-home/.vim/autoload"
cp "$HOME/.vim/autoload/plug.vim" "$TMP_ROOT/missing-home/.vim/autoload/plug.vim"
HOME="$TMP_ROOT/missing-home" XDG_CONFIG_HOME="$EMPTY_XDG" \
vim -u .vimrc -i NONE -es -N \
-c 'ChopsticksStatus' \
-c "redir! > $TMP_ROOT/status-missing-plugin.txt" \
-c 'silent %print' \
-c 'redir END' \
-c 'qa!' 2>&1
grep -Fq 'vim-lsp not installed; run :PlugInstall' "$TMP_ROOT/status-missing-plugin.txt"
vim -u NONE -i NONE -es -N \ vim -u NONE -i NONE -es -N \
-c 'let g:chopsticks_profile = "minimal"' \ -c 'let g:chopsticks_profile = "minimal"' \
-c 'source .vimrc' \ -c 'source .vimrc' \