From f667f3e2085886aa821162005ff2e5baa69f0eaa Mon Sep 17 00:00:00 2001 From: Yuta Yamamoto Date: Mon, 26 May 2025 13:17:06 +0900 Subject: [PATCH] Set proper current directory for :lmake with 'cargo' compiler The buffer-local current directory of the location-list window should match the location of the Cargo.toml file. Related commit: c6ffafc0dfd8704a1da8e6ab05d0b4d642c8b918 Related issue: #230 This commit fixes the following bug; cargo#quickfix#CmdPre() and cargo#quickfix#CmdPost() are not called when executing :lmake, and hence filenames in the location list are not parsed correctly. Steps to reproduce the bug: ``` cargo new example cd example/src echo erroneous_line >> main.rs ``` Open `main.rs` and execute `:lmake check`. (Press ENTER if necessary.) Expected behavior: The cursor jumps to the last line in `example/src/main.rs`. Actual behavior: The cursor jumps to the top of the wrong file, i.e., `example/src/src/main.rs`. Explanation: This is related to the known and fixed issue #230. Since the error message of cargo is relative to the project root, we have to take care of the current directory of the window when parsing the file names in the error message. The commit c6ffafc0dfd8704a1da8e6ab05d0b4d642c8b918 fixes by executing :chdir before and after the execution of :make. But they don't cover the case for :lmake. This commit fixes this case. --- compiler/cargo.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/cargo.vim b/compiler/cargo.vim index a511ef6f..898c95be 100644 --- a/compiler/cargo.vim +++ b/compiler/cargo.vim @@ -28,7 +28,9 @@ endif augroup RustCargoQuickFixHooks autocmd! autocmd QuickFixCmdPre make call cargo#quickfix#CmdPre() + autocmd QuickFixCmdPre lmake call cargo#quickfix#CmdPre() autocmd QuickFixCmdPost make call cargo#quickfix#CmdPost() + autocmd QuickFixCmdPost lmake call cargo#quickfix#CmdPost() augroup END " Ignore general cargo progress messages