skywind3000 / asyncrun.vim

:rocket: Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
https://www.vim.org/scripts/script.php?script_id=5431
MIT License
1.86k stars 111 forks source link

:AsyncRun 的 quickfix 在特定情况下不能显示或跳转到错误的地方 #189

Closed bingxuechangya closed 4 years ago

bingxuechangya commented 4 years ago

非常感谢您开发了这个插件,给我的工作学习带来了很多便利!只是在使用的时候发现在某种特定情况下:AsyncRun 打开的 quickfix 里面,不能显示或跳转到错误的地方,而在 :make 打开的 quickfix 里面却可以。不知道是不是因为我还没有掌握正确的用法。

复现步骤

1. 保存这段代码到 ./reproduce.sh:

#! /bin/bash
mkdir ./reproduce && cd ./reproduce || exit 1

# 创建 main.c
cat > main.c <<- EOF
#include "a.h"
int main() { return 0; }
EOF

# 创建 a.h
cat > a.h <<- EOF
#include "b.h"
EOF

# 创建 b.h
cat > b.h <<- EOF
#include "common.h"
EOF

# 创建 Makefile
cat > Makefile << EOF
all:
    gcc main.c
EOF

2. 运行这条命令开始测试 asyncrun 插件:

chmod +x ./reproduce.sh && cd ./reproduce && vim main.c

3. 比较

3.1 ":make" —— ":cprevious|:cnext" 定位正常:

|| gcc main.c b.h|1 col 10| fatal error: common.h: No such file or directory || #include "common.h" || ^~~~~~ || compilation terminated. Makefile|2| recipe for target 'all' failed || make: *** [all] Error 1

3.2 ":AsyncRun make" —— b.h 的报错被忽略了:

|| [make] || gcc main.c || [make] || gcc main.c || [make] || gcc main.c Makefile|2| recipe for target 'all' failed || make: *** [all] Error 1 || [Finished in 0 seconds with code 2]

3.3 ":AsyncRun -raw make" —— b.h 报错会显示,但 ":cprevious|:cnext" 无法跳转到 b.h 报错的地方:

|| [make] || gcc main.c || In file included from a.h:1:0, || from main.c:1: || b.h:1:10: fatal error: common.h: No such file or directory || #include "common.h" || ^~~~~~ || compilation terminated. || Makefile:2: recipe for target 'all' failed || make: *** [all] Error 1 || [Finished in 0 seconds with code 2]

skywind3000 commented 4 years ago

这是因为你的 errorformat 设置的有问题,多行错误匹配存在干扰,make 是一次性添加内容,而 AsyncRun 是逐行添加内容,所以多行匹配的设置不适合 AsyncRun:

试试修改全局 errorformat:

:set errorformat=%.\ %#-->\ %f:%l:%c,%f(%l):%m,%f:%l:%c:%m,%f:%l:%m

或者为每次运行指定单独的 errorformat:

:AsyncRun -errorformat=%f:%l:%m,%f:%l:%c:%m make
bingxuechangya commented 4 years ago

好的,非常感谢!只是这条命令好像还不能达到预期效果:

:AsyncRun -errorformat=%f:%l:%m,%f:%l:%c:%m make
skywind3000 commented 4 years ago

哦,想起来了,所有百分号前面要加反斜杠,因为 % 是关键字:

:AsyncRun -errorformat=\%f:\%l:\%m,\%f:\%l:\%c:\%m make
bingxuechangya commented 4 years ago

嗯,的确是的 :+1: :+1: :+1:

skywind3000 commented 4 years ago

欢迎使用:

https://github.com/skywind3000/asynctasks.vim

用于管理 asyncrun 的各种命令和配置,让 asyncrun 更好用

bingxuechangya commented 4 years ago

嗯,我试试看,多谢多谢 😁