简体   繁体   English

设置由 ghcide 生成的多行错误消息的错误格式

[英]Setup errorformat for multi line error message produces by ghcide

I'm trying to setup errorformat for ghcide , which produces following output.我正在尝试为errorformat设置错误格式,它会产生以下 output。

ghcide version: 0.0.4 (GHC: 8.6.5)
Ghcide setup tester in /opt/devel/haskell/haskell-vim-now.
Report bugs at https://github.com/digital-asset/ghcide/issues

Step 1/6: Finding files to test in /opt/devel/haskell/haskell-vim-now
Found 1 files

Step 2/6: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/6, Cradle 1/1: Implicit cradle for /opt/devel/haskell/haskell-vim-now
Cradle {cradleRootDir = "/opt/devel/haskell/haskell-vim-now", cradleOptsProg = CradleAction: default}

Step 4/6, Cradle 1/1: Loading GHC Session

Step 5/6: Initializing the IDE

Step 6/6: Type checking the files
File:     foo.hs
Range:    1:4-1:5
Source:   typecheck
Severity: DsError
Message: 
  ESC[0;91mfoo.hs:1:5: error:
  • No instance for (Num String) arising from the literal ‘5’
  • In the expression: 5
  In an equation for ‘x’: x = 5ESC[0m
Completed (1 file worked, 0 files failed)

With following ~/.vim/compiler/ghcide.vim :使用以下~/.vim/compiler/ghcide.vim

CompilerSet  errorformat=%-Gghcide\ %s
CompilerSet  errorformat+=%-GReport\ bugs\ at\ %s
CompilerSet  errorformat+=%-GStep\ %s
CompilerSet  errorformat+=%-GFound\ %s
CompilerSet  errorformat+=%-GCradle\ %s
CompilerSet  errorformat+=%-GRange:\ %s
CompilerSet  errorformat+=%-GFile:\ %s
CompilerSet  errorformat+=%-GSource:\ %s
CompilerSet  errorformat+=%-GSeverity:\ %s
CompilerSet  errorformat+=%-GCompleted\ %s
" exclude empty or whitespace-only lines
CompilerSet  errorformat+=%-G\\s%#
CompilerSet  errorformat+=%E!\ Message:%>%trror%m
setlocal makeprg=ghcide\ %

Quickfix buffer shows only remaining four lines: Quickfix 缓冲区仅显示剩余的四行:

:clist                                                                                                                                                                                                             
 1: Message:-                                                                                                                                                                                                      
 2:   ^[[0;91mfoo.hs:1:5: error:                                                                                                                                                                                   
 3:   • No instance for (Num String) arising from the literal ‘5’                                                                                                                                                  
 4:   • In the expression: 5  

Since I couldn't figure out by my self how aforementioned multi line message could be mapped into single clist entry, I'm looking for help.由于我自己无法弄清楚如何将上述多行消息映射到单个clist条目中,因此我正在寻求帮助。

You could try this:你可以试试这个:

CompilerSet errorformat=%-Gghcide\ %s
CompilerSet errorformat+=%-GReport\ bugs\ at\ %s
CompilerSet errorformat+=%-GStep\ %s
CompilerSet errorformat+=%-GFound\ %s
CompilerSet errorformat+=%-GCradle\ %s
CompilerSet errorformat+=%-GRange:\ %s
CompilerSet errorformat+=%-GFile:\ %s
CompilerSet errorformat+=%-GSource:\ %s
CompilerSet errorformat+=%-GSeverity:\ %s
CompilerSet errorformat+=%-GCompleted\ %s
" exclude empty or whitespace-only lines
CompilerSet errorformat+=%-G\\s%#
CompilerSet errorformat+=%EMessage:%\\s%#%>
CompilerSet errorformat+=%C%\\s%#ESC[%\\d%#;%\\d%#m%f:%l:%c:%m
CompilerSet errorformat+=%C%m
CompilerSet errorformat+=%ZCompleted%m

The difference compared to your original code is in the last 4 lines:与原始代码相比的区别在于最后 4 行:

CompilerSet errorformat+=%EMessage:%\\s%#%>
CompilerSet errorformat+=%C%\\s%#ESC[%\\d%#;%\\d%#m%f:%l:%c:%m
CompilerSet errorformat+=%C%m
CompilerSet errorformat+=%ZCompleted%m

Originally, you used this:最初,您使用的是:

CompilerSet  errorformat+=%E!\ Message:%>%trror%m

But in the compiler output you provided, the Message: line does not begin with a bang and a space, so I think it should be removed.但是在您提供的编译器 output 中, Message:行不以 bang 和空格开头,所以我认为应该删除它。

Besides, %E already sets the type of the entry to error , so %t is not necessary.此外, %E已经将条目的类型设置为error ,因此%t不是必需的。 And there is no message on the line (the message is on the next lines), so you don't need %m .并且行上没有消息(消息在下一行),所以你不需要%m Finally, in the output, there is a trailing whitespace, so you need %\\s%# .最后,在 output 中,有一个尾随空格,所以你需要%\\s%#

All in all this gives:总而言之,这给出了:

CompilerSet errorformat+=%EMessage:%\\s%#%>

But you still need to extract the filename and the line/column position, which you can get with resp.但是您仍然需要提取文件名和行/列 position,您可以分别获得。 %f , %l and %c : %f%l%c

CompilerSet errorformat+=%C%\\s%#ESC[%\\d%#;%\\d%#m%f:%l:%c:%m

Note that the format begins with %C which tells Vim that it matches the continuation of a multi-line message (see :h errorformat-multi-line ).请注意,格式以%C开头,它告诉 Vim 它匹配多行消息的延续(请参阅:h errorformat-multi-line )。

Finally, I think you want the rest of the message, until the Completed line, which you can get with:最后,我认为您想要消息的 rest,直到Completed行,您可以使用:

CompilerSet errorformat+=%C%m
CompilerSet errorformat+=%ZCompleted%m

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

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