Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add goreturns #1888

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This plugin adds Go language support for Vim, with the following main features:
* Improved syntax highlighting and folding.
* Debug programs with integrated `delve` support with `:GoDebugStart`.
* Completion support via `gocode`.
* `gofmt` or `goimports` on save keeps the cursor position and undo history.
* `gofmt`, `goimports` or `goreturns` on save keeps the cursor position and undo history.
* Go to symbol/declaration with `:GoDef`.
* Look up documentation with `:GoDoc` or `:GoDocBrowser`.
* Easily import packages via `:GoImport`, remove them via `:GoDrop`.
Expand Down
8 changes: 5 additions & 3 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
" it doesn't undo changes and break undo history. If you are here reading
" this and have VimL experience, please look at the function for
" improvements, patches are welcome :)
function! go#fmt#Format(withGoimport) abort
function! go#fmt#Format(fmtBinFlag) abort
if go#config#FmtExperimental()
" Using winsaveview to save/restore cursor state has the problem of
" closing folds on save:
Expand Down Expand Up @@ -49,8 +49,10 @@ function! go#fmt#Format(withGoimport) abort
endif

let bin_name = go#config#FmtCommand()
if a:withGoimport == 1
if a:fmtBinFlag == 1
let bin_name = "goimports"
elseif a:fmtBinFlag == 2
let bin_name = "goreturns"
endif

let current_col = col('.')
Expand Down Expand Up @@ -157,7 +159,7 @@ function! s:fmt_cmd(bin_name, source, target)
let opts = has_key(opts, a:bin_name) ? opts[a:bin_name] : ""
endif
call extend(cmd, split(opts, " "))
if a:bin_name is# 'goimports'
if a:bin_name is# 'goimports' || a:bin_name is# 'goreturns'
call extend(cmd, ["-srcdir", a:target])
endif

Expand Down
19 changes: 16 additions & 3 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ tools developed by the Go community to provide a seamless Vim experience.
* Improved syntax highlighting and folding.
* Debug programs with integrated `delve` support with |:GoDebugStart|.
* Completion support via `gocode`.
* `gofmt` or `goimports` on save keeps the cursor position and undo history.
* `gofmt`, `goimports` or `goreturns` on save keeps the cursor position and
undo history.
* Go to symbol/declaration with |:GoDef|.
* Look up documentation with |:GoDoc| or |:GoDocBrowser|.
* Easily import packages via |:GoImport|, remove them via |:GoDrop|.
Expand Down Expand Up @@ -229,6 +230,14 @@ COMMANDS *go-commands*
`goimports` automatically discards/add import path based on the code. Like
|:GoFmt|, It tries to preserve cursor position and avoids replacing the
buffer with stderr output.
*:GoReturns*
:GoReturns

Filter the current Go buffer through goreturns (needs to be installed).
`goreturns` automatically discards/add import path and fills in Go return
statements with zero values to match the func return types based on the
code. Like |:GoFmt|, It tries to preserve cursor position and avoids
replacing the buffer with stderr output.

*:GoPlay*
:[range]GoPlay
Expand Down Expand Up @@ -959,6 +968,10 @@ annotation.

Calls `goimports` for the current package

*(go-returns)*

Calls `goreturns` for the current package

*(go-lint)*

Calls `golint` for the current package
Expand Down Expand Up @@ -2294,8 +2307,8 @@ Check it out: https://www.patreon.com/fatih
CREDITS *go-credits*

* Go Authors for official Vim plugins.
* Gocode, Godef, Golint, Guru, Goimports, Errcheck projects and authors of
those projects.
* Gocode, Godef, Golint, Guru, Goimports, Goreturns, Errcheck projects and
authors of those projects.
* Other vim-plugins, thanks for inspiration (vim-golang, go.vim, vim-gocode,
vim-godef).
* vim-go contributors: https://github.com/fatih/vim-go/graphs/contributors.
Expand Down
1 change: 1 addition & 0 deletions ftplugin/go/commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ command! -nargs=* -range -complete=customlist,go#package#Complete GoDocBrowser c
command! -nargs=0 GoFmt call go#fmt#Format(-1)
command! -nargs=0 GoFmtAutoSaveToggle call go#fmt#ToggleFmtAutoSave()
command! -nargs=0 GoImports call go#fmt#Format(1)
command! -nargs=0 GoReturns call go#fmt#Format(2)

" -- asmfmt
command! -nargs=0 GoAsmFmtAutoSaveToggle call go#asmfmt#ToggleAsmFmtAutoSave()
Expand Down
1 change: 1 addition & 0 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let s:packages = {
\ 'godef': ['github.com/rogpeppe/godef'],
\ 'gogetdoc': ['github.com/zmb3/gogetdoc'],
\ 'goimports': ['golang.org/x/tools/cmd/goimports'],
\ 'goreturns': ['github.com/sqs/goreturns'],
\ 'golint': ['github.com/golang/lint/golint'],
\ 'gometalinter': ['github.com/alecthomas/gometalinter'],
\ 'gomodifytags': ['github.com/fatih/gomodifytags'],
Expand Down