Updated plugins
This commit is contained in:
@@ -10,9 +10,9 @@ if !exists("g:go_oracle_bin")
|
||||
endif
|
||||
|
||||
" Parses (via regex) Oracle's 'plain' format output and puts them into a
|
||||
" quickfix list.
|
||||
func! s:qflist(output)
|
||||
let qflist = []
|
||||
" location list
|
||||
func! s:loclist(output)
|
||||
let llist = []
|
||||
" Parse GNU-style 'file:line.col-line.col: message' format.
|
||||
let mx = '^\(\a:[\\/][^:]\+\|[^:]\+\):\(\d\+\):\(\d\+\):\(.*\)$'
|
||||
for line in split(a:output, "\n")
|
||||
@@ -33,17 +33,17 @@ func! s:qflist(output)
|
||||
if bnr != -1
|
||||
let item['bufnr'] = bnr
|
||||
endif
|
||||
call add(qflist, item)
|
||||
call add(llist, item)
|
||||
endfor
|
||||
call setqflist(qflist)
|
||||
cwindow
|
||||
call go#list#Populate(llist)
|
||||
call go#list#Window(len(llist))
|
||||
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
|
||||
" and put it into location 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)
|
||||
func! s:loclistSecond(output)
|
||||
" backup users errorformat, will be restored once we are finished
|
||||
let old_errorformat = &errorformat
|
||||
|
||||
@@ -53,15 +53,13 @@ func! s:qflistSecond(output)
|
||||
" '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
|
||||
" useful and location only has the ability to show one line and column
|
||||
" number
|
||||
let &errorformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
let errformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
call go#list#ParseFormat(errformat, split(a:output, "\n"))
|
||||
|
||||
" create the quickfix list and open it
|
||||
cgetexpr split(a:output, "\n")
|
||||
cwindow
|
||||
|
||||
let &errorformat = old_errorformat
|
||||
let errors = go#list#Get()
|
||||
call go#list#Window(len(errors))
|
||||
endfun
|
||||
|
||||
func! s:getpos(l, c)
|
||||
@@ -73,7 +71,7 @@ func! s:getpos(l, c)
|
||||
return line2byte(a:l) + (a:c-2)
|
||||
endfun
|
||||
|
||||
func! s:RunOracle(mode, selected) range abort
|
||||
func! s:RunOracle(mode, selected, needs_package) range abort
|
||||
let fname = expand('%:p')
|
||||
let dname = expand('%:p:h')
|
||||
let pkg = go#package#ImportPath(dname)
|
||||
@@ -81,14 +79,10 @@ func! s:RunOracle(mode, selected) range abort
|
||||
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
|
||||
let scopes = split(get(g:, 'go_oracle_scope'))
|
||||
elseif a:needs_package || exists('g:go_oracle_include_tests') && pkg != -1
|
||||
" give import path so it includes all _test.go files too
|
||||
let scopes = [shellescape(pkg)]
|
||||
let scopes = [pkg]
|
||||
else
|
||||
" best usable way, only pass the package itself, without the test
|
||||
" files
|
||||
@@ -100,27 +94,31 @@ func! s:RunOracle(mode, selected) range abort
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if exists('g:go_oracle_tags')
|
||||
let tags = get(g:, 'go_oracle_tags')
|
||||
else
|
||||
let tags = ""
|
||||
endif
|
||||
|
||||
if a:selected != -1
|
||||
let pos1 = s:getpos(line("'<"), col("'<"))
|
||||
let pos2 = s:getpos(line("'>"), col("'>"))
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d,#%d %s',
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d,#%d -tags=%s %s',
|
||||
\ bin_path,
|
||||
\ shellescape(fname), pos1, pos2, a:mode)
|
||||
\ shellescape(fname), pos1, pos2, tags, a:mode)
|
||||
else
|
||||
let pos = s:getpos(line('.'), col('.'))
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d %s',
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d -tags=%s %s',
|
||||
\ bin_path,
|
||||
\ shellescape(fname), pos, a:mode)
|
||||
\ shellescape(fname), pos, tags, 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
|
||||
let cmd .= ' ' . go#util#Shelljoin(scopes)
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "analysing ..." | echohl None
|
||||
|
||||
@@ -143,9 +141,9 @@ func! s:RunOracle(mode, selected) range abort
|
||||
endfunc
|
||||
|
||||
function! go#oracle#Scope(...)
|
||||
if len(a:000)
|
||||
if len(a:000) == 1 && a:1 == '""'
|
||||
let g:go_oracle_scope = ""
|
||||
if a:0
|
||||
if a:0 == 1 && a:1 == '""'
|
||||
unlet g:go_oracle_scope
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is cleared"| echohl None
|
||||
else
|
||||
let g:go_oracle_scope = join(a:000, ' ')
|
||||
@@ -155,59 +153,85 @@ function! go#oracle#Scope(...)
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists(g:go_oracle_scope)
|
||||
if !exists('g:go_oracle_scope')
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is not set"| echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "current oracle scope: '". g:go_oracle_scope ."'" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! go#oracle#Tags(...)
|
||||
if a:0
|
||||
if a:0 == 1 && a:1 == '""'
|
||||
unlet g:go_oracle_tags
|
||||
echon "vim-go: " | echohl Function | echon "oracle tags is cleared"| echohl None
|
||||
else
|
||||
let g:go_oracle_tags = a:1
|
||||
echon "vim-go: " | echohl Function | echon "oracle tags changed to: '". g:go_oracle_tags ."'" | echohl None
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists('g:go_oracle_tags')
|
||||
echon "vim-go: " | echohl Function | echon "oracle tags is not set"| echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "current oracle tags: '". g:go_oracle_tags ."'" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Show 'implements' relation for selected package
|
||||
function! go#oracle#Implements(selected)
|
||||
let out = s:RunOracle('implements', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('implements', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Describe selected syntax: definition, methods, etc
|
||||
function! go#oracle#Describe(selected)
|
||||
let out = s:RunOracle('describe', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('describe', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show possible targets of selected function call
|
||||
function! go#oracle#Callees(selected)
|
||||
let out = s:RunOracle('callees', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callees', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show possible callers of selected function
|
||||
function! go#oracle#Callers(selected)
|
||||
let out = s:RunOracle('callers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callers', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show path from callgraph root to selected function
|
||||
function! go#oracle#Callstack(selected)
|
||||
let out = s:RunOracle('callstack', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callstack', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show free variables of selection
|
||||
function! go#oracle#Freevars(selected)
|
||||
let out = s:RunOracle('freevars', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
" Freevars requires a selection
|
||||
if a:selected == -1
|
||||
echon "vim-go: " | echohl Statement | echon "GoFreevars requires a selection (range) of code "| echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let out = s:RunOracle('freevars', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show send/receive corresponding to selected channel op
|
||||
function! go#oracle#ChannelPeers(selected)
|
||||
let out = s:RunOracle('peers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('peers', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show all refs to entity denoted by selected identifier
|
||||
function! go#oracle#Referrers(selected)
|
||||
let out = s:RunOracle('referrers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('referrers', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
||||
Reference in New Issue
Block a user