1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 01:25:00 +08:00

Updated plugins

This commit is contained in:
amix
2016-12-27 11:46:49 -03:00
parent 04abc6907c
commit a6de243fca
67 changed files with 2836 additions and 1097 deletions

View File

@ -1,7 +1,7 @@
let s:go_stack = []
let s:go_stack_level = 0
function! go#def#Jump(mode)
function! go#def#Jump(mode) abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
@ -27,42 +27,53 @@ function! go#def#Jump(mode)
endif
let command = printf("%s -f=%s -o=%s -t", bin_path, fname, go#util#OffsetCursor())
let out = go#util#System(command)
" append the type information to the same line so our
" jump_to_declaration() function can parse it. This makes it
" compatible with guru definition as well too
let out = join(split(out, '\n'), ':')
if exists("l:tmpname")
call delete(l:tmpname)
endif
elseif bin_name == 'guru'
let flags = ""
let in = ""
if &modified
let sep = go#util#LineEnding()
let content = join(getline(1, '$'), sep)
let in = fname . "\n" . strlen(content) . "\n" . content
let flags .= " -modified"
endif
let bin_path = go#path#CheckBinPath("guru")
if empty(bin_path)
let $GOPATH = old_gopath
return
endif
if exists('g:go_guru_tags')
let tags = get(g:, 'go_guru_tags')
let flags .= printf(" -tags %s", tags)
endif
let fname = shellescape(fname.':#'.go#util#OffsetCursor())
let command = printf("%s %s definition %s", bin_path, flags, fname)
let cmd = [bin_path]
let stdin_content = ""
if &modified
let out = go#util#System(command, in)
let sep = go#util#LineEnding()
let content = join(getline(1, '$'), sep)
let stdin_content = fname . "\n" . strlen(content) . "\n" . content
call add(cmd, "-modified")
endif
if exists('g:go_guru_tags')
let tags = get(g:, 'go_guru_tags')
call extend(cmd, ["-tags", tags])
endif
let fname = fname.':#'.go#util#OffsetCursor()
call extend(cmd, ["definition", fname])
if go#util#has_job()
let l:spawn_args = {
\ 'cmd': cmd,
\ 'custom_cb': function('s:jump_to_declaration_cb', [a:mode, bin_name]),
\ }
if &modified
let l:spawn_args.input = stdin_content
endif
call go#util#EchoProgress("searching declaration ...")
call s:def_job(spawn_args)
return
endif
let command = join(cmd, " ")
if &modified
let out = go#util#System(command, stdin_content)
else
let out = go#util#System(command)
endif
@ -76,13 +87,28 @@ function! go#def#Jump(mode)
return
endif
call s:jump_to_declaration(out, a:mode)
call s:jump_to_declaration(out, a:mode, bin_name)
let $GOPATH = old_gopath
endfunction
function! s:jump_to_declaration(out, mode)
function! s:jump_to_declaration_cb(mode, bin_name, job, exit_status, data) abort
if a:exit_status != 0
return
endif
call s:jump_to_declaration(a:data[0], a:mode, a:bin_name)
endfunction
function! s:jump_to_declaration(out, mode, bin_name) abort
let final_out = a:out
if a:bin_name == "godef"
" append the type information to the same line so our we can parse it.
" This makes it compatible with guru output.
let final_out = join(split(a:out, '\n'), ':')
endif
" strip line ending
let out = split(a:out, go#util#LineEnding())[0]
let out = split(final_out, go#util#LineEnding())[0]
if go#util#IsWin()
let parts = split(out, '\(^[a-zA-Z]\)\@<!:')
else
@ -120,19 +146,27 @@ function! s:jump_to_declaration(out, mode)
if get(g:, 'go_def_reuse_buffer', 0) && bufloaded(filename) != 0 && bufwinnr(filename) != -1
" jumpt to existing buffer if it exists
execute bufwinnr(filename) . 'wincmd w'
elseif a:mode == "tab"
let &switchbuf = "usetab"
if bufloaded(filename) == 0
tab split
else
if &modified
let cmd = 'hide edit'
else
let cmd = 'edit'
endif
elseif a:mode == "split"
split
elseif a:mode == "vsplit"
vsplit
endif
" open the file and jump to line and column
exec 'edit' filename
if a:mode == "tab"
let &switchbuf = "usetab"
if bufloaded(filename) == 0
tab split
endif
elseif a:mode == "split"
split
elseif a:mode == "vsplit"
vsplit
endif
" open the file and jump to line and column
exec cmd filename
endif
endif
call cursor(line, col)
@ -142,7 +176,7 @@ function! s:jump_to_declaration(out, mode)
let &switchbuf = old_switchbuf
endfunction
function! go#def#SelectStackEntry()
function! go#def#SelectStackEntry() abort
let target_window = go#ui#GetReturnWindow()
if empty(target_window)
let target_window = winnr()
@ -157,7 +191,7 @@ function! go#def#SelectStackEntry()
call go#ui#CloseWindow()
endfunction
function! go#def#StackUI()
function! go#def#StackUI() abort
if len(s:go_stack) == 0
call go#util#EchoError("godef stack empty")
return
@ -192,12 +226,12 @@ function! go#def#StackUI()
noremap <buffer> <silent> q :<C-U>call go#ui#CloseWindow()<CR>
endfunction
function! go#def#StackClear(...)
function! go#def#StackClear(...) abort
let s:go_stack = []
let s:go_stack_level = 0
endfunction
function! go#def#StackPop(...)
function! go#def#StackPop(...) abort
if len(s:go_stack) == 0
call go#util#EchoError("godef stack empty")
return
@ -218,7 +252,7 @@ function! go#def#StackPop(...)
call go#def#Stack(newLevel + 1)
endfunction
function! go#def#Stack(...)
function! go#def#Stack(...) abort
if len(s:go_stack) == 0
call go#util#EchoError("godef stack empty")
return
@ -246,7 +280,13 @@ function! go#def#Stack(...)
let target = s:go_stack[s:go_stack_level]
" jump
exec 'edit' target["file"]
if expand('%:p') != target["file"]
if &modified
exec 'hide edit' target["file"]
else
exec 'edit' target["file"]
endif
endif
call cursor(target["line"], target["col"])
normal! zz
else
@ -254,4 +294,27 @@ function! go#def#Stack(...)
endif
endfunction
function s:def_job(args) abort
function! s:error_info_cb(job, exit_status, data) closure
" do not print anything during async definition search&jump
endfunction
let a:args.error_info_cb = function('s:error_info_cb')
let callbacks = go#job#Spawn(a:args)
let start_options = {
\ 'callback': callbacks.callback,
\ 'close_cb': callbacks.close_cb,
\ }
if &modified
let l:tmpname = tempname()
call writefile(split(a:args.input, "\n"), l:tmpname, "b")
let l:start_options.in_io = "file"
let l:start_options.in_name = l:tmpname
endif
call job_start(a:args.cmd, start_options)
endfunction
" vim: sw=2 ts=2 et