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

Updated vim plugins

This commit is contained in:
amix
2015-02-24 10:45:22 +00:00
parent 8fa0bd4574
commit d195ccb777
104 changed files with 1743 additions and 1464 deletions

View File

@ -68,7 +68,7 @@ function! go#fmt#Format(withGoimport)
" restore 'redo' history because it's getting being destroyed every
" BufWritePre
let tmpundofile=tempname()
exe 'wundo! ' . Tmpundofile
exe 'wundo! ' . tmpundofile
endif
" get the command first so we can test it

View File

@ -10,16 +10,20 @@ if !exists("g:go_oracle_bin")
let g:go_oracle_bin = "oracle"
endif
" Parses (via regex) Oracle's 'plain' format output and puts them into a
" quickfix list.
func! s:qflist(output)
let qflist = []
" Parse GNU-style 'file:line.col-line.col: message' format.
let mx = '^\(\a:[\\/][^:]\+\|[^:]\+\):\(\d\+\):\(\d\+\):\(.*\)$'
for line in split(a:output, "\n")
let ml = matchlist(line, mx)
" Ignore non-match lines or warnings
if ml == [] || ml[4] =~ '^ warning:'
continue
endif
let item = {
\ 'filename': ml[1],
\ 'text': ml[4],
@ -36,6 +40,31 @@ func! s:qflist(output)
cwindow
endfun
" This uses Vim's errorformat to parse the output from Oracle's 'plain output
" and put it into quickfix list. I believe using errorformat is much more
" easier to use. If we need more power we can always switch back to parse it
" via regex.
func! s:qflistSecond(output)
" backup users errorformat, will be restored once we are finished
let old_errorformat = &errorformat
" match two possible styles of errorformats:
"
" 'file:line.col-line2.col2: message'
" 'file:line:col: message'
"
" We discard line2 and col2 for the first errorformat, because it's not
" useful and quickfix only has the ability to show one line and column
" number
let &errorformat = "%f:%l.%c-%.%#:\ %m,%f:%l:%c:\ %m"
" create the quickfix list and open it
cgetexpr split(a:output, "\n")
cwindow
let &errorformat = old_errorformat
endfun
func! s:getpos(l, c)
if &encoding != 'utf-8'
let buf = a:l == 1 ? '' : (join(getline(1, a:l-1), "\n") . "\n")
@ -50,16 +79,21 @@ func! s:RunOracle(mode, selected) range abort
let dname = expand('%:p:h')
let pkg = go#package#ImportPath(dname)
if exists('g:go_oracle_scope_file')
" let the user defines the scope
let sname = shellescape(get(g:, 'go_oracle_scope_file'))
if exists('g:go_oracle_scope')
" let the user defines the scope, must be a space separated string,
" example: 'fmt math net/http'
let unescaped_scopes = split(get(g:, 'go_oracle_scope'))
let scopes = []
for unescaped_scope in unescaped_scopes
call add(scopes, shellescape(unescaped_scope))
endfor
elseif exists('g:go_oracle_include_tests') && pkg != -1
" give import path so it includes all _test.go files too
let sname = shellescape(pkg)
let scopes = [shellescape(pkg)]
else
" best usable way, only pass the package itself, without the test
" files
let sname = join(go#tool#Files(), ' ')
let scopes = go#tool#Files()
endif
"return with a warning if the bin doesn't exist
@ -71,16 +105,24 @@ func! s:RunOracle(mode, selected) range abort
if a:selected != -1
let pos1 = s:getpos(line("'<"), col("'<"))
let pos2 = s:getpos(line("'>"), col("'>"))
let cmd = printf('%s -format json -pos=%s:#%d,#%d %s %s',
let cmd = printf('%s -format plain -pos=%s:#%d,#%d %s',
\ bin_path,
\ shellescape(fname), pos1, pos2, a:mode, sname)
\ shellescape(fname), pos1, pos2, a:mode)
else
let pos = s:getpos(line('.'), col('.'))
let cmd = printf('%s -format json -pos=%s:#%d %s %s',
let cmd = printf('%s -format plain -pos=%s:#%d %s',
\ bin_path,
\ shellescape(fname), pos, a:mode, sname)
\ shellescape(fname), pos, a:mode)
endif
" now append each scope to the end as Oracle's scope parameter. It can be
" a packages or go files, dependent on the User's own choice. For more
" info check Oracle's User Manual section about scopes:
" https://docs.google.com/document/d/1SLk36YRjjMgKqe490mSRzOPYEDe0Y_WQNRv-EiFYUyw/view#heading=h.nwso96pj07q8
for scope in scopes
let cmd .= ' ' . scope
endfor
echon "vim-go: " | echohl Identifier | echon "analysing ..." | echohl None
let out = system(cmd)
@ -89,169 +131,65 @@ func! s:RunOracle(mode, selected) range abort
" parsable to show the real error. But the main issue is usually the
" package which doesn't build.
redraw | echon "vim-go: " | echohl Statement | echon out | echohl None
return {}
return ""
else
let json_decoded = webapi#json#decode(out)
return json_decoded
endif
return out
endfun
" Show 'implements' relation for selected package
function! go#oracle#Implements(selected)
let out = s:RunOracle('implements', a:selected)
if empty(out)
return
endif
" be sure they exists before we retrieve them from the map
if !has_key(out, "implements")
return
endif
if has_key(out.implements, "from")
let interfaces = out.implements.from
elseif has_key(out.implements, "fromptr")
let interfaces = out.implements.fromptr
else
redraw | echon "vim-go: " | echon "does not satisfy any interface"| echohl None
return
endif
" get the type name from the type under the cursor
let typeName = out.implements.type.name
" prepare the title
let title = typeName . " implements:"
" start to populate our buffer content
let result = [title, ""]
for interface in interfaces
" don't add runtime interfaces
if interface.name !~ '^runtime'
let line = interface.name . "\t" . interface.pos
call add(result, line)
endif
endfor
" open a window and put the result
call go#ui#OpenWindow("Implements", result)
" define some buffer related mappings:
"
" go to definition when hit enter
nnoremap <buffer> <CR> :<C-u>call go#ui#OpenDefinition("implements")<CR>
" close the window when hit ctrl-c
nnoremap <buffer> <c-c> :<C-u>call go#ui#CloseWindow()<CR>
call s:qflistSecond(out)
endfunction
" Describe selected syntax: definition, methods, etc
function! go#oracle#Describe(selected)
let out = s:RunOracle('describe', a:selected)
if empty(out)
return
endif
echo out
return
let detail = out["describe"]["detail"]
let desc = out["describe"]["desc"]
echo '# detail: '. detail
" package, constant, variable, type, function or statement labe
if detail == "package"
echo desc
return
endif
if detail == "value"
echo desc
echo out["describe"]["value"]
return
endif
" the rest needs to be implemented
echo desc
call s:qflistSecond(out)
endfunction
" Show possible targets of selected function call
function! go#oracle#Callees(selected)
let out = s:RunOracle('callees', a:selected)
if empty(out)
return
endif
" be sure the callees object exists which contains the position and names
" of the callees, before we continue
if !has_key(out, "callees")
return
endif
" get the callees list
if has_key(out.callees, "callees")
let callees = out.callees.callees
else
redraw | echon "vim-go: " | echon "no callees available"| echohl None
return
endif
let title = "Call targets:"
" start to populate our buffer content
let result = [title, ""]
for calls in callees
let line = calls.name . "\t" . calls.pos
call add(result, line)
endfor
" open a window and put the result
call go#ui#OpenWindow("Callees", result)
" define some buffer related mappings:
"
" go to definition when hit enter
nnoremap <buffer> <CR> :<C-u>call go#ui#OpenDefinition("call targets")<CR>
" close the window when hit ctrl-c
nnoremap <buffer> <c-c> :<C-u>call go#ui#CloseWindow()<CR>
call s:qflistSecond(out)
endfunction
" Show possible callers of selected function
function! go#oracle#Callers(selected)
let out = s:RunOracle('callers', a:selected)
echo out
call s:qflistSecond(out)
endfunction
" Show the callgraph of the current program.
function! go#oracle#Callgraph(selected)
let out = s:RunOracle('callgraph', a:selected)
echo out
call s:qflistSecond(out)
endfunction
" Show path from callgraph root to selected function
function! go#oracle#Callstack(selected)
let out = s:RunOracle('callstack', a:selected)
echo out
call s:qflistSecond(out)
endfunction
" Show free variables of selection
function! go#oracle#Freevars(selected)
let out = s:RunOracle('freevars', a:selected)
echo out
call s:qflistSecond(out)
endfunction
" Show send/receive corresponding to selected channel op
function! go#oracle#Peers(selected)
function! go#oracle#ChannelPeers(selected)
let out = s:RunOracle('peers', a:selected)
echo out
call s:qflistSecond(out)
endfunction
" Show all refs to entity denoted by selected identifier
function! go#oracle#Referrers(selected)
let out = s:RunOracle('referrers', a:selected)
echo out
call s:qflistSecond(out)
endfunction
" vim:ts=4:sw=4:et