0

I'm using msys + vim + ninja + MSVC on windows.

When building, the quickfix list has errors that use the windows path, ie c:\work\folder\file.cpp

Vim handles it ok-ish, it can open the files, but ideally it should translate those into msys style paths, ie /c/work/folder/file.cpp

and better yet, I'm in the C:\work folder, so it should become a relative path, ie folder/file.cpp

The messages are coming back from Ninja, which is using MSVC's cl.exe to build.

2
  • Do you run Vim from the msys command prompt? Have you check the the output of the ninja command? I suspect this is more a ninja problem than a Vim problem. Commented Jun 21, 2022 at 14:52
  • I do run vim from msys, it is the msys vim. And, yes the output of Ninja does have the Windows C:\ paths. My goal is to see if vim can auto-translate these windows-style paths to unix - perhaps with a plugin or script.
    – user92979
    Commented Jun 21, 2022 at 15:01

2 Answers 2

1

If vim is able to resolve your paths correctly and the issue is simply the visual component in the quickfix list, then you can customize its output with quickfixtextfunc (:h qftf) as follows (untested since I don't have a machine running Windows):

set qftf=QuickFixTextFunc
function QuickFixTextFunc(info) abort
 if a:info.quickfix
     let qfl = getqflist(#{id: a:info.id, items: 0}).items
 else
     let qfl = getloclist(a:info.winid, #{id: a:info.id, items: 0}).items
 endif
 let l = []
 for idx in range(a:info.start_idx - 1, a:info.end_idx - 1)
     let e = qfl[idx]
     let fname = bufname(e.bufnr)->fnamemodify(':p')
     let fname = 'c:' .. substitute(fname, '/', '\', 'g')
     let path = split(fname, ':')
     let letter = path[0]
     let fname = letter .. substitute(join(path[1:], ''), '\', '/', 'g')
     let lnum = e.lnum
     let col = e.col
     let type = e.type
     call add(l, fname .. '|' .. lnum..' '.. col .. '|' .. e.text)
 endfor
 return l
endfunction

The quickfix entries should looks like this:

enter image description here

0

In BuildToolsWrapper I have a hook for translating cygwin pathnames into gvim(-win32) pathnames.

The approach I've taken consists in piping make/ninja... output into another program that'll do the translation. It's done directly in the &makeprg option.

It could be done in pure vimscript as well. For instance, I have a filter that changes filenames after the compilation (event triggered on QuickFixCmdPost) where i do some dark magic in order to update the buffers registered in the quickfix list: https://github.com/LucHermitte/vim-build-tools-wrapper/blob/project/compiler/BTW/substitute_filenames.vim

I think this approach/workaround is convoluted and best avoided, and we should prefer filtering error messages (and thus changing filenames) directly in the &makeprg.

3
  • 1
    When I started reading the question I was sure Luc would have an answer :)
    – D. Ben Knoble
    Commented Jun 22, 2022 at 0:39
  • Very neat, and looks like it could work, but didn't quite work for me. I've opened a draft PR on your github, at least it now loads in my env (msys), so I guess now it is a problem with the pattern matcher. I'm not familiar enough with Perl to fix myself... Oh and I use "ninja -C build-folder" and not make. I added a Makefile that calls ninja for now. I wonder if we can fix it up so it works?
    – user92979
    Commented Jun 22, 2022 at 4:58
  • I'm currently trying to fix the CMake compilation chain which is a mess. I may have troubles to provide you with a solution as I don't use msys. I'll see this weekend whether I could provide you with a solution. If you have perl, this should be doable. Commented Jun 22, 2022 at 8:40

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.