Skip to content

support for customizable lists types #1415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function! go#cmd#Build(bang, ...) abort
call s:cmd_job({
\ 'cmd': ['go'] + args,
\ 'bang': a:bang,
\ 'for': 'GoBuild',
\})
return
elseif has('nvim')
Expand All @@ -39,7 +40,7 @@ function! go#cmd#Build(bang, ...) abort
endif

" if we have nvim, call it asynchronously and return early ;)
call go#jobcontrol#Spawn(a:bang, "build", args)
call go#jobcontrol#Spawn(a:bang, "build", "GoBuild", args)
return
endif

Expand All @@ -48,7 +49,7 @@ function! go#cmd#Build(bang, ...) abort
let default_makeprg = &makeprg
let &makeprg = "go " . join(args, ' ')

let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type("GoBuild", "quickfix")
" execute make inside the source folder so we can parse the errors
" correctly
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand Down Expand Up @@ -149,7 +150,7 @@ function! go#cmd#Run(bang, ...) abort
let &makeprg = "go run " . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
endif

let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type("GoRun", "quickfix")

if l:listtype == "locationlist"
exe 'lmake!'
Expand Down Expand Up @@ -186,6 +187,7 @@ function! go#cmd#Install(bang, ...) abort
call s:cmd_job({
\ 'cmd': ['go', 'install'] + goargs,
\ 'bang': a:bang,
\ 'for': 'GoInstall',
\})
return
endif
Expand All @@ -198,7 +200,7 @@ function! go#cmd#Install(bang, ...) abort
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
let &makeprg = "go install " . goargs

let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type("GoInstall", "quickfix")
" execute make inside the source folder so we can parse the errors
" correctly
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand Down Expand Up @@ -243,7 +245,7 @@ function! go#cmd#Generate(bang, ...) abort
let &makeprg = "go generate " . goargs . ' ' . gofiles
endif

let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type("GoGenerate", "quickfix")

echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None
if l:listtype == "locationlist"
Expand Down
2 changes: 2 additions & 0 deletions autoload/go/coverage.vim
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function! go#coverage#Buffer(bang, ...) abort
\ 'cmd': ['go', 'test', '-coverprofile', l:tmpname] + a:000,
\ 'custom_cb': function('s:coverage_callback', [l:tmpname]),
\ 'bang': a:bang,
\ 'for': 'GoTest',
\ })
return
endif
Expand Down Expand Up @@ -108,6 +109,7 @@ function! go#coverage#Browser(bang, ...) abort
\ 'cmd': ['go', 'test', '-coverprofile', l:tmpname],
\ 'custom_cb': function('s:coverage_browser_callback', [l:tmpname]),
\ 'bang': a:bang,
\ 'for': 'GoTest',
\ })
return
endif
Expand Down
13 changes: 8 additions & 5 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,20 @@ function! go#fmt#update_file(source, target)
let &fileformat = old_fileformat
let &syntax = &syntax


" the title information was introduced with 7.4-2200
" https://github.com/vim/vim/commit/d823fa910cca43fec3c31c030ee908a14c272640
if !has('patch-7.4-2200')
return
endif

" clean up previous location list
let l:list_title = getqflist({'title': 1})
" clean up previous list
let l:listtype = go#list#Type("GoFmt", "locationlist")
if l:listtype == "quickfix"
let l:list_title = getqflist({'title': 1})
else
let l:list_title = getloclist(0, {'title': 1})
endif
if has_key(l:list_title, "title") && l:list_title['title'] == "Format"
let l:listtype = go#list#Type("quickfix")
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
endif
Expand Down Expand Up @@ -245,7 +248,7 @@ endfunction
" show_errors opens a location list and shows the given errors. If the given
" errors is empty, it closes the the location list
function! s:show_errors(errors) abort
let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type("GoFmt", "locationlist")
if !empty(a:errors)
call go#list#Populate(l:listtype, a:errors, 'Format')
echohl Error | echomsg "Gofmt returned error" | echohl None
Expand Down
7 changes: 4 additions & 3 deletions autoload/go/guru.vim
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,12 @@ function! s:parse_guru_output(exit_val, output, title) abort

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

let errors = go#list#Get("locationlist")
call go#list#Window("locationlist", len(errors))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
endfun

function! go#guru#Scope(...) abort
Expand Down
7 changes: 6 additions & 1 deletion autoload/go/job.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ function go#job#Spawn(args)
\ 'messages': [],
\ 'args': a:args.cmd,
\ 'bang': 0,
\ 'for': "quickfix",
\ }

if has_key(a:args, 'bang')
let cbs.bang = a:args.bang
endif

if has_key(a:args, 'for')
let cbs.for = a:args.for
endif

" add final callback to be called if async job is finished
" The signature should be in form: func(job, exit_status, messages)
if has_key(a:args, 'custom_cb')
Expand Down Expand Up @@ -47,7 +52,7 @@ function go#job#Spawn(args)
call self.custom_cb(a:job, a:exitval, self.messages)
endif

let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type(self.for, "quickfix")
if a:exitval == 0
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
Expand Down
9 changes: 5 additions & 4 deletions autoload/go/jobcontrol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ let s:handlers = {}
" Spawn is a wrapper around s:spawn. It can be executed by other files and
" scripts if needed. Desc defines the description for printing the status
" during the job execution (useful for statusline integration).
function! go#jobcontrol#Spawn(bang, desc, args) abort
function! go#jobcontrol#Spawn(bang, desc, for, args) abort
" autowrite is not enabled for jobs
call go#cmd#autowrite()

let job = s:spawn(a:bang, a:desc, a:args)
let job = s:spawn(a:bang, a:desc, a:for, a:args)
return job.id
endfunction

Expand All @@ -37,7 +37,7 @@ endfunction
" a job is started a reference will be stored inside s:jobs. spawn changes the
" GOPATH when g:go_autodetect_gopath is enabled. The job is started inside the
" current files folder.
function! s:spawn(bang, desc, args) abort
function! s:spawn(bang, desc, args, for) abort
let status_type = a:args[0]
let status_dir = expand('%:p:h')
let started_at = reltime()
Expand All @@ -62,6 +62,7 @@ function! s:spawn(bang, desc, args) abort
\ 'status_type' : status_type,
\ 'status_dir' : status_dir,
\ 'started_at' : started_at,
\ 'for' : a:for,
\ }

" modify GOPATH if needed
Expand Down Expand Up @@ -129,7 +130,7 @@ function! s:on_exit(job_id, exit_status, event) dict abort

call s:callback_handlers_on_exit(s:jobs[a:job_id], a:exit_status, std_combined)

let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type(self.for, "quickfix")
if a:exit_status == 0
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
Expand Down
10 changes: 5 additions & 5 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function! go#lint#Gometa(autosave, ...) abort

let out = go#tool#ExecuteInDir(meta_command)

let l:listtype = "quickfix"
let l:listtype = go#list#Type("GoMetaLinter", "quickfix")
if go#util#ShellError() == 0
redraw | echo
call go#list#Clean(l:listtype)
Expand Down Expand Up @@ -134,7 +134,7 @@ function! go#lint#Golint(...) abort
return
endif

let l:listtype = "quickfix"
let l:listtype = go#list#Type("GoLint", "quickfix")
call go#list#Parse(l:listtype, out)
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
Expand All @@ -152,7 +152,7 @@ function! go#lint#Vet(bang, ...) abort
let out = go#util#System('go tool vet ' . go#util#Shelljoin(a:000))
endif

let l:listtype = "quickfix"
let l:listtype = go#list#Type("GoVet", "quickfix")
if go#util#ShellError() != 0
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:listtype, errors, 'Vet')
Expand Down Expand Up @@ -192,7 +192,7 @@ function! go#lint#Errcheck(...) abort
let command = go#util#Shellescape(bin_path) . ' -abspath ' . import_path
let out = go#tool#ExecuteInDir(command)

let l:listtype = "quickfix"
let l:listtype = go#list#Type("GoErrCheck", "quickfix")
if go#util#ShellError() != 0
let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m"

Expand Down Expand Up @@ -246,7 +246,7 @@ function s:lint_job(args)
" autowrite is not enabled for jobs
call go#cmd#autowrite()

let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type("GoMetaLinter", "quickfix")
let l:errformat = '%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m'

function! s:callback(chan, msg) closure
Expand Down
49 changes: 23 additions & 26 deletions autoload/go/list.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ if !exists("g:go_list_type")
let g:go_list_type = ""
endif

if !exists("g:go_list_type_commands")
let g:go_list_type_commands = {}
endif

" Window opens the list with the given height up to 10 lines maximum.
" Otherwise g:go_loclist_height is used.
"
" If no or zero height is given it closes the window by default.
" To prevent this, set g:go_list_autoclose = 0
function! go#list#Window(listtype, ...) abort
let l:listtype = go#list#Type(a:listtype)
" we don't use lwindow to close the location list as we need also the
" ability to resize the window. So, we are going to use lopen and lclose
" for a better user experience. If the number of errors in a current
Expand All @@ -17,7 +20,7 @@ function! go#list#Window(listtype, ...) abort
if !a:0 || a:1 == 0
let autoclose_window = get(g:, 'go_list_autoclose', 1)
if autoclose_window
if l:listtype == "locationlist"
if a:listtype == "locationlist"
lclose
else
cclose
Expand All @@ -36,28 +39,26 @@ function! go#list#Window(listtype, ...) abort
endif
endif

if l:listtype == "locationlist"
if a:listtype == "locationlist"
exe 'lopen ' . height
else
exe 'copen ' . height
endif
endfunction


" Get returns the current list of items from the location list
" Get returns the current items from the list
function! go#list#Get(listtype) abort
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
if a:listtype == "locationlist"
return getloclist(0)
else
return getqflist()
endif
endfunction

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

" The last argument ({what}) is introduced with 7.4.2200:
Expand All @@ -69,20 +70,15 @@ function! go#list#Populate(listtype, items, title) abort
endif
endfunction

function! go#list#PopulateWin(winnr, items) abort
call setloclist(a:winnr, a:items, 'r')
endfunction

" Parse parses the given items based on the specified errorformat and
" populates the location list.
" populates the list.
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

" parse and populate the location list
let &errorformat = a:errformat
if l:listtype == "locationlist"
if a:listtype == "locationlist"
lgetexpr a:items
if has("patch-7.4.2200") | call setloclist(0, [], 'a', {'title': a:title}) | endif
else
Expand All @@ -95,10 +91,9 @@ function! go#list#ParseFormat(listtype, errformat, items, title) abort
endfunction

" Parse parses the given items based on the global errorformat and
" populates the location list.
" populates the list.
function! go#list#Parse(listtype, items) abort
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
if a:listtype == "locationlist"
lgetexpr a:items
else
cgetexpr a:items
Expand All @@ -107,8 +102,7 @@ endfunction

" JumpToFirst jumps to the first item in the location list
function! go#list#JumpToFirst(listtype) abort
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
if a:listtype == "locationlist"
ll 1
else
cc 1
Expand All @@ -117,22 +111,25 @@ endfunction

" Clean cleans the location list
function! go#list#Clean(listtype) abort
let l:listtype = go#list#Type(a:listtype)
if l:listtype == "locationlist"
if a:listtype == "locationlist"
lex []
else
cex []
endif
endfunction

function! go#list#Type(listtype) abort
function! s:listtype(listtype) abort
if g:go_list_type == "locationlist"
return "locationlist"
elseif g:go_list_type == "quickfix"
return "quickfix"
else
return a:listtype
endif

return a:listtype
endfunction

function! go#list#Type(for, default) abort
let l:listtype = s:listtype(a:default)
return get(g:go_list_type_commands, a:for, l:listtype)
endfunction
" vim: sw=2 ts=2 et
2 changes: 1 addition & 1 deletion autoload/go/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function s:parse_errors(exit_val, bang, out)
silent! checktime
let &autoread = current_autoread

let l:listtype = "quickfix"
let l:listtype = go#list#Type("GoRename", "quickfix")
if a:exit_val != 0
call go#util#EchoError("FAILED")
let errors = go#tool#ParseErrors(a:out)
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/tags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func s:write_out(out) abort

if has_key(result, 'errors')
let l:winnr = winnr()
let l:listtype = go#list#Type("quickfix")
let l:listtype = go#list#Type("GoModifyTags", "quickfix")
call go#list#ParseFormat(l:listtype, "%f:%l:%c:%m", result['errors'], "gomodifytags")
call go#list#Window(l:listtype, len(result['errors']))

Expand Down
Loading