mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Updated vim plugins
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,135 +0,0 @@
|
||||
" json
|
||||
" Last Change: 2012-03-08
|
||||
" Maintainer: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||
" License: This file is placed in the public domain.
|
||||
" Reference:
|
||||
"
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! webapi#json#null()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! webapi#json#true()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! webapi#json#false()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:nr2byte(nr)
|
||||
if a:nr < 0x80
|
||||
return nr2char(a:nr)
|
||||
elseif a:nr < 0x800
|
||||
return nr2char(a:nr/64+192).nr2char(a:nr%64+128)
|
||||
else
|
||||
return nr2char(a:nr/4096%16+224).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:nr2enc_char(charcode)
|
||||
if &encoding == 'utf-8'
|
||||
return nr2char(a:charcode)
|
||||
endif
|
||||
let char = s:nr2byte(a:charcode)
|
||||
if strlen(char) > 1
|
||||
let char = strtrans(iconv(char, 'utf-8', &encoding))
|
||||
endif
|
||||
return char
|
||||
endfunction
|
||||
|
||||
function! s:fixup(val, tmp)
|
||||
if type(a:val) == 0
|
||||
return a:val
|
||||
elseif type(a:val) == 1
|
||||
if a:val == a:tmp.'null'
|
||||
return function('webapi#json#null')
|
||||
elseif a:val == a:tmp.'true'
|
||||
return function('webapi#json#true')
|
||||
elseif a:val == a:tmp.'false'
|
||||
return function('webapi#json#false')
|
||||
endif
|
||||
return a:val
|
||||
elseif type(a:val) == 2
|
||||
return a:val
|
||||
elseif type(a:val) == 3
|
||||
return map(a:val, 's:fixup(v:val, a:tmp)')
|
||||
elseif type(a:val) == 4
|
||||
return map(a:val, 's:fixup(v:val, a:tmp)')
|
||||
else
|
||||
return string(a:val)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! webapi#json#decode(json)
|
||||
let json = iconv(a:json, "utf-8", &encoding)
|
||||
if get(g:, 'webapi#json#parse_strict', 1) == 1 && substitute(substitute(substitute(
|
||||
\ json,
|
||||
\ '\\\%(["\\/bfnrt]\|u[0-9a-fA-F]\{4}\)', '\@', 'g'),
|
||||
\ '"[^\"\\\n\r]*\"\|true\|false\|null\|-\?\d\+'
|
||||
\ . '\%(\.\d*\)\?\%([eE][+\-]\{-}\d\+\)\?', ']', 'g'),
|
||||
\ '\%(^\|:\|,\)\%(\s*\[\)\+', '', 'g') !~ '^[\],:{} \t\n]*$'
|
||||
throw json
|
||||
endif
|
||||
let json = substitute(json, '\n', '', 'g')
|
||||
let json = substitute(json, '\\u34;', '\\"', 'g')
|
||||
if v:version >= 703 && has('patch780')
|
||||
let json = substitute(json, '\\u\(\x\x\x\x\)', '\=iconv(nr2char(str2nr(submatch(1), 16), 1), "utf-8", &encoding)', 'g')
|
||||
else
|
||||
let json = substitute(json, '\\u\(\x\x\x\x\)', '\=s:nr2enc_char("0x".submatch(1))', 'g')
|
||||
endif
|
||||
if get(g:, 'webapi#json#allow_nil', 0) != 0
|
||||
let tmp = '__WEBAPI_JSON__'
|
||||
while 1
|
||||
if stridx(json, tmp) == -1
|
||||
break
|
||||
endif
|
||||
let tmp .= '_'
|
||||
endwhile
|
||||
let [null,true,false] = [
|
||||
\ tmp.'null',
|
||||
\ tmp.'true',
|
||||
\ tmp.'false']
|
||||
sandbox let ret = eval(json)
|
||||
call s:fixup(ret, tmp)
|
||||
else
|
||||
let [null,true,false] = [0,1,0]
|
||||
sandbox let ret = eval(json)
|
||||
endif
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function! webapi#json#encode(val)
|
||||
if type(a:val) == 0
|
||||
return a:val
|
||||
elseif type(a:val) == 1
|
||||
let json = '"' . escape(a:val, '\"') . '"'
|
||||
let json = substitute(json, "\r", '\\r', 'g')
|
||||
let json = substitute(json, "\n", '\\n', 'g')
|
||||
let json = substitute(json, "\t", '\\t', 'g')
|
||||
let json = substitute(json, '\([[:cntrl:]]\)', '\=printf("\x%02d", char2nr(submatch(1)))', 'g')
|
||||
return iconv(json, &encoding, "utf-8")
|
||||
elseif type(a:val) == 2
|
||||
let s = string(a:val)
|
||||
if s == "function('webapi#json#null')"
|
||||
return 'null'
|
||||
elseif s == "function('webapi#json#true')"
|
||||
return 'true'
|
||||
elseif s == "function('webapi#json#false')"
|
||||
return 'false'
|
||||
endif
|
||||
elseif type(a:val) == 3
|
||||
return '[' . join(map(copy(a:val), 'webapi#json#encode(v:val)'), ',') . ']'
|
||||
elseif type(a:val) == 4
|
||||
return '{' . join(map(keys(a:val), 'webapi#json#encode(v:val).":".webapi#json#encode(a:val[v:val])'), ',') . '}'
|
||||
else
|
||||
return string(a:val)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et:
|
Reference in New Issue
Block a user