Skip to content

Commit

Permalink
use strings for list type
Browse files Browse the repository at this point in the history
* Refactor to use strings for list types instead of an integer.

* rename variables that store the list type.
  • Loading branch information
bhcleek committed Feb 8, 2016
1 parent 71d0f04 commit 62feccf
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 113 deletions.
66 changes: 33 additions & 33 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function! go#cmd#Build(bang, ...)
let default_makeprg = &makeprg
let &makeprg = "go " . join(args, ' ')

let l:quickfix = go#list#Type(1)
let l:listtype = go#list#Type("quickfix")
" execute make inside the source folder so we can parse the errors
" correctly
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand All @@ -47,7 +47,7 @@ function! go#cmd#Build(bang, ...)
if g:go_dispatch_enabled && exists(':Make') == 2
call go#util#EchoProgress("building dispatched ...")
silent! exe 'Make'
elseif l:quickfix == 0
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
silent! exe 'make!'
Expand All @@ -57,12 +57,12 @@ function! go#cmd#Build(bang, ...)
execute cd . fnameescape(dir)
endtry

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

if !empty(errors)
if !a:bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
else
call go#util#EchoSuccess("[build] SUCCESS")
Expand Down Expand Up @@ -112,23 +112,23 @@ function! go#cmd#Run(bang, ...)
let &makeprg = "go run " . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
endif

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

if g:go_dispatch_enabled && exists(':Make') == 2
silent! exe 'Make'
elseif l:quickfix == 0
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
silent! exe 'make!'
endif

let items = go#list#Get(l:quickfix)
let items = go#list#Get(l:listtype)
let errors = go#tool#FilterValids(items)

call go#list#Populate(l:quickfix, errors)
call go#list#Window(l:quickfix, len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif

let $GOPATH = old_gopath
Expand All @@ -145,7 +145,7 @@ function! go#cmd#Install(bang, ...)
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
let &makeprg = "go install " . goargs

let l:quickfix = go#list#Type(1)
let l:listtype = go#list#Type("quickfix")
" execute make inside the source folder so we can parse the errors
" correctly
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand All @@ -155,7 +155,7 @@ function! go#cmd#Install(bang, ...)
if g:go_dispatch_enabled && exists(':Make') == 2
call go#util#EchoProgress("building dispatched ...")
silent! exe 'Make'
elseif l:quickfix == 0
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
silent! exe 'make!'
Expand All @@ -165,11 +165,11 @@ function! go#cmd#Install(bang, ...)
execute cd . fnameescape(dir)
endtry

let errors = go#list#Get(l:quickfix)
call go#list#Window(l:quickfix, len(errors))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
if !a:bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
else
redraws! | echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
Expand Down Expand Up @@ -223,7 +223,7 @@ function! go#cmd#Test(bang, compile, ...)

let out = go#tool#ExecuteInDir(command)

let l:quickfix = 1
let l:listtype = "quickfix"

if v:shell_error
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand All @@ -236,18 +236,18 @@ function! go#cmd#Test(bang, compile, ...)
execute cd . fnameescape(dir)
endtry

call go#list#Populate(l:quickfix, errors)
call go#list#Window(l:quickfix, len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
elseif empty(errors)
" failed to parse errors, output the original content
call go#util#EchoError(out)
endif
echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None
else
call go#list#Clean(l:quickfix)
call go#list#Window(l:quickfix)
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)

if a:compile
echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None
Expand Down Expand Up @@ -294,20 +294,20 @@ function! go#cmd#Coverage(bang, ...)
let command = "go test -coverprofile=" . l:tmpname . ' ' . go#util#Shelljoin(a:000)


let l:quickfix = 1
let l:listtype = "quickfix"
call go#cmd#autowrite()
let out = go#tool#ExecuteInDir(command)
if v:shell_error
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:quickfix, errors)
call go#list#Window(l:quickfix, len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
else
" clear previous location list
call go#list#Clean(l:quickfix)
call go#list#Window(l:quickfix)
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)

let openHTML = 'go tool cover -html='.l:tmpname
call go#tool#ExecuteInDir(openHTML)
Expand All @@ -332,23 +332,23 @@ function! go#cmd#Generate(bang, ...)
let &makeprg = "go generate " . goargs . ' ' . gofiles
endif

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

echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None
if g:go_dispatch_enabled && exists(':Make') == 2
silent! exe 'Make'
elseif l:quickfix == 0
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
silent! exe 'make!'
endif
redraw!

let errors = go#list#Get(l:quickfix)
call go#list#Window(l:quickfix, len(errors))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
if !a:bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
else
redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None
Expand Down
10 changes: 5 additions & 5 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function! go#fmt#Format(withGoimport)
let $GOPATH = old_gopath
endif

let l:quickfix = 0
let l:listtype = "locationlist"
"if there is no error on the temp file replace the output with the current
"file (if this fails, we can always check the outputs first line with:
"splitted =~ 'package \w\+')
Expand All @@ -123,8 +123,8 @@ function! go#fmt#Format(withGoimport)
" clean up previous location list, but only if it's due fmt
if s:got_fmt_error
let s:got_fmt_error = 0
call go#list#Clean(l:quickfix)
call go#list#Window(l:quickfix)
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
endif
elseif g:go_fmt_fail_silently == 0
let splitted = split(out, '\n')
Expand All @@ -143,12 +143,12 @@ function! go#fmt#Format(withGoimport)
% | " Couldn't detect gofmt error format, output errors
endif
if !empty(errors)
call go#list#Populate(l:quickfix, errors)
call go#list#Populate(l:listtype, errors)
echohl Error | echomsg "Gofmt returned error" | echohl None
endif

let s:got_fmt_error = 1
call go#list#Window(l:quickfix, len(errors))
call go#list#Window(l:listtype, len(errors))

" We didn't use the temp file, so clean up
call delete(l:tmpname)
Expand Down
8 changes: 4 additions & 4 deletions autoload/go/jobcontrol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ function! s:on_exit(job_id, exit_status)

" if we are still in the same windows show the list
if self.winnr == winnr()
let l:quickfix = 0
call go#list#Populate(l:quickfix, errors)
call go#list#Window(l:quickfix, len(errors))
let l:listtype = "locationlist"
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !self.bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
endif
endfunction
Expand Down
52 changes: 26 additions & 26 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ function! go#lint#Gometa(autosave, ...) abort

let out = go#tool#ExecuteInDir(meta_command)

let l:quickfix = 1
let l:listtype = "quickfix"
if v:shell_error == 0
redraw | echo
call go#list#Clean(l:quickfix)
call go#list#Window(l:quickfix)
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None
else
" GoMetaLinter can output one of the two, so we look for both:
Expand All @@ -77,13 +77,13 @@ 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:quickfix, errformat, split(out, "\n"))
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))

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

if !a:autosave
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
endif
endfunction
Expand All @@ -108,11 +108,11 @@ function! go#lint#Golint(...) abort
return
endif

let l:quickfix = 1
call go#list#Parse(l:quickfix, out)
let errors = go#list#Get(l:quickfix)
call go#list#Window(l:quickfix, len(errors))
call go#list#JumpToFirst(l:quickfix)
let l:listtype = "quickfix"
call go#list#Parse(l:listtype, out)
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
call go#list#JumpToFirst(l:listtype)
endfunction

" Vet calls 'go vet' on the current directory. Any warnings are populated in
Expand All @@ -126,18 +126,18 @@ function! go#lint#Vet(bang, ...)
let out = go#tool#ExecuteInDir('go tool vet ' . go#util#Shelljoin(a:000))
endif

let l:quickfix = 1
let l:listtype = "quickfix"
if v:shell_error
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:quickfix, errors)
call go#list#Window(l:quickfix, len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
echon "vim-go: " | echohl ErrorMsg | echon "[vet] FAIL" | echohl None
else
call go#list#Clean(l:quickfix)
call go#list#Window(l:quickfix)
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
endif
endfunction
Expand Down Expand Up @@ -166,14 +166,14 @@ function! go#lint#Errcheck(...) abort
let command = bin_path . ' -abspath ' . goargs
let out = go#tool#ExecuteInDir(command)

let l:quickfix = 1
let l:listtype = "quickfix"
if v:shell_error
let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m"

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

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

if empty(errors)
echohl Error | echomsg "GoErrCheck returned error" | echohl None
Expand All @@ -182,15 +182,15 @@ function! go#lint#Errcheck(...) abort
endif

if !empty(errors)
call go#list#Populate(l:quickfix, errors)
call go#list#Window(l:quickfix, len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
call go#list#JumpToFirst(l:quickfix)
call go#list#JumpToFirst(l:listtype)
endif
endif
else
call go#list#Clean(l:quickfix)
call go#list#Window(l:quickfix)
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None
endif

Expand Down
Loading

0 comments on commit 62feccf

Please sign in to comment.