2

我正在尝试设置 errorformatghcide ,它产生以下输出。

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)

有以下内容~/.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 缓冲区仅显示剩余的四行:

: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  

由于我自己无法弄清楚如何将上述多行消息映射到单个clist条目中,因此我正在寻求帮助。

4

1 回答 1

1

你可以试试这个:

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

与原始代码相比的区别在于最后 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

最初,您使用的是:

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

但是在您提供的编译器输出中,该Message:行不是以 bang 和空格开头的,所以我认为应该删除它。

此外,%E已经将条目的类型设置为error,所以%t没有必要。并且行上没有消息(消息在下一行),所以你不需要%m. 最后,在输出中,有一个尾随空格,所以你需要%\\s%#.

总而言之,这给出了:

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

但是您仍然需要提取文件名和行/列位置,您可以使用 resp 获得。%f,%l%c:

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

请注意,格式以%Cwhich 开头,告诉 Vim 它匹配多行消息的延续(请参阅 参考资料:h errorformat-multi-line)。

最后,我认为你想要消息的其余部分,直到Completed你可以得到的行:

CompilerSet errorformat+=%C%m
CompilerSet errorformat+=%ZCompleted%m
于 2019-11-24T18:34:16.530 回答