0

I build my c++ software inside a docker image while running Vim in the host.

Although I succeed in building through :make by setting set makeprg=./build_script.sh, where ./build_script.sh calls docker run ... make, the paths in the quickfix list are relative to the docker filesystem, as I would expect.

That is, if I my host -> docker mounting mapping is /home/myname/myproject -> /app and there is an error in myfile.c, then the quickfix list will refer to a /app/myfile.c instead of /home/myname/myproject/myfile.c and therefore a jump from the quickfix list to such error will end up in a jump to a non-existing /app/myfile.c.

I fixed that with the following autocommand:

au! BufReadPost quickfix  setlocal modifiable
    \ | silent exe ':%s/^\/app/\/home\/myname\/myproject/g'
    \ | setlocal nomodifiable

and in-fact, the path in the quicklist are changed.

However, if I hit <enter> in the line where the error related to myfile.c is, then Vim tries to jump to /app/file.c (which does not exist) instead of jumping to /home/myname/myproject/myfile.c. To circumnavigate this, I <c-w>f on that file listed in the quickfix list.

How to make Vim to open /home/myname/myproject/myfile.c when I hit <enter>?

3 Answers 3

2

Unless new features have been added (in vim9 or neovim) to correctly patch filenames from quickfix list, I'm afraid you're stuck in between another bash script that'll do filename conversion (the solution I recommend), and dark magic.

See my previous answer on a very similar question: Translate file paths in quickfix list

5
  • I did set makeprg=./build_script.sh\ \\\|\ fix_paths.sh such that fix_paths.sh changes the line starting with /app into /home/myname/myproject and that worked. What do you mean with dark magic?
    – Barzi2001
    Commented Apr 16 at 22:41
  • We can try to read getqflist() on QuickFixCmdPost, and update the buffer names. Alas, this is not enough: we have to force a refreshing of buffer numbers when writing back the quickfix list. See the code behind the link to the other answer. Commented Apr 16 at 22:44
  • 1
    PS: You'll want to set pipefail in order to keep the information about compilation errors. Commented Apr 16 at 22:45
  • Yes, I have seen that, but as you said, piping into another script looks easier.
    – Barzi2001
    Commented Apr 16 at 22:45
  • (What I've described was what I meant by dark magic: something convoluted that seems to do the work for some obscure reasons) Commented Apr 17 at 0:09
1

2 options come to mind:

  • post process the output in your build script to make the file names relative to the current directory
  • use getqflist()/setqflist() to manipulate the quickfix list entries
1

This is fundamentally the same problem as your earlier question about escape sequences: your pipeline sends garbage to Vim and that's where you should put your effort.

build_script.sh knows the working directory, where it is located, etc., so it should be able to pass some information about the context along to the other tools in the pipeline. It could also be done with an additional parameter, like in so many build tools:

" untested
set makeprg=./build_script.sh\ --basedir=%:p

Basically, you should strive for agnosticism in your build system, leaving the peculiarities of whatever consumes its textual output completely out of the equation.

1
  • I agree, but unfortunately I have no full control of the build scripts, nor the required skills to perform advanced actions. At the end I created a script build_scripts_local_paths.sh that just contains set -o pipefail and ./build_script.sh | fix_paths.sh and then I set makeprg=./build_scripts_local_paths.sh. It works fine so far but I agree that it would be handy to adjust the build_script.sh with a --basedir flag.
    – Barzi2001
    Commented Apr 17 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.