From be18563c9a1c1fcd80eef702883a8443d8bac42e Mon Sep 17 00:00:00 2001 From: xs Date: Mon, 9 Nov 2026 00:50:43 +0800 Subject: vimrc: find language servers on $PATH (exepath) instead of hardcoded install paths --- core/vimrc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'core') diff --git a/core/vimrc b/core/vimrc index 8c43954..4ae28ad 100644 --- a/core/vimrc +++ b/core/vimrc @@ -225,26 +225,27 @@ augroup rust_detached \ && empty(RustCrate()) && s:RustAddDetached() \ | call lsp#update_workspace_config('rust-analyzer', {'rust-analyzer': g:ra_init}) | endif augroup END -" rust-analyzer via the rustup proxy shim (portable across toolchains/machines) -if executable(expand('~/.cargo/bin/rust-analyzer')) +" Language servers are looked up on $PATH (exepath); a server that isn't on $PATH is skipped +" rust-analyzer: normally the rustup proxy shim (portable across toolchains/machines) +let s:ra = exepath('rust-analyzer') +if !empty(s:ra) au User lsp_setup call lsp#register_server({ \ 'name': 'rust-analyzer', 'allowlist': ['rust'], - \ 'cmd': {server_info -> [expand('~/.cargo/bin/rust-analyzer')]}, + \ 'cmd': {server_info -> [s:ra]}, \ 'root_uri': {server_info -> lsp#utils#path_to_uri(RustRoot())}, \ 'initialization_options': g:ra_init, \ 'workspace_config': {'rust-analyzer': g:ra_init}}) endif -if executable(expand('~/.local/bin/ruff')) +let s:ruff = exepath('ruff') +if !empty(s:ruff) au User lsp_setup call lsp#register_server({ \ 'name': 'ruff', - \ 'cmd': {server_info -> [expand('~/.local/bin/ruff'), 'server']}, + \ 'cmd': {server_info -> [s:ruff, 'server']}, \ 'allowlist': ['python'], \ }) endif -let s:uv_bin = has('macunix') && executable('/opt/homebrew/bin/uv') - \ ? '/opt/homebrew/bin/uv' - \ : expand('~/.local/bin/uv') -if executable(expand('~/.local/bin/ty')) && executable(s:uv_bin) +let s:uv_bin = exepath('uv') +if !empty(exepath('ty')) && !empty(s:uv_bin) " Launched through `uv run` (not the raw path) so it picks up whichever " project's .venv is active via cwd/VIRTUAL_ENV. au User lsp_setup call lsp#register_server({ @@ -254,18 +255,20 @@ if executable(expand('~/.local/bin/ty')) && executable(s:uv_bin) \ }) endif " tofu-ls (OpenTofu/Terraform .tf) for go-to-definition -if executable(expand('~/.local/bin/tofu-ls')) +let s:tofu_ls = exepath('tofu-ls') +if !empty(s:tofu_ls) au User lsp_setup call lsp#register_server({ \ 'name': 'tofu-ls', - \ 'cmd': {server_info -> [expand('~/.local/bin/tofu-ls'), 'serve']}, + \ 'cmd': {server_info -> [s:tofu_ls, 'serve']}, \ 'allowlist': ['terraform', 'terraform-vars'], \ }) endif " gopls (Go) for go-to-definition -if executable(expand('~/go/bin/gopls')) +let s:gopls = exepath('gopls') +if !empty(s:gopls) au User lsp_setup call lsp#register_server({ \ 'name': 'gopls', - \ 'cmd': {server_info -> [expand('~/go/bin/gopls')]}, + \ 'cmd': {server_info -> [s:gopls]}, \ 'allowlist': ['go'], \ 'root_uri': {server_info -> lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'go.mod'))}, \ }) -- cgit