mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Updated vim plugins
This commit is contained in:
@ -4,7 +4,7 @@ function! go#cmd#autowrite() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Build builds the source code without producting any output binary. We live in
|
||||
" Build builds the source code without producing any output binary. We live in
|
||||
" an editor so the best is to build it to catch errors and fix them. By
|
||||
" default it tries to call simply 'go build', but it first tries to get all
|
||||
" dependent files for the current folder and passes it to go build.
|
||||
@ -18,8 +18,10 @@ function! go#cmd#Build(bang, ...) abort
|
||||
endif
|
||||
" create our command arguments. go build discards any results when it
|
||||
" compiles multiple packages. So we pass the `errors` package just as an
|
||||
" placeholder with the current folder (indicated with '.')
|
||||
let args = ["build"] + goargs + [".", "errors"]
|
||||
" placeholder with the current folder (indicated with '.'). We also pass -i
|
||||
" that tries to install the dependencies, this has the side effect that it
|
||||
" caches the build results, so every other build is faster.
|
||||
let args = ["build"] + goargs + ["-i", ".", "errors"]
|
||||
|
||||
if go#util#has_job()
|
||||
if get(g:, 'go_echo_command_info', 1)
|
||||
@ -109,7 +111,7 @@ function! go#cmd#RunTerm(bang, mode, files) abort
|
||||
endfunction
|
||||
|
||||
" Run runs the current file (and their dependencies if any) and outputs it.
|
||||
" This is intented to test small programs and play with them. It's not
|
||||
" This is intended to test small programs and play with them. It's not
|
||||
" suitable for long running apps, because vim is blocking by default and
|
||||
" calling long running apps will block the whole UI.
|
||||
function! go#cmd#Run(bang, ...) abort
|
||||
@ -225,145 +227,6 @@ function! go#cmd#Install(bang, ...) abort
|
||||
let &makeprg = default_makeprg
|
||||
endfunction
|
||||
|
||||
" Test runs `go test` in the current directory. If compile is true, it'll
|
||||
" compile the tests instead of running them (useful to catch errors in the
|
||||
" test files). Any other argument is appendend to the final `go test` command
|
||||
function! go#cmd#Test(bang, compile, ...) abort
|
||||
let args = ["test"]
|
||||
|
||||
" don't run the test, only compile it. Useful to capture and fix errors.
|
||||
if a:compile
|
||||
let compile_file = "vim-go-test-compile"
|
||||
call extend(args, ["-c", "-o", compile_file])
|
||||
endif
|
||||
|
||||
if a:0
|
||||
let goargs = a:000
|
||||
|
||||
" do not expand for coverage mode as we're passing the arg ourself
|
||||
if a:1 != '-coverprofile'
|
||||
" expand all wildcards(i.e: '%' to the current file name)
|
||||
let goargs = map(copy(a:000), "expand(v:val)")
|
||||
endif
|
||||
|
||||
if !(has('nvim') || go#util#has_job())
|
||||
let goargs = go#util#Shelllist(goargs, 1)
|
||||
endif
|
||||
|
||||
call extend(args, goargs, 1)
|
||||
else
|
||||
" only add this if no custom flags are passed
|
||||
let timeout = get(g:, 'go_test_timeout', '10s')
|
||||
call add(args, printf("-timeout=%s", timeout))
|
||||
endif
|
||||
|
||||
if get(g:, 'go_echo_command_info', 1)
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Identifier | echon "compiling tests ..." | echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Identifier | echon "testing ..." | echohl None
|
||||
endif
|
||||
endif
|
||||
|
||||
if go#util#has_job()
|
||||
" use vim's job functionality to call it asynchronously
|
||||
let job_args = {
|
||||
\ 'cmd': ['go'] + args,
|
||||
\ 'bang': a:bang,
|
||||
\ }
|
||||
|
||||
if a:compile
|
||||
let job_args['custom_cb'] = function('s:test_compile', [compile_file])
|
||||
endif
|
||||
|
||||
call s:cmd_job(job_args)
|
||||
return
|
||||
elseif has('nvim')
|
||||
" use nvims's job functionality
|
||||
if get(g:, 'go_term_enabled', 0)
|
||||
let id = go#term#new(a:bang, ["go"] + args)
|
||||
else
|
||||
let id = go#jobcontrol#Spawn(a:bang, "test", args)
|
||||
endif
|
||||
|
||||
if a:compile
|
||||
call go#jobcontrol#AddHandler(function('s:test_compile_handler'))
|
||||
let s:test_compile_handlers[id] = compile_file
|
||||
endif
|
||||
return id
|
||||
endif
|
||||
|
||||
call go#cmd#autowrite()
|
||||
redraw
|
||||
|
||||
let command = "go " . join(args, ' ')
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
execute cd fnameescape(expand("%:p:h"))
|
||||
|
||||
if a:compile
|
||||
call delete(compile_file)
|
||||
endif
|
||||
|
||||
if go#util#ShellError() != 0
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
let errors = go#tool#FilterValids(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)
|
||||
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:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "[test] PASS" | echohl None
|
||||
endif
|
||||
endif
|
||||
execute cd . fnameescape(dir)
|
||||
endfunction
|
||||
|
||||
" Testfunc runs a single test that surrounds the current cursor position.
|
||||
" Arguments are passed to the `go test` command.
|
||||
function! go#cmd#TestFunc(bang, ...) abort
|
||||
" search flags legend (used only)
|
||||
" 'b' search backward instead of forward
|
||||
" 'c' accept a match at the cursor position
|
||||
" 'n' do Not move the cursor
|
||||
" 'W' don't wrap around the end of the file
|
||||
"
|
||||
" for the full list
|
||||
" :help search
|
||||
let test = search('func \(Test\|Example\)', "bcnW")
|
||||
|
||||
if test == 0
|
||||
echo "vim-go: [test] no test found immediate to cursor"
|
||||
return
|
||||
end
|
||||
|
||||
let line = getline(test)
|
||||
let name = split(split(line, " ")[1], "(")[0]
|
||||
let args = [a:bang, 0, "-run", name . "$"]
|
||||
|
||||
if a:0
|
||||
call extend(args, a:000)
|
||||
endif
|
||||
|
||||
call call('go#cmd#Test', args)
|
||||
endfunction
|
||||
|
||||
" Generate runs 'go generate' in similar fashion to go#cmd#Build()
|
||||
function! go#cmd#Generate(bang, ...) abort
|
||||
let default_makeprg = &makeprg
|
||||
@ -465,24 +328,4 @@ function s:cmd_job(args) abort
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
|
||||
" test_compile is called when a GoTestCompile call is finished
|
||||
function! s:test_compile(test_file, job, exit_status, data) abort
|
||||
call delete(a:test_file)
|
||||
endfunction
|
||||
|
||||
" -----------------------
|
||||
" | Neovim job handlers |
|
||||
" -----------------------
|
||||
let s:test_compile_handlers = {}
|
||||
|
||||
function! s:test_compile_handler(job, exit_status, data) abort
|
||||
if !has_key(s:test_compile_handlers, a:job.id)
|
||||
return
|
||||
endif
|
||||
let l:compile_file = s:test_compile_handlers[a:job.id]
|
||||
call delete(l:compile_file)
|
||||
unlet s:test_compile_handlers[a:job.id]
|
||||
endfunction
|
||||
|
||||
" vim: sw=2 ts=2 et
|
||||
|
Reference in New Issue
Block a user