简体   繁体   English

错误格式,其中类型位于消息的中间

[英]errorformat where the type is in the middle of the message

Given a C# compiler message like this, when warnings-as-errors is turned on: 给定这样的C#编译器消息,当警告错误时打开:

File.cs(3,1415): error CS1572: Warning as Error: XML comment on 'FooLibrary.Foo.Foo()' has a param tag for 'foo', but there is no parameter by that name

I would like to have my errorformat marking it as type warning rather than type error . 我想将我的errorformat标记为类型warning而不是error类型。

I already have such values in my errorformat as: 我的错误errorformat已经有以下值:

%f(%l\\,%c):\ %trror\ %m^M
%f(%l\\,%c):\ %trror\ %m

(Whenever you see ^M , know that it is the actual control code in my file, but it doesn't transmit well to the web. Suffice it to indicate that the C# compiler outputs \\r\\n rather than just \\n , and this is a Mild Nuisance.) (只要看到^M ,就知道它是我文件中的实际控制代码,但是它不能很好地传输到Web上。足以表明C#编译器输出\\r\\n而不是\\n ,并且这是轻微的滋扰。)

Here is what I first tried: 这是我首先尝试的方法:

%f(%l\\,%c):\ error\ %m: %tarning\ as\ Error:\ %m^M
%f(%l\\,%c):\ error\ %m: %tarning\ as\ Error:\ %m

Vim bemoaned the fact that it couldn't deal with multiple occurrences of %m in the one string. Vim抱怨这样一个事实,即它无法处理一个字符串中多次出现的%m

So then I started getting fancy with unusual regular expressions incorporating assertions. 因此,我开始喜欢带有断言的异常正则表达式。 Here is what I tried: 这是我尝试过的:

%f(%l\\,%c):\ error\ %\\(%[A-Z0-9]%#:\ %tarning\ as\ Error:\ %[%^^M]%#%\\)%\\@=%m^M
%f(%l\\,%c):\ error\ %\\(%[A-Z0-9]%#:\ %tarning\ as\ Error:\ %[%^^M]%#%\\)%\\@=%m

This didn't work; 这行不通; it gets type "C" (presumably from "CS1572") and message "W" (the value which %t should be consuming). 它得到类型“ C”(可能来自“ CS1572”)和消息“ W”( %t应该消耗的值)。 (In some other experimentation, omitting the %t , it proved necessary to consume the rest of the string inside the assertion, or else it stopped its match of %m at that point. Very strange.) (在其他一些实验中,省略了%t ,事实证明有必要消耗断言中的其余字符串,否则就在那一刻停止了对%m匹配。 非常奇怪。)

Perceiving that it was not treating them as regular expression groups, as they might be, but rather in a peculiar linear manner, I then tried reversing the assertions and wound up with this: 感觉到它并没有像对待正则表达式组那样对待它们,而是以一种特殊的线性方式,然后我尝试反转这些断言并总结如下:

%f(%l\\,%c):\ error\ %\\(%m^M%\\)%\\@=%[A-Z0-9]%#:\ %tarning\ as\ Error:\ %.%#^M
%f(%l\\,%c):\ error\ %\\(%m^M%\\)%\\@=%[A-Z0-9]%#:\ %tarning\ as\ Error:\ %.%#

Unfortunately, these also fail, getting type "C" rather than "warning" and (though getting the message intact, at last) leaving the ^M on the end of the string. 不幸的是,它们也失败了,它们的类型为“ C”而不是“ warning”,并且(尽管使消息完整无缺)最后在字符串末尾加上了^M

I've exhausted the possibilities that I can think of inside the errorformat command; 我已经尽我所能在errorformat命令中想到的可能性了。 is there aught else which might resolve this matter, or would I need to resort to running another script to wrap it which would turn the format into something that Vim could cope with? 还有其他解决方案吗,还是我需要运行另一个脚本来包装它,从而将格式转换成Vim可以应付的东西?

(All that for getting the word "warning" rather than "error" in the quickfix list. Sad, isn't it?) (在快速修复列表中获得“警告”而不是“错误”一词的全部。难过,不是吗?)

If you are not fine with 如果你不满意

set efm=%f(%l\\,%c):\ error\ %[A-Z0-9]%#:\ %tarning\ as\ Error:\ %m

which will drop error number then I can suggest you using 这将删除错误号,然后我建议您使用

set efm=%f(%l\\,%c):\ %m

and post-processing the list with 然后用

function QFPostProc(location)
    let qflist=[]
    for entry in (a:location?getloclist(0):getqflist())
        " Using the fact that “%tarning” can match only warnings 
        " thus unconditionally setting type to 'W'

        " Replace 'W' with something like
        "     matchstr(entry.text, '\u\ze\a\+ as Error')
        " if this is not true.
        call add(qflist, extend(entry, {'type': 'W'}))
    endfor
    if a:location
        call setloclist(0, qflist, 'r')
    else
        call setqflist(qflist, 'r')
    endif
endfunction

. This should be called like 这应该叫做

:make | call QFPostProc(0)

or 要么

:lmake | call QFPostProc(1)

Can't test the ^M stuff, but this works with linux style line endings: 无法测试^ M的东西,但是这适用于linux样式行结尾:

set efm=%f(%l\\,%c):%*[^:]:\ %t%*[^:]:%m

and to get the error (warning) number: 并获取错误(警告)编号:

set efm=%f(%l\\,%c):\ error\ CS%n:\ %t%*[^:]:%m

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM