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

Updated plugins

This commit is contained in:
amix
2017-03-07 18:04:28 +01:00
parent fe46dfbbe6
commit ccb7854aa2
103 changed files with 1729 additions and 445 deletions

View File

@ -4,10 +4,10 @@ Write here what's happening and what you're expecting instead of...
### Steps to reproduce:
Please create a reproducible case of your problem. If this step is
Please create a reproducible case of your problem. If this step is
not provided, the issue will be **closed**
Re produce it with a minimal `vimrc` with all plugins disabled and
Re produce it with a minimal `vimrc` with all plugins disabled and
only `vim-go` enabled:
1.
@ -20,7 +20,6 @@ Add here your current configuration and additional information that might be
useful, such as:
* `vimrc` you used to reproduce
* vim version:
* vim version:
* vim-go version:
* go version:
* go version:

View File

@ -19,4 +19,3 @@ install: |
cd -
script: ./scripts/test.sh

View File

@ -2,6 +2,7 @@
FEATURES:
* New `:GoAddTags` and `:GoRemoveTags` command based on the tool [gomodifytags](https://github.com/fatih/gomodifytags). This fixes many old bugs that were due prior regexp based implementation. For the usage please read the docs and checkout the demo at: https://github.com/fatih/vim-go/pull/1204 [gh-1204]
* Add new `errl` snippet that expands to [gh-1185]:
```
@ -14,6 +15,10 @@ IMPROVEMENTS:
* Lowercase `<Leader>` in mappings examples for consisten documentation across the README [gh-1192]
* All of files should be written in utf-8 if the file will be passed to external command. [gh-1184]
* `:GoAddTags` is now able to add options to existing tags with the syntax `:GoAddTags key,option`, i.e: `:GoAddTags json,omitempty` [gh-985]
* Document 'noshowmode' requirement for echo_go_info [gh-1197]
* Improve godoc view for vertical splits [gh-1195]
* Set GOPATH for both possible go guru execution paths (sync and async) [gh-1193]
BUG FIXES:
@ -22,6 +27,15 @@ BUG FIXES:
* Update statusline before and after `go#jobcontrol#Spawn` command is executed [gh-1176]
* Correctly report the value of the 'g:go_guru_tags' variable [gh-1177]
* Ensure no trailing `:` exist in GOPATH detection if initial GOPATH is not set [gh-1194]
* Fix `:GoAddTags` to allow modifying existing comments [gh-984]
* Fix `:GoAddTags` to work with nested structs [gh-990]
* Fix `:GoAddTags` adding tags twice for existing tags [gh-1064]
* Fix `:GoAddTags` not working for fiels of types `interface{}` [gh-1091]
* Fix `:GoAddTags` not working for fields with one line comments [gh-1181]
* Fix `:GoAddTags` not working if any field comment would contain `{}` [gh-1189]
* Respect go_fmt_options when running goimports [gh-1211]
* Set the filename in the location-list when there is an error with :GoFmt [gh-1199]
## 1.11 - (January 9, 2017)
@ -80,7 +94,7 @@ FEATURES:
you have at least Vim 8.0.0087. Backwards compatible with Vim 7.4.x.
If you see any problems, please open an issue.
* We have now a [logo for vim-go](https://github.com/fatih/vim-go/blob/master/assets/vim-go.png)! Thanks to @egonelbre for his work on this.
* We have now a [logo for vim-go](https://github.com/fatih/vim-go/blob/master/assets/vim-go.png)! Thanks to @egonelbre for his work on this.
* `:GoBuild`, `:GoTest`, `:GoTestCompile`, `:GoInstall` commands are now fully
async. Async means it doesn't block your UI anymore. If the command finished
it echoes the status. For a better experience use the statusline information
@ -95,7 +109,7 @@ FEATURES:
`:GoMetaLinterAutoSaveToggle` (temporary) or add `let
g:go_metalinter_autosave = 1` (persistent) to your virmc).
* All `guru` commands run asynchronously if Vim 8.0 is being used. Current
* All `guru` commands run asynchronously if Vim 8.0 is being used. Current
Commands:
* GoImplements
* GoWhicherrs
@ -111,7 +125,7 @@ FEATURES:
auto sameids mode. In this mode it constantly evaluates the identifier under the
cursor whenever it's in hold position and then calls :GoSameIds. As a
reminder, to enable auto info either call `:GoSameIdsAutoToggle`(temporary)
or add `let g:go_auto_sameids = 1` (persistent) to your vimrc.
or add `let g:go_auto_sameids = 1` (persistent) to your vimrc.
* `:GoInfo` is now non blocking and works in async mode if `guru` is used in
`g:go_info_mode`. This makes it useful especially for autoinfo mode. In this
@ -221,7 +235,7 @@ FEATURES:
* The snippet expansion `json` is now much more smarter. It pre populates the placeholder according to the first word and it also applies `snake_case` or `camelCase` conversion. Together with `:GoAddTags` it gives `vim-go` users flexible ways of populating a field tag. Checkout the demo to see it in action: https://twitter.com/fatih/status/754477622042689536 [gh-927]
* New **`:GoSameIds`** command. When called highlights all same identifiers in the current file. Can be also enabled to highlight identifiers automatically (with `:GoSameIdsAutoToggle` or `g:go_auto_sameids`). Checkout the demo to see it in action: https://twitter.com/fatih/status/753673709278339072. [gh-936]
* New **`:GoWhicherrs`** command. It shows all possible values of the selected error variable. [gh-948]
* Add new `errp` snippet to expand an `if err != nil { panic() }` clause [gh-926]
* Add new `errp` snippet to expand an `if err != nil { panic() }` clause [gh-926]
* If you open a new buffer with a Go filename it get automatically populated based on the directory. If there are no Go files a simple main package is created, otherwise the file will include the package declaration line based on the package in the current directory. Checkout the demo to see it in action: https://twitter.com/fatih/status/748333086643994624. This is enabled by default. Can be disabled with `let g:go_template_autocreate = 0`. You can use your own template with `let g:go_template_file = "foo.go"` and putting the file under the `templates/` folder. [gh-918]
* Added new toggle commands to enable/disable feature that run for your
automatic. For example if you have `let g:go_auto_type_info = 1` enabled, you
@ -371,4 +385,3 @@ BACKWARDS INCOMPATIBILITIES:
## Previous releases
Previous changelogs can be found here: https://github.com/fatih/vim-go/releases

View File

@ -25,7 +25,7 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software includes some portions from Go. Go is used under the terms of the
BSD like license.

View File

@ -1,4 +1,4 @@
# vim-go [![Build Status](http://img.shields.io/travis/fatih/vim-go.svg?style=flat-square)](https://travis-ci.org/fatih/vim-go)
# vim-go [![Build Status](http://img.shields.io/travis/fatih/vim-go.svg?style=flat-square)](https://travis-ci.org/fatih/vim-go)
<p align="center">
<img style="float: right;" src="assets/vim-go.png" alt="Vim-go logo"/>
@ -235,9 +235,9 @@ let g:go_get_update = 0
### Using with Neovim (beta)
Note: Neovim currently is not a first class citizen for vim-go. You are free
to open bug, however I'm not using Neovim so it's hard for me to test it.
vim-go might not work well as good as in Vim. I'm happy to accept pull requests
or very detailed bug reports. If you're interested to improve the state of
to open bug, however I'm not using Neovim so it's hard for me to test it.
vim-go might not work well as good as in Vim. I'm happy to accept pull requests
or very detailed bug reports. If you're interested to improve the state of
Neovim in vim-go you're always welcome!

View File

@ -39,7 +39,7 @@ function! ctrlp#decls#accept(mode, str) abort
let vals = matchlist(a:str, '|\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)|')
" i.e: main.go
let filename = vals[1]
let filename = vals[1]
let line = vals[2]
let col = vals[3]
@ -119,7 +119,7 @@ function! ctrlp#decls#enter() abort
let space .= " "
endfor
call add(s:decls, printf("%s\t%s |%s:%s:%s|\t%s",
call add(s:decls, printf("%s\t%s |%s:%s:%s|\t%s",
\ decl.ident . space,
\ decl.keyword,
\ fnamemodify(decl.filename, ":t"),
@ -135,7 +135,7 @@ function! s:enable_syntax() abort
return
endif
syntax match CtrlPIdent '\zs\h\+\ze\s'
syntax match CtrlPIdent '\zs\h\+\ze\s'
syntax match CtrlPKeyword '\zs[^\t|]\+\ze|[^|]\+:\d\+:\d\+|'
syntax match CtrlPFilename '|\zs[^|]\+:\d\+:\d\+\ze|'
syntax match CtrlPSignature '\zs\t.*\ze$' contains=CtrlPKeyWord,CtrlPFilename

View File

@ -373,7 +373,7 @@ function! go#cmd#Generate(bang, ...) abort
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
if !empty(errors)
if !a:bang
call go#list#JumpToFirst(l:listtype)
endif

View File

@ -27,11 +27,11 @@ function! s:gocodeCommand(cmd, preargs, args) abort
let $GOROOT = go#util#env("goroot")
let socket_type = get(g:, 'go_gocode_socket_type', s:sock_type)
let cmd = printf('%s -sock %s %s %s %s',
\ go#util#Shellescape(bin_path),
\ socket_type,
\ join(a:preargs),
\ go#util#Shellescape(a:cmd),
let cmd = printf('%s -sock %s %s %s %s',
\ go#util#Shellescape(bin_path),
\ socket_type,
\ join(a:preargs),
\ go#util#Shellescape(a:cmd),
\ join(a:args)
\ )
@ -55,7 +55,7 @@ endfunction
let s:optionsEnabled = 0
function! s:gocodeEnableOptions() abort
if s:optionsEnabled
if s:optionsEnabled
return
endif

View File

@ -34,7 +34,7 @@ function! go#coverage#Buffer(bang, ...) abort
try
execute cd . fnameescape(expand("%:p:h"))
if empty(glob("*_test.go"))
call go#util#EchoError("no tests files available")
call go#util#EchoError("no test files available")
return
endif
finally
@ -89,8 +89,8 @@ function! go#coverage#Clear() abort
if exists("s:toggle") | let s:toggle = 0 | endif
" remove the autocmd we defined
if exists("#BufWinLeave#<buffer>")
" remove the autocmd we defined
if exists("#BufWinLeave#<buffer>")
autocmd! BufWinLeave <buffer>
endif
endfunction
@ -160,8 +160,8 @@ function! go#coverage#genmatch(cov) abort
" example: foo.go:92.2,92.65 1 0
if a:cov.startline == a:cov.endline
call add(matches, {
\ 'group': color,
\ 'pos': [[a:cov.startline, a:cov.startcol, a:cov.endcol - a:cov.startcol]],
\ 'group': color,
\ 'pos': [[a:cov.startline, a:cov.startcol, a:cov.endcol - a:cov.startcol]],
\ 'priority': 2,
\ })
return matches
@ -171,8 +171,8 @@ function! go#coverage#genmatch(cov) abort
" the line, we assume it is at maximum 200 bytes. I know this is hacky,
" but that's only way of fixing the issue
call add(matches, {
\ 'group': color,
\ 'pos': [[a:cov.startline, a:cov.startcol, 200]],
\ 'group': color,
\ 'pos': [[a:cov.startline, a:cov.startcol, 200]],
\ 'priority': 2,
\ })
@ -181,16 +181,16 @@ function! go#coverage#genmatch(cov) abort
while start_line < a:cov.endline
let start_line += 1
call add(matches, {
\ 'group': color,
\ 'pos': [[start_line]],
\ 'group': color,
\ 'pos': [[start_line]],
\ 'priority': 2,
\ })
endwhile
" finally end columns
call add(matches, {
\ 'group': color,
\ 'pos': [[a:cov.endline, a:cov.endcol-1]],
\ 'group': color,
\ 'pos': [[a:cov.endline, a:cov.endcol-1]],
\ 'priority': 2,
\ })

View File

@ -209,7 +209,7 @@ function! go#def#StackUI() abort
let prefix = " "
endif
call add(stackOut, printf("%s %d %s|%d col %d|%s",
call add(stackOut, printf("%s %d %s|%d col %d|%s",
\ prefix, i+1, entry["file"], entry["line"], entry["col"], entry["ident"]))
let i += 1
endwhile

View File

@ -32,10 +32,10 @@ function! go#doc#OpenBrowser(...) abort
let import = out["import"]
let name = out["name"]
let decl = out["decl"]
let godoc_url = "https://godoc.org/" . import
if decl !~ "^package"
let godoc_url .= "#" . name
let godoc_url .= "#" . name
endif
echo godoc_url
@ -92,13 +92,20 @@ function! s:GodocView(newposition, position, content) abort
execute bufwinnr(s:buf_nr) . 'wincmd w'
endif
" cap buffer height to 20, but resize it for smaller contents
let max_height = 20
let content_height = len(split(a:content, "\n"))
if content_height > max_height
exe 'resize ' . max_height
if a:position == "split"
" cap buffer height to 20, but resize it for smaller contents
let max_height = 20
let content_height = len(split(a:content, "\n"))
if content_height > max_height
exe 'resize ' . max_height
else
exe 'resize ' . content_height
endif
else
exe 'resize ' . content_height
" set a sane maximum width for vertical splits. In this case the minimum
" that fits the godoc for package http without extra linebreaks and line
" numbers on
exe 'vertical resize 84'
endif
setlocal filetype=godoc

View File

@ -77,7 +77,7 @@ function! go#fmt#Format(withGoimport) abort
if go#util#ShellError() == 0
call go#fmt#update_file(l:tmpname, expand('%'))
elseif g:go_fmt_fail_silently == 0
let errors = s:parse_errors(out)
let errors = s:parse_errors(expand('%'), out)
call s:show_errors(errors)
endif
@ -102,7 +102,7 @@ function! go#fmt#Format(withGoimport) abort
endfunction
" update_file updates the target file with the given formatted source
function! go#fmt#update_file(source, target)
function! go#fmt#update_file(source, target)
" remove undo point caused via BufWritePre
try | silent undojoin | catch | endtry
@ -133,8 +133,8 @@ endfunction
" run runs the gofmt/goimport command for the given source file and returns
" the the output of the executed command. Target is the real file to be
" formated.
function! go#fmt#run(bin_name, source, target)
" formated.
function! go#fmt#run(bin_name, source, target)
let cmd = s:fmt_cmd(a:bin_name, a:source, a:target)
if cmd[0] == "goimports"
" change GOPATH too, so goimports can pick up the correct library
@ -168,10 +168,9 @@ function! s:fmt_cmd(bin_name, source, target)
" start constructing the command
let cmd = [bin_path]
call add(cmd, "-w")
call extend(cmd, split(g:go_fmt_options, " "))
if a:bin_name != "goimports"
call extend(cmd, split(g:go_fmt_options, " "))
else
if a:bin_name == "goimports"
" lazy check if goimports support `-srcdir`. We should eventually remove
" this in the future
if !exists('b:goimports_vendor_compatible')
@ -196,7 +195,7 @@ function! s:fmt_cmd(bin_name, source, target)
endfunction
" parse_errors parses the given errors and returns a list of parsed errors
function! s:parse_errors(content) abort
function! s:parse_errors(filename, content) abort
let splitted = split(a:content, '\n')
" list of errors to be put into location list
@ -205,6 +204,7 @@ function! s:parse_errors(content) abort
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
if !empty(tokens)
call add(errors,{
\"filename": a:filename,
\"lnum": tokens[2],
\"col": tokens[3],
\"text": tokens[4],
@ -218,13 +218,13 @@ endfunction
" show_errors opens a location list and shows the given errors. If the given
" errors is empty, it closes the the location list
function! s:show_errors(errors) abort
let l:listtype = "locationlist"
let l:listtype = "locationlist"
if !empty(a:errors)
call go#list#Populate(l:listtype, a:errors, 'Format')
echohl Error | echomsg "Gofmt returned error" | echohl None
endif
" this closes the window if there are no errors or it opens
" this closes the window if there are no errors or it opens
" it if there is any
call go#list#Window(l:listtype, len(a:errors))
endfunction

View File

@ -25,7 +25,7 @@ function! s:guru_cmd(args) range abort
endif
"return with a warning if the binary doesn't exist
let bin_path = go#path#CheckBinPath("guru")
let bin_path = go#path#CheckBinPath("guru")
if empty(bin_path)
return {'err': "bin path not found"}
endif
@ -41,7 +41,7 @@ function! s:guru_cmd(args) range abort
endif
" enable outputting in json format
if format == "json"
if format == "json"
call add(cmd, "-json")
endif
@ -120,8 +120,6 @@ function! s:sync_guru(args) abort
endif
endif
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" run, forrest run!!!
let command = join(result.cmd, " ")
@ -131,8 +129,6 @@ function! s:sync_guru(args) abort
let out = go#util#System(command)
endif
let $GOPATH = old_gopath
if has_key(a:args, 'custom_parse')
call a:args.custom_parse(go#util#ShellError(), out)
else
@ -217,11 +213,17 @@ endfunc
" run_guru runs the given guru argument
function! s:run_guru(args) abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
if go#util#has_job()
return s:async_guru(a:args)
let res = s:async_guru(a:args)
else
let res = s:sync_guru(a:args)
endif
return s:sync_guru(a:args)
let $GOPATH = old_gopath
return res
endfunction
" Show 'implements' relation for selected package
@ -270,7 +272,7 @@ endfunction
function! go#guru#DescribeInfo() abort
" json_encode() and friends are introduced with this patch (7.4.1304)
" vim: https://groups.google.com/d/msg/vim_dev/vLupTNhQhZ8/cDGIk0JEDgAJ
" nvim: https://github.com/neovim/neovim/pull/4131
" nvim: https://github.com/neovim/neovim/pull/4131
if !exists("*json_decode")
call go#util#EchoError("requires 'json_decode'. Update your Vim/Neovim version.")
return
@ -465,7 +467,7 @@ function! go#guru#SameIds() abort
" json_encode() and friends are introduced with this patch (7.4.1304)
" vim: https://groups.google.com/d/msg/vim_dev/vLupTNhQhZ8/cDGIk0JEDgAJ
" nvim: https://github.com/neovim/neovim/pull/4131
" nvim: https://github.com/neovim/neovim/pull/4131
if !exists("*json_decode")
call go#util#EchoError("GoSameIds requires 'json_decode'. Update your Vim/Neovim version.")
return
@ -547,7 +549,7 @@ function! go#guru#ClearSameIds() abort
endfunction
function! go#guru#ToggleSameIds() abort
if len(getmatches()) != 0
if len(getmatches()) != 0
call go#guru#ClearSameIds()
else
call go#guru#SameIds()

View File

@ -18,7 +18,7 @@ function! go#impl#Impl(...) abort
return
endif
elseif a:0 == 1
" we assume the user only passed the interface type,
" we assume the user only passed the interface type,
" i.e: ':GoImpl io.Writer'
let receiveType = expand("<cword>")
let recv = printf("%s *%s", tolower(receiveType)[0], receiveType)
@ -44,7 +44,7 @@ function! go#impl#Impl(...) abort
end
let pos = getpos('.')
put =''
put =''
put =result
call setpos('.', pos)
endfunction

View File

@ -109,9 +109,9 @@ endfunction
" Golint calls 'golint' on the current directory. Any warnings are populated in
" the location list
function! go#lint#Golint(...) abort
let bin_path = go#path#CheckBinPath(g:go_golint_bin)
if empty(bin_path)
return
let bin_path = go#path#CheckBinPath(g:go_golint_bin)
if empty(bin_path)
return
endif
if a:0 == 0
@ -280,7 +280,7 @@ function s:lint_job(args)
call go#statusline#Update(status_dir, status)
let errors = go#list#Get(l:listtype)
if empty(errors)
if empty(errors)
call go#list#Window(l:listtype, len(errors))
elseif has("patch-7.4.2200")
if l:listtype == 'quickfix'

View File

@ -124,7 +124,7 @@ function! go#list#Type(listtype) abort
if g:go_list_type == "locationlist"
return "locationlist"
elseif g:go_list_type == "quickfix"
return "quickfix"
return "quickfix"
else
return a:listtype
endif

View File

@ -70,7 +70,7 @@ function! s:get_visual_selection() abort
return join(lines, "\n")
endfunction
" following two functions are from: https://github.com/mattn/gist-vim
" following two functions are from: https://github.com/mattn/gist-vim
" thanks @mattn
function! s:get_browser_command() abort
let go_play_browser_command = get(g:, 'go_play_browser_command', '')

View File

@ -4,7 +4,7 @@
" s:statuses is a global reference to all statuses. It stores the statuses per
" import paths (map[string]status), where each status is unique per its
" type. Current status dict is in form:
" {
" {
" 'desc' : 'Job description',
" 'state' : 'Job state, such as success, failure, etc..',
" 'type' : 'Job type, such as build, test, etc..'

View File

@ -0,0 +1,206 @@
function! go#tags#Add(start, end, count, ...) abort
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
if &modified
" Write current unsaved buffer to a temp file and use the modified content
let l:tmpname = tempname()
call writefile(getline(1, '$'), l:tmpname)
let fname = l:tmpname
endif
let offset = 0
if a:count == -1
let offset = go#util#OffsetCursor()
endif
let test_mode = 0
call call("go#tags#run", [a:start, a:end, offset, "add", fname, test_mode] + a:000)
" if exists, delete it as we don't need it anymore
if exists("l:tmpname")
call delete(l:tmpname)
endif
endfunction
function! go#tags#Remove(start, end, count, ...) abort
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
if &modified
" Write current unsaved buffer to a temp file and use the modified content
let l:tmpname = tempname()
call writefile(getline(1, '$'), l:tmpname)
let fname = l:tmpname
endif
let offset = 0
if a:count == -1
let offset = go#util#OffsetCursor()
endif
let test_mode = 0
call call("go#tags#run", [a:start, a:end, offset, "remove", fname, test_mode] + a:000)
" if exists, delete it as we don't need it anymore
if exists("l:tmpname")
call delete(l:tmpname)
endif
endfunction
" run runs gomodifytag. This is an internal test so we can test it
function! go#tags#run(start, end, offset, mode, fname, test_mode, ...) abort
" do not split this into multiple lines, somehow tests fail in that case
let args = {'mode': a:mode,'start': a:start,'end': a:end,'offset': a:offset,'fname': a:fname,'cmd_args': a:000}
let result = s:create_cmd(args)
if has_key(result, 'err')
call go#util#EchoError(result.err)
return -1
endif
let command = join(result.cmd, " ")
call go#cmd#autowrite()
let out = go#util#System(command)
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
endif
if a:test_mode
exe 'edit ' . a:fname
endif
call s:write_out(out)
if a:test_mode
exe 'write! ' . a:fname
endif
endfunc
" write_out writes back the given output to the current buffer
func s:write_out(out) abort
" not a json output
if a:out[0] !=# '{'
return
endif
" nothing to do
if empty(a:out) || type(a:out) != type("")
return
endif
let result = json_decode(a:out)
if type(result) != type({})
call go#util#EchoError(printf("malformed output from gomodifytags: %s", a:out))
return
endif
let lines = result['lines']
let start_line = result['start']
let end_line = result['end']
let index = 0
for line in range(start_line, end_line)
call setline(line, lines[index])
let index += 1
endfor
endfunc
" create_cmd returns a dict that contains the command to execute gomodifytags
func s:create_cmd(args) abort
if !exists("*json_decode")
return {'err': "requires 'json_decode'. Update your Vim/Neovim version."}
endif
let bin_path = go#path#CheckBinPath('gomodifytags')
if empty(bin_path)
return {'err': "gomodifytags does not exist"}
endif
let l:start = a:args.start
let l:end = a:args.end
let l:offset = a:args.offset
let l:mode = a:args.mode
let l:cmd_args = a:args.cmd_args
" start constructing the command
let cmd = [bin_path]
call extend(cmd, ["-format", "json"])
call extend(cmd, ["-file", a:args.fname])
if l:offset != 0
call extend(cmd, ["-offset", l:offset])
else
let range = printf("%d,%d", l:start, l:end)
call extend(cmd, ["-line", range])
endif
if l:mode == "add"
let l:tags = []
let l:options = []
if !empty(l:cmd_args)
for item in l:cmd_args
let splitted = split(item, ",")
" tag only
if len(splitted) == 1
call add(l:tags, splitted[0])
endif
" options only
if len(splitted) == 2
call add(l:tags, splitted[0])
call add(l:options, printf("%s=%s", splitted[0], splitted[1]))
endif
endfor
endif
" construct options
if !empty(l:options)
call extend(cmd, ["-add-options", join(l:options, ",")])
else
" default value
if empty(l:tags)
let l:tags = ["json"]
endif
" construct tags
call extend(cmd, ["-add-tags", join(l:tags, ",")])
endif
elseif l:mode == "remove"
if empty(l:cmd_args)
call add(cmd, "-clear-tags")
else
let l:tags = []
let l:options = []
for item in l:cmd_args
let splitted = split(item, ",")
" tag only
if len(splitted) == 1
call add(l:tags, splitted[0])
endif
" options only
if len(splitted) == 2
call add(l:options, printf("%s=%s", splitted[0], splitted[1]))
endif
endfor
" construct tags
if !empty(l:tags)
call extend(cmd, ["-remove-tags", join(l:tags, ",")])
endif
" construct options
if !empty(l:options)
call extend(cmd, ["-remove-options", join(l:options, ",")])
endif
endif
else
return {'err': printf("unknown mode: %s", l:mode)}
endif
return {'cmd': cmd}
endfunc

View File

@ -0,0 +1,28 @@
func Test_add_tags()
let input_file = tempname()
call writefile(readfile("test-fixtures/tags/add_all_input.go"), input_file)
let expected = join(readfile("test-fixtures/tags/add_all_golden.go"), "\n")
" run for offset 40, which is inside the struct
call go#tags#run(0, 0, 40, "add", input_file, 1)
let actual = join(readfile(input_file), "\n")
call assert_equal(expected, actual)
endfunc
func Test_remove_tags()
let input_file = tempname()
call writefile(readfile("test-fixtures/tags/remove_all_input.go"), input_file)
let expected = join(readfile("test-fixtures/tags/remove_all_golden.go"), "\n")
" run for offset 40, which is inside the struct
call go#tags#run(0, 0, 40, "remove", input_file, 1)
let actual = join(readfile(input_file), "\n")
call assert_equal(expected, actual)
endfunc

View File

@ -67,7 +67,7 @@ function! go#textobj#Function(mode) abort
normal! v
call cursor(info.rbrace.line, info.rbrace.col)
return
endif
endif
" rest is inner mode, a:mode == 'i'

View File

@ -164,7 +164,7 @@ function! go#tool#Exists(importpath) abort
endfunction
" following two functions are from: https://github.com/mattn/gist-vim
" following two functions are from: https://github.com/mattn/gist-vim
" thanks @mattn
function! s:get_browser_command() abort
let go_play_browser_command = get(g:, 'go_play_browser_command', '')

View File

@ -53,7 +53,7 @@ let s:env_cache = {}
" env returns the go environment variable for the given key. Where key can be
" GOARCH, GOOS, GOROOT, etc... It caches the result and returns the cached
" version.
" version.
function! go#util#env(key) abort
let l:key = tolower(a:key)
if has_key(s:env_cache, l:key)

View File

@ -576,7 +576,7 @@ CTRL-t
*:GoSameIdsToggle*
:GoSameIdsToggle
Toggle between |:GoSameIds| and |:GoSameIdsClear|.
Toggle between |:GoSameIds| and |:GoSameIdsClear|.
*:GoSameIdsAutoToggle*
:GoSameIdsAutoToggle
@ -669,12 +669,13 @@ CTRL-t
:GoImpl T io.ReadWriteCloser
<
*:GoAddTags*
:[range]GoAddTags [key] [key1] ...
:[range]GoAddTags [key],[option] [key1],[option] ...
Adds field tags for the fields of a struct. If called inside a struct it
automatically add field tags with the `json` key and the value
automatically generated based on the field name. An error message is given
if it's called outside a struct definition.
if it's called outside a struct definition or if the file is not correctly
formatted.
If [range] is given, only the selected fields will be changed.
@ -682,6 +683,37 @@ CTRL-t
arguments. An example of adding `xml` and `db` would be:
>
:GoAddTags xml db
<
If [option] is passed it'll either add a new tag with an option or will
modify exising tags. An example of adding `omitempty` to all `json` fields
would be:
>
:GoAddTags json,omitempty
<
You can define a constant value instead of the default field based value.
For example the following command will add ``valid:"1"`` to all fields.
>
:GoAddTags valid=1
<
*:GoRemoveTags*
:[range]GoRemoveTags [key],[option] [key1],[option1] ...
Rmove field tags for the fields of a struct. If called inside a struct it
automatically remove all field tags. An error message is given if it's
called outside a struct definition or if the file is not correctly
formatted
If [range] is given, only the selected fields will be changed.
If [key] is given, it will only remove those keys. Example:
>
:GoRemoveTags json
<
If [option] is passed with a [key], it will only remove the options.
Example, this will only remove `omitempty` options from fields containing
`json`:
>
:GoRemoveTags json,omitempty
<
*:GoAutoTypeInfoToggle*
:GoAutoTypeInfoToggle
@ -958,7 +990,7 @@ Shows the status of a job running asynchronously. Can be used to plug into the
statusline. It works to show the status per package instead of per
file. Assume you have three files open, all belonging to the same package, if
the package build (`:GoBuild`) is successful, all statusline's will show
`success`, if you it fails all file's statusline will show `failed`.
`success`, if you it fails all file's statusline will show `failed`.
To avoid always showing old status information, the status information is
cleaned for each package after `60` seconds. This can be changed with the
@ -1488,6 +1520,8 @@ default it's enabled >
let g:go_echo_go_info = 1
<
Please note that 'noshowmode' must be set for this feature to work correctly.
*'g:go_statusline_duration'*
Specifices the duration of statusline information being showed per package. By

View File

@ -14,14 +14,15 @@ command! -range=% GoChannelPeers call go#guru#ChannelPeers(<count>)
command! -range=% GoReferrers call go#guru#Referrers(<count>)
command! -nargs=? GoGuruTags call go#guru#Tags(<f-args>)
command! -nargs=* -range GoAddTags call go#util#AddTags(<line1>, <line2>, <f-args>)
command! -range=0 GoSameIds call go#guru#SameIds()
command! -range=0 GoSameIdsClear call go#guru#ClearSameIds()
command! -range=0 GoSameIdsToggle call go#guru#ToggleSameIds()
command! -range=0 GoSameIdsAutoToggle call go#guru#AutoToogleSameIds()
" -- tags
command! -nargs=* -range GoAddTags call go#tags#Add(<line1>, <line2>, <count>, <f-args>)
command! -nargs=* -range GoRemoveTags call go#tags#Remove(<line1>, <line2>, <count>, <f-args>)
" -- tool
command! -nargs=0 GoFiles echo go#tool#Files()
command! -nargs=0 GoDeps echo go#tool#Deps()

View File

@ -15,9 +15,9 @@ endif
function! s:SetTagbar()
let bin_path = go#path#CheckBinPath(g:go_gotags_bin)
if empty(bin_path)
return
let bin_path = go#path#CheckBinPath(g:go_gotags_bin)
if empty(bin_path)
return
endif
if !exists("g:tagbar_type_go")

View File

@ -175,7 +175,7 @@ if err != nil {
${0}
endsnippet
# error test
# error test
snippet errt "Error test fatal " !b
if err != nil {
t.Fatal(err)

View File

@ -18,6 +18,7 @@ let s:packages = [
\ "github.com/jstemmer/gotags",
\ "github.com/klauspost/asmfmt/cmd/asmfmt",
\ "github.com/fatih/motion",
\ "github.com/fatih/gomodifytags",
\ "github.com/zmb3/gogetdoc",
\ "github.com/josharian/impl",
\ ]

View File

@ -4,6 +4,9 @@ set -e
cd $(dirname $0)
# install dependencies
go get github.com/fatih/gomodifytags
# cleanup test.log
if [ -f "test.log" ]; then
rm test.log