From d0107582ab99e5412d62bbaea029afd3b7d1fab7 Mon Sep 17 00:00:00 2001 From: gonotes Date: Thu, 15 Oct 2015 16:36:16 +0800 Subject: [PATCH] Add GoTags command to set build tags for oracle --- autoload/go/oracle.vim | 35 +++++++++++++++++++++++++++++++---- autoload/go/tool.vim | 5 +++++ ftplugin/go/commands.vim | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) mode change 100644 => 100755 autoload/go/oracle.vim mode change 100644 => 100755 autoload/go/tool.vim mode change 100644 => 100755 ftplugin/go/commands.vim diff --git a/autoload/go/oracle.vim b/autoload/go/oracle.vim old mode 100644 new mode 100755 index cd754734a7..3be362ca08 --- a/autoload/go/oracle.vim +++ b/autoload/go/oracle.vim @@ -96,18 +96,24 @@ 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 @@ -115,6 +121,7 @@ func! s:RunOracle(mode, selected, needs_package) range abort " 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 @@ -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) diff --git a/autoload/go/tool.vim b/autoload/go/tool.vim old mode 100644 new mode 100755 index 64bc026744..767fc6f6d8 --- a/autoload/go/tool.vim +++ b/autoload/go/tool.vim @@ -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 diff --git a/ftplugin/go/commands.vim b/ftplugin/go/commands.vim old mode 100644 new mode 100755 index 3d998ba40b..31e2a3a983 --- a/ftplugin/go/commands.vim +++ b/ftplugin/go/commands.vim @@ -11,6 +11,7 @@ command! -range=% GoCallstack call go#oracle#Callstack() command! -range=% GoFreevars call go#oracle#Freevars() command! -range=% GoChannelPeers call go#oracle#ChannelPeers() command! -range=% GoReferrers call go#oracle#Referrers() +command! -nargs=? GoTags call go#oracle#Tags() " tool command! -nargs=0 GoFiles echo go#tool#Files()