From dc1ff54f7290a42ae440389141401b78ed76d473 Mon Sep 17 00:00:00 2001 From: xs Date: Tue, 3 Nov 2026 19:53:33 +0800 Subject: vimrc: no cargo check on standalone .rs files cargo check on a file without Cargo.toml needs nightly -Zscript, so rust-analyzer's checkOnSave warned on every save. Turn it off when the server starts on a standalone file. Co-Authored-By: Claude Opus 5.5 --- core/vimrc | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/core/vimrc b/core/vimrc index a2b40c4..06d1782 100644 --- a/core/vimrc +++ b/core/vimrc @@ -181,6 +181,16 @@ endfunction " else it loads nothing for them (no gd/completion). The list is shared by reference with " the init options below (covers the first file) and pushed as config for later files. let g:ra_detached = [] +" checkOnSave runs `cargo check` on the file, which needs nightly -Zscript for a file with +" no Cargo.toml; RustDetach turns it off when the server starts on a standalone file. +let g:ra_init = { + \ 'completion': { + \ 'autoimport': { 'enable': v:true }, + \ 'postfix': { 'enable': v:true }, + \ }, + \ 'checkOnSave': v:true, + \ 'detachedFiles': g:ra_detached, + \ } function! RustDetach() abort if !exists('g:lsp_loaded') return @@ -190,6 +200,9 @@ function! RustDetach() abort return endif call add(g:ra_detached, l:p) + if lsp#get_server_status('rust-analyzer') !~# '^\(running\|starting\)$' + let g:ra_init['checkOnSave'] = v:false + endif if lsp#get_server_status('rust-analyzer') ==# 'running' call lsp#update_workspace_config('rust-analyzer', {'rust-analyzer': {'detachedFiles': copy(g:ra_detached)}}) endif @@ -206,14 +219,7 @@ if executable(expand('~/.cargo/bin/rust-analyzer')) \ 'cmd': {server_info -> [expand('~/.cargo/bin/rust-analyzer')]}, \ 'allowlist': ['rust'], \ 'root_uri': {server_info -> lsp#utils#path_to_uri(RustRoot())}, - \ 'initialization_options': { - \ 'completion': { - \ 'autoimport': { 'enable': v:true }, - \ 'postfix': { 'enable': v:true }, - \ }, - \ 'checkOnSave': v:true, - \ 'detachedFiles': g:ra_detached, - \ }, + \ 'initialization_options': g:ra_init, \ 'workspace_config': {'rust-analyzer': {'detachedFiles': g:ra_detached}}, \ }) endif -- cgit