Skip to content

Commit

Permalink
Add GoTags command to set build tags for oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
gonotes committed Oct 15, 2015
1 parent 17b57b9 commit d010758
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
35 changes: 31 additions & 4 deletions autoload/go/oracle.vim
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,32 @@ func! s:RunOracle(mode, selected, needs_package) 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
let cmd .= ' ' . go#util#Shelljoin(scopes)
" echon "vim-go: " | echohl Function | echon "current cmd is: '". cmd ."'" | echohl None

echon "vim-go: " | echohl Identifier | echon "analysing ..." | echohl None

Expand Down Expand Up @@ -156,6 +163,26 @@ function! go#oracle#Scope(...)
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, 0)
Expand Down
5 changes: 5 additions & 0 deletions autoload/go/tool.vim
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ function! go#tool#Files()
else
let command = "go list -f '{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}'"
endif

if exists('g:go_oracle_tags')
let command .= ' ' .command
endif

let out = go#tool#ExecuteInDir(command)
return split(out, '\n')
endfunction
Expand Down
1 change: 1 addition & 0 deletions ftplugin/go/commands.vim
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ command! -range=% GoCallstack call go#oracle#Callstack(<count>)
command! -range=% GoFreevars call go#oracle#Freevars(<count>)
command! -range=% GoChannelPeers call go#oracle#ChannelPeers(<count>)
command! -range=% GoReferrers call go#oracle#Referrers(<count>)
command! -nargs=? GoTags call go#oracle#Tags(<f-args>)

" tool
command! -nargs=0 GoFiles echo go#tool#Files()
Expand Down

0 comments on commit d010758

Please sign in to comment.