Skip to content

Commit

Permalink
Provide a descriptive quickfix/location list title.
Browse files Browse the repository at this point in the history
Currently, the w:quickfix_title is being automatically set to the actual
Vim command that populates quickfix/location list. For example, running
any Guru command it will be displayed as ':    lgetexpr a:items' which
is not really informative.
  • Loading branch information
Kent Sibilev committed Nov 24, 2016
1 parent 7c27c6b commit f665e5e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 36 deletions.
4 changes: 2 additions & 2 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function! go#cmd#Run(bang, ...) abort
let items = go#list#Get(l:listtype)
let errors = go#tool#FilterValids(items)

call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, &makeprg)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
Expand Down Expand Up @@ -285,7 +285,7 @@ function! go#cmd#Test(bang, compile, ...) abort
let errors = go#tool#ParseErrors(split(out, '\n'))
let errors = go#tool#FilterValids(errors)

call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, command)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function! go#fmt#Format(withGoimport) abort
% | " Couldn't detect gofmt error format, output errors
endif
if !empty(errors)
call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, 'Format')
echohl Error | echomsg "Gofmt returned error" | echohl None
endif

Expand Down
49 changes: 25 additions & 24 deletions autoload/go/guru.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function! s:guru_cmd(args) range abort
endfunction

" sync_guru runs guru in sync mode with the given arguments
function! s:sync_guru(args) abort
function! s:sync_guru(args, title) abort
let result = s:guru_cmd(a:args)
if has_key(result, 'err')
call go#util#EchoError(result.err)
Expand Down Expand Up @@ -136,16 +136,16 @@ function! s:sync_guru(args) abort
let $GOPATH = old_gopath

if has_key(a:args, 'custom_parse')
call a:args.custom_parse(go#util#ShellError(), out)
call a:args.custom_parse(go#util#ShellError(), out, a:title)
else
call s:parse_guru_output(go#util#ShellError(), out)
call s:parse_guru_output(go#util#ShellError(), out, a:title)
endif

return out
endfunc

" async_guru runs guru in async mode with the given arguments
function! s:async_guru(args) abort
function! s:async_guru(args, title) abort
let result = s:guru_cmd(a:args)
if has_key(result, 'err')
call go#util#EchoError(result.err)
Expand All @@ -154,6 +154,7 @@ function! s:async_guru(args) abort

let import_path = go#package#ImportPath(expand('%:p:h'))
let statusline_type = printf("%s", a:args.mode)
let title = a:title

if !has_key(a:args, 'disable_progress')
if a:args.needs_scope
Expand Down Expand Up @@ -191,9 +192,9 @@ function! s:async_guru(args) abort
call go#statusline#Update(import_path, status)

if has_key(a:args, 'custom_parse')
call a:args.custom_parse(l:info.exitval, out)
call a:args.custom_parse(l:info.exitval, out, title)
else
call s:parse_guru_output(l:info.exitval, out)
call s:parse_guru_output(l:info.exitval, out, title)
endif
endfunction

Expand All @@ -218,12 +219,12 @@ function! s:async_guru(args) abort
endfunc

" run_guru runs the given guru argument
function! s:run_guru(args) abort
function! s:run_guru(args, title) abort
if go#util#has_job()
return s:async_guru(a:args)
return s:async_guru(a:args, a:title)
endif

return s:sync_guru(a:args)
return s:sync_guru(a:args, a:title)
endfunction

" Show 'implements' relation for selected package
Expand All @@ -235,7 +236,7 @@ function! go#guru#Implements(selected) abort
\ 'needs_scope': 1,
\ }

call s:run_guru(args)
call s:run_guru(args, 'Implements')
endfunction

" Report the possible constants, global variables, and concrete types that may
Expand All @@ -254,7 +255,7 @@ function! go#guru#Whicherrs(selected) abort
" call go#util#EchoSuccess("no error variables found. Try to change the scope with :GoGuruScope")
" return
" endif
call s:run_guru(args)
call s:run_guru(args, 'Whicherrs')
endfunction

" Describe selected syntax: definition, methods, etc
Expand All @@ -266,7 +267,7 @@ function! go#guru#Describe(selected) abort
\ 'needs_scope': 1,
\ }

call s:run_guru(args)
call s:run_guru(args, 'Describe')
endfunction

function! go#guru#DescribeInfo() abort
Expand All @@ -278,7 +279,7 @@ function! go#guru#DescribeInfo() abort
return
endif

function! s:info(exit_val, output)
function! s:info(exit_val, output, title)
if a:exit_val != 0
return
endif
Expand Down Expand Up @@ -372,7 +373,7 @@ function! go#guru#DescribeInfo() abort
\ 'disable_progress': 1,
\ }

call s:run_guru(args)
call s:run_guru(args, 'DescribeInfo')
endfunction

" Show possible targets of selected function call
Expand All @@ -384,7 +385,7 @@ function! go#guru#Callees(selected) abort
\ 'needs_scope': 1,
\ }

call s:run_guru(args)
call s:run_guru(args, 'Callees')
endfunction

" Show possible callers of selected function
Expand All @@ -396,7 +397,7 @@ function! go#guru#Callers(selected) abort
\ 'needs_scope': 1,
\ }

call s:run_guru(args)
call s:run_guru(args, 'Callers')
endfunction

" Show path from callgraph root to selected function
Expand All @@ -408,7 +409,7 @@ function! go#guru#Callstack(selected) abort
\ 'needs_scope': 1,
\ }

call s:run_guru(args)
call s:run_guru(args, 'Callstack')
endfunction

" Show free variables of selection
Expand All @@ -426,7 +427,7 @@ function! go#guru#Freevars(selected) abort
\ 'needs_scope': 0,
\ }

call s:run_guru(args)
call s:run_guru(args, 'Freevars')
endfunction

" Show send/receive corresponding to selected channel op
Expand All @@ -438,7 +439,7 @@ function! go#guru#ChannelPeers(selected) abort
\ 'needs_scope': 1,
\ }

call s:run_guru(args)
call s:run_guru(args, 'ChannelPeers')
endfunction

" Show all refs to entity denoted by selected identifier
Expand All @@ -450,7 +451,7 @@ function! go#guru#Referrers(selected) abort
\ 'needs_scope': 0,
\ }

call s:run_guru(args)
call s:run_guru(args, 'Referrers')
endfunction

function! go#guru#SameIdsTimer() abort
Expand Down Expand Up @@ -481,10 +482,10 @@ function! go#guru#SameIds() abort
\ 'custom_parse': function('s:same_ids_highlight'),
\ }

call s:run_guru(args)
call s:run_guru(args, 'SameIds')
endfunction

function! s:same_ids_highlight(exit_val, output) abort
function! s:same_ids_highlight(exit_val, output, title) abort
call go#guru#ClearSameIds() " run after calling guru to reduce flicker.

if a:output[0] !=# '{'
Expand Down Expand Up @@ -584,15 +585,15 @@ endfunction
" We discard line2 and col2 for the first errorformat, because it's not
" useful and location only has the ability to show one line and column
" number
function! s:parse_guru_output(exit_val, output) abort
function! s:parse_guru_output(exit_val, output, title) abort
if a:exit_val
call go#util#EchoError(a:output)
return
endif

let old_errorformat = &errorformat
let errformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
call go#list#ParseFormat("locationlist", errformat, a:output)
call go#list#ParseFormat("locationlist", errformat, a:output, a:title)
let &errorformat = old_errorformat

let errors = go#list#Get("locationlist")
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/jobcontrol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function! s:on_exit(job_id, exit_status) abort
" if we are still in the same windows show the list
if self.winnr == winnr()
let l:listtype = "locationlist"
call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, self.desc)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !self.bang
call go#list#JumpToFirst(l:listtype)
Expand Down
8 changes: 4 additions & 4 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function! go#lint#Gometa(autosave, ...) abort
let errformat = "%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m"

" Parse and populate our location list
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"), 'GoMetaLinter')

let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
Expand Down Expand Up @@ -135,7 +135,7 @@ function! go#lint#Vet(bang, ...) abort
let l:listtype = "quickfix"
if go#util#ShellError() != 0
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, 'Vet')
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
Expand Down Expand Up @@ -177,7 +177,7 @@ function! go#lint#Errcheck(...) abort
let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m"

" Parse and populate our location list
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"), 'Errcheck')

let errors = go#list#Get(l:listtype)

Expand All @@ -188,7 +188,7 @@ function! go#lint#Errcheck(...) abort
endif

if !empty(errors)
call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, 'Errcheck')
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
call go#list#JumpToFirst(l:listtype)
Expand Down
8 changes: 6 additions & 2 deletions autoload/go/list.vim
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ function! go#list#Get(listtype) abort
endfunction

" Populate populate the location list with the given items
function! go#list#Populate(listtype, items) abort
function! go#list#Populate(listtype, items, title) abort
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
call setloclist(0, a:items, 'r')
call setloclist(0, [], 'a', {'title': a:title})
else
call setqflist(a:items, 'r')
call setqflist([], 'a', {'title': a:title})
endif
endfunction

Expand All @@ -65,7 +67,7 @@ endfunction

" Parse parses the given items based on the specified errorformat nad
" populates the location list.
function! go#list#ParseFormat(listtype, errformat, items) abort
function! go#list#ParseFormat(listtype, errformat, items, title) abort
let l:listtype = go#list#Type(a:listtype)
" backup users errorformat, will be restored once we are finished
let old_errorformat = &errorformat
Expand All @@ -74,8 +76,10 @@ function! go#list#ParseFormat(listtype, errformat, items) abort
let &errorformat = a:errformat
if l:listtype == "locationlist"
lgetexpr a:items
call setloclist(0, [], 'a', {'title': a:title})
else
cgetexpr a:items
call setqflist([], 'a', {'title': a:title})
endif

"restore back
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function s:parse_errors(exit_val, bang, out)
if a:exit_val != 0
call go#util#EchoError("FAILED")
let errors = go#tool#ParseErrors(a:out)
call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, 'Rename')
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
Expand Down
3 changes: 2 additions & 1 deletion autoload/go/term.vim
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function! go#term#newmode(bang, cmd, mode) abort
let $GOPATH = old_gopath

let job.id = id
let job.cmd = a:cmd
startinsert

" resize new term if needed.
Expand Down Expand Up @@ -115,7 +116,7 @@ function! s:on_exit(job_id, exit_status) abort
" close terminal we don't need it anymore
close

call go#list#Populate(l:listtype, errors)
call go#list#Populate(l:listtype, errors, job.cmd)
call go#list#Window(l:listtype, len(errors))
if !self.bang
call go#list#JumpToFirst(l:listtype)
Expand Down

0 comments on commit f665e5e

Please sign in to comment.