Skip to content

Commit

Permalink
Show multiline errors (#1456)
Browse files Browse the repository at this point in the history
Unlike `:echo`, `:echom` is rather stupid. It will display a newline as
`^@` or `<00>` and tabs as `^I` or `<09>` (depending on the `display`
setting).

This some messages display nicer, for example `:GoBuild --` looked
rather confusing before, and looks as expected now.

This fixes some – but not all – of #1429.
arp242 authored Sep 18, 2017
1 parent 5e4ed05 commit 0371da6
Showing 5 changed files with 32 additions and 20 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -15,14 +15,17 @@ IMPROVEMENTS:
easier to use [[GH-1386]](https://github.com/fatih/vim-go/pull/1386)
* `:GoDef` sets the path of new buffers as relative to the current directory
when appropriate, instead of always using the full path [[GH-1277]](https://github.com/fatih/vim-go/pull/1277).
* Syntax highlighting for variable declarations (disabled by default) [[GH-1426]](https://github.com/fatih/vim-go/pull/1426).
* Syntax highlighting for variable declarations and assignments (disabled by default)
[[GH-1426]](https://github.com/fatih/vim-go/pull/1426) and
[[GH-1458]](https://github.com/fatih/vim-go/pull/1458).

* Add support for `:GoDecls[Dir]` in [unite.vim](https://github.com/Shougo/unite.vim) [[GH-1391]](https://github.com/fatih/vim-go/pull/1391).
* Support relative imports for `:GoImpl` [[GH-1322]](https://github.com/fatih/vim-go/pull/1322).
* A new `g:go_list_type_commands` setting is added to individually set the list type for each command [[GH-1415]](https://github.com/fatih/vim-go/pull/1415). As en example:

let g:go_list_type_commands = {"GoBuild": "quickfix", "GoTest": "locationlist"}

* Variable assignments are highlighted when `g:go_highlight_variable_assignments` is enabled [[GH-1458]](https://github.com/fatih/vim-go/pull/1458)
* Show unexpected errors better by expanding newlines and tabs
[[GH-1456]](https://github.com/fatih/vim-go/pull/1456).

BUG FIXES:

3 changes: 1 addition & 2 deletions autoload/go/job.vim
Original file line number Diff line number Diff line change
@@ -74,8 +74,7 @@ function go#job#Spawn(args)

if !len(errors)
" failed to parse errors, output the original content
call go#util#EchoError(join(self.messages, " "))
call go#util#EchoError(self.dir)
call go#util#EchoError(self.messages + [self.dir])
return
endif

2 changes: 1 addition & 1 deletion autoload/go/rename.vim
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ function s:parse_errors(exit_val, bang, out)
call go#list#JumpToFirst(l:listtype)
elseif empty(errors)
" failed to parse errors, output the original content
call go#util#EchoError(join(a:out, ""))
call go#util#EchoError(a:out)
endif

return
2 changes: 1 addition & 1 deletion autoload/go/test.vim
Original file line number Diff line number Diff line change
@@ -237,7 +237,7 @@ function! s:show_errors(args, exit_val, messages) abort

if !len(errors)
" failed to parse errors, output the original content
call go#util#EchoError(join(a:messages, " "))
call go#util#EchoError(a:messages)
call go#util#EchoError(a:args.dir)
return
endif
36 changes: 23 additions & 13 deletions autoload/go/util.vim
Original file line number Diff line number Diff line change
@@ -261,29 +261,39 @@ function! go#util#camelcase(word) abort
endif
endfunction

" TODO(arslan): I couldn't parameterize the highlight types. Check if we can
" simplify the following functions
" Echo a message to the screen and highlight it with the group in a:hi.
"
" NOTE(arslan): echon doesn't work well with redraw, thus echo doesn't print
" even though we order it. However echom seems to be work fine.
function! go#util#EchoSuccess(msg)
redraw | echohl Function | echom "vim-go: " . a:msg | echohl None
" The message can be a list or string; every line with be :echomsg'd separately.
function! s:echo(msg, hi)
let l:msg = a:msg
if type(l:msg) != v:t_list
let l:msg = split(l:msg, "\n")
endif

" Tabs display as ^I or <09>, so manually expand them.
let l:msg = map(l:msg, 'substitute(v:val, "\t", " ", "")')

exe 'echohl ' . a:hi
for line in l:msg
echom "vim-go: " . line
endfor
echohl None
endfunction

function! go#util#EchoSuccess(msg)
call s:echo(a:msg, 'Function')
endfunction
function! go#util#EchoError(msg)
redraw | echohl ErrorMsg | echom "vim-go: " . a:msg | echohl None
call s:echo(a:msg, 'ErrorMsg')
endfunction

function! go#util#EchoWarning(msg)
redraw | echohl WarningMsg | echom "vim-go: " . a:msg | echohl None
call s:echo(a:msg, 'WarningMsg')
endfunction

function! go#util#EchoProgress(msg)
redraw | echohl Identifier | echom "vim-go: " . a:msg | echohl None
call s:echo(a:msg, 'Identifier')
endfunction

function! go#util#EchoInfo(msg)
redraw | echohl Debug | echom "vim-go: " . a:msg | echohl None
call s:echo(a:msg, 'Debug')
endfunction

function! go#util#GetLines()

0 comments on commit 0371da6

Please sign in to comment.