diff options
| author | xs <xs@xs.local> | 2026-11-03 19:53:33 +0800 |
|---|---|---|
| committer | xs <xs@xs.local> | 2026-11-05 10:45:32 +0800 |
| commit | dc1ff54f7290a42ae440389141401b78ed76d473 (patch) | |
| tree | f5f0b3133b0cdcf791e8838bb989e558ca60ac6d /core/vimrc | |
| parent | be7440b5c365303865ebf7a3c437039e96c170c1 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'core/vimrc')
| -rw-r--r-- | core/vimrc | 22 |
1 files changed, 14 insertions, 8 deletions
| @@ -181,6 +181,16 @@ endfunction | |||
| 181 | " else it loads nothing for them (no gd/completion). The list is shared by reference with | 181 | " else it loads nothing for them (no gd/completion). The list is shared by reference with |
| 182 | " the init options below (covers the first file) and pushed as config for later files. | 182 | " the init options below (covers the first file) and pushed as config for later files. |
| 183 | let g:ra_detached = [] | 183 | let g:ra_detached = [] |
| 184 | " checkOnSave runs `cargo check` on the file, which needs nightly -Zscript for a file with | ||
| 185 | " no Cargo.toml; RustDetach turns it off when the server starts on a standalone file. | ||
| 186 | let g:ra_init = { | ||
| 187 | \ 'completion': { | ||
| 188 | \ 'autoimport': { 'enable': v:true }, | ||
| 189 | \ 'postfix': { 'enable': v:true }, | ||
| 190 | \ }, | ||
| 191 | \ 'checkOnSave': v:true, | ||
| 192 | \ 'detachedFiles': g:ra_detached, | ||
| 193 | \ } | ||
| 184 | function! RustDetach() abort | 194 | function! RustDetach() abort |
| 185 | if !exists('g:lsp_loaded') | 195 | if !exists('g:lsp_loaded') |
| 186 | return | 196 | return |
| @@ -190,6 +200,9 @@ function! RustDetach() abort | |||
| 190 | return | 200 | return |
| 191 | endif | 201 | endif |
| 192 | call add(g:ra_detached, l:p) | 202 | call add(g:ra_detached, l:p) |
| 203 | if lsp#get_server_status('rust-analyzer') !~# '^\(running\|starting\)$' | ||
| 204 | let g:ra_init['checkOnSave'] = v:false | ||
| 205 | endif | ||
| 193 | if lsp#get_server_status('rust-analyzer') ==# 'running' | 206 | if lsp#get_server_status('rust-analyzer') ==# 'running' |
| 194 | call lsp#update_workspace_config('rust-analyzer', {'rust-analyzer': {'detachedFiles': copy(g:ra_detached)}}) | 207 | call lsp#update_workspace_config('rust-analyzer', {'rust-analyzer': {'detachedFiles': copy(g:ra_detached)}}) |
| 195 | endif | 208 | endif |
| @@ -206,14 +219,7 @@ if executable(expand('~/.cargo/bin/rust-analyzer')) | |||
| 206 | \ 'cmd': {server_info -> [expand('~/.cargo/bin/rust-analyzer')]}, | 219 | \ 'cmd': {server_info -> [expand('~/.cargo/bin/rust-analyzer')]}, |
| 207 | \ 'allowlist': ['rust'], | 220 | \ 'allowlist': ['rust'], |
| 208 | \ 'root_uri': {server_info -> lsp#utils#path_to_uri(RustRoot())}, | 221 | \ 'root_uri': {server_info -> lsp#utils#path_to_uri(RustRoot())}, |
| 209 | \ 'initialization_options': { | 222 | \ 'initialization_options': g:ra_init, |
| 210 | \ 'completion': { | ||
| 211 | \ 'autoimport': { 'enable': v:true }, | ||
| 212 | \ 'postfix': { 'enable': v:true }, | ||
| 213 | \ }, | ||
| 214 | \ 'checkOnSave': v:true, | ||
| 215 | \ 'detachedFiles': g:ra_detached, | ||
| 216 | \ }, | ||
| 217 | \ 'workspace_config': {'rust-analyzer': {'detachedFiles': g:ra_detached}}, | 223 | \ 'workspace_config': {'rust-analyzer': {'detachedFiles': g:ra_detached}}, |
| 218 | \ }) | 224 | \ }) |
| 219 | endif | 225 | endif |
