I'm trying to setup errorformat for ghcide, which produces following 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:
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:
: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.
You could try this:
The difference compared to your original code is in the last 4 lines:
Originally, you used this:
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.Besides,
%Ealready sets the type of the entry toerror, so%tis not necessary. And there is no message on the line (the message is on the next lines), so you don't need%m. Finally, in the output, there is a trailing whitespace, so you need%\\s%#.All in all this gives:
But you still need to extract the filename and the line/column position, which you can get with resp.
%f,%land%c:Note that the format begins with
%Cwhich tells Vim that it matches the continuation of a multi-line message (see:h errorformat-multi-line).Finally, I think you want the rest of the message, until the
Completedline, which you can get with: