robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:fc93594d562d2dd5e472df

master
1.1 KiB29 linesraw
1" Last Modified: 2023-09-11
2
3function! cargo#quickfix#CmdPre() abort
4    if &filetype ==# 'rust' && get(b:, 'current_compiler', '') ==# 'cargo' &&
5         \ &makeprg =~ '\V\^cargo\ \.\*'
6        " Preserve the current directory, and 'lcd' to the nearest Cargo file.
7        let b:rust_compiler_cargo_qf_has_lcd = haslocaldir()
8        let b:rust_compiler_cargo_qf_prev_cd = getcwd()
9        let b:rust_compiler_cargo_qf_prev_cd_saved = 1
10        let l:nearest = fnamemodify(cargo#nearestRootCargo(0), ':h')
11        execute 'lchdir! '.l:nearest
12    else
13        let b:rust_compiler_cargo_qf_prev_cd_saved = 0
14    endif
15endfunction
16
17function! cargo#quickfix#CmdPost() abort
18    if exists("b:rust_compiler_cargo_qf_prev_cd_saved") && b:rust_compiler_cargo_qf_prev_cd_saved
19        " Restore the current directory.
20        if b:rust_compiler_cargo_qf_has_lcd
21            execute 'lchdir! '.b:rust_compiler_cargo_qf_prev_cd
22        else
23            execute 'chdir! '.b:rust_compiler_cargo_qf_prev_cd
24        endif
25        let b:rust_compiler_cargo_qf_prev_cd_saved = 0
26    endif
27endfunction
28
29" vim: set et sw=4 sts=4 ts=8: