diff --git a/modules/tools.vim b/modules/tools.vim index 05fddfd..962c491 100644 --- a/modules/tools.vim +++ b/modules/tools.vim @@ -147,12 +147,58 @@ function! s:Off(name, reason) abort return ' off ' . a:name . ' (' . a:reason . ')' endfunction -function! s:LspCheck(ft, server) abort - if !get(g:, 'chopsticks_enable_lsp', 1) - return s:Off(a:ft, 'LSP disabled by profile') +function! s:PlugDir(name) abort + if !exists('g:plugs') || !has_key(g:plugs, a:name) + return '' endif - if !exists('*lsp#get_server_names') - return ' -- ' . a:ft . ' (vim-lsp not loaded)' + return fnamemodify(get(g:plugs[a:name], 'dir', ''), ':p') +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 let l:dir = expand('~/.local/share/vim-lsp-settings/servers/' . a:server) if isdirectory(l:dir) @@ -178,6 +224,7 @@ function! s:ChopsticksStatus() abort call add(l:lines, '') 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('go', 'gopls')) call add(l:lines, s:LspCheck('rust', 'rust-analyzer')) diff --git a/scripts/test.sh b/scripts/test.sh index d2287e4..abb3d13 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -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 '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 \ -c 'let g:chopsticks_profile = "minimal"' \ -c 'source .vimrc' \