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-05-02 14:42:08 +02:00
parent c4fbfe8aa8
commit 85e105159e
63 changed files with 1389 additions and 737 deletions

View File

@ -1,5 +1,13 @@
## unplanned
IMPROVEMENTS
* :GoMetaLinter can now exclude linters with the new `g:go_metalinter_excludes` option [gh-1253]
BUG FIXES:
* job: fix race between channel close and job exit [gh-1247]
## 1.12 - (March 29, 2017)
FEATURES:

View File

@ -4,336 +4,64 @@
<img style="float: right;" src="assets/vim-go.png" alt="Vim-go logo"/>
</p>
Go (golang) support for Vim, which comes with pre-defined sensible settings (like
auto gofmt on save), with autocomplete, snippet support, improved syntax
highlighting, go toolchain commands, and more. If needed vim-go installs all
necessary binaries for providing seamless Vim integration with current
commands. It's highly customizable and each individual feature can be
disabled/enabled easily.
## Features
* Improved Syntax highlighting with items such as Functions, Operators, Methods.
* Auto completion support via `gocode`
* Better `gofmt` on save, which keeps cursor position and doesn't break your undo
history
* Go to symbol/declaration with `:GoDef`
* Look up documentation with `:GoDoc` inside Vim or open it in browser
* Automatically import packages via `:GoImport` or plug it into autosave
* Compile your package with `:GoBuild`, install it with `:GoInstall` or test
them with `:GoTest` (also supports running single tests via `:GoTestFunc`)
This plugin adds Go language support for Vim, with the following main features:
* Build with `:GoBuild`, install with `:GoInstall` or test
with `:GoTest` (run single tests via `:GoTestFunc`)
* Show test coverage with `:GoCoverage` or in browser with `:GoCoverageBrowser`
* Goto definition with `:GoDef`
* Quick jump to declarations with `:GoDecls` or `:GoDeclsDir`
* Show documentation with `:GoDoc` inside or in browser with `:GoDocBrowser`
* Quickly execute your current file/files with `:GoRun`
* Automatic `GOPATH` detection based on the directory structure (i.e. `gb`
projects, `godep` vendored projects)
* Change or display `GOPATH` with `:GoPath`
* Create a coverage profile and display annotated source code to see which
functions are covered with `:GoCoverage`
* Call `gometalinter` with `:GoMetaLinter`, which invokes all possible linters
(golint, vet, errcheck, deadcode, etc..) and shows the warnings/errors
* Lint your code with `:GoLint`
* Run your code through `:GoVet` to catch static errors
* Advanced source analysis tools utilizing guru, such as `:GoImplements`,
`:GoCallees`, and `:GoReferrers`
* Precise type-safe renaming of identifiers with `:GoRename`
* List all source files and dependencies
* Unchecked error checking with `:GoErrCheck`
* Integrated and improved snippets, supporting `ultisnips` or `neosnippet`
* Share your current code to [play.golang.org](http://play.golang.org) with `:GoPlay`
* On-the-fly type information about the word under the cursor. Plug it into
your custom vim function.
* Go asm formatting on save
* Tagbar support to show tags of the source code in a sidebar with `gotags`
* Custom vim text objects such as `a function` or `inner function`
list.
* Jump to function or type declarations with `:GoDecls` or `:GoDeclsDir`
* Vim 8.0 support. Async execution for most commands, various underlying improvements.
* NeoVim support (beta). Async execution for some commands.
* Alternate between implementation and test code with `:GoAlternate`
* Change or display `GOPATH` with `:GoPath`
* Multiple 3rd linter support with `:GoMetaLinter`
* Renaming identifiers with `:GoRename`
* Share your code to [play.golang.org](http://play.golang.org) with `:GoPlay`
* Switch between `*.go` and `*_test.go` code with `:GoAlternate`
* Add/Remove tags on struct fields with `:GoAddTags`
* Add import paths via `:GoImport` or remove them with `:GoDrop`
* Custom vim text objects such as `a function (af)` or `inner function (if)`
* ... and many more! Please see [doc/vim-go.txt](doc/vim-go.txt) for more information.
Checkout the official [tutorial](https://github.com/fatih/vim-go-tutorial)
that goes literally over all features and shows many tips and tricks. It shows
how to install vim-go and explains many unknown use cases. Recommended for
beginners as well as advanced users: https://github.com/fatih/vim-go-tutorial
## Install
Master branch is supposed to be a development branch. So stuff here can break
and change. Please try use always the [latest
release](https://github.com/fatih/vim-go/releases/latest)
Master branch is a **development** branch. Please use with caution.
I recommend to use the [**latest stable release**](https://github.com/fatih/vim-go/releases/latest)
Vim-go follows the standard runtime path structure, so I highly recommend to
use a common and well known plugin manager to install vim-go. Do not use vim-go
with other Go oriented vim plugins. For Pathogen just clone the repo. For other
plugin managers add the appropriate lines and execute the plugin's install
command.
Vim-go follows the standard runtime path structure. Below are some helper lines
for popular package managers:
* [Pathogen](https://github.com/tpope/vim-pathogen)
* `git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go`
* `git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go`
* [vim-plug](https://github.com/junegunn/vim-plug)
* `Plug 'fatih/vim-go'`
* [NeoBundle](https://github.com/Shougo/neobundle.vim)
* `NeoBundle 'fatih/vim-go'`
* [Vundle](https://github.com/gmarik/vundle)
* `Plugin 'fatih/vim-go'`
* [Vim packages](http://vimhelp.appspot.com/repeat.txt.html#packages) (since Vim 7.4.1528)
* `git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go`
* `Plug 'fatih/vim-go'`
* [Vim packages](http://vimhelp.appspot.com/repeat.txt.html#packages)
* `git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go`
Please be sure all necessary binaries are installed (such as `gocode`, `godef`,
`goimports`, etc.). You can easily install them with the included
`:GoInstallBinaries` command. If invoked, all necessary binaries will be
automatically downloaded and installed to your `$GOBIN` environment (if not set
it will use `$GOPATH/bin`). Note that this command requires `git` for fetching
the individual Go packages. Additionally, use `:GoUpdateBinaries` to update the
installed binaries.
After installing, please install all necessary binaries. We have a handy
command for it:
### Optional
```
:GoInstallBinaries
```
* Autocompletion is enabled by default via `<C-x><C-o>`. To get real-time
completion (completion by type) install:
[neocomplete](https://github.com/Shougo/neocomplete.vim) for Vim or
[deoplete](https://github.com/Shougo/deoplete.nvim) and
[deoplete-go](https://github.com/zchee/deoplete-go) for NeoVim or
[SimpleAutoCmplPop](https://github.com/roxma/SimpleAutoComplPop)
* To display source code tag information on a sidebar install
[tagbar](https://github.com/majutsushi/tagbar).
* For snippet features install:
[neosnippet](https://github.com/Shougo/neosnippet.vim) or
[ultisnips](https://github.com/SirVer/ultisnips).
* Screenshot color scheme is a slightly modified molokai:
[fatih/molokai](https://github.com/fatih/molokai).
* For a better documentation viewer checkout:
[go-explorer](https://github.com/garyburd/go-explorer).
for more information please check out the [documentation](doc/vim-go.txt)
## Usage
Many of the plugin's [features](#features) are enabled by default. There are no
additional settings needed. All usages and commands are listed in
`doc/vim-go.txt`. Note that help tags needs to be populated. Check your plugin
manager settings to generate the documentation (some do it automatically).
After that just open the help page to see all commands:
:help vim-go
## Example Mappings
vim-go has several `<Plug>` mappings which can be used to create custom
mappings. Unless otherwise specified, none of these mappings are enabled
by default. Here some examples you might find useful:
Run commands such as `go run` for the current file with `<leader>r` or `go
build` and `go test` for the current package with `<leader>b` and `<leader>t`
respectively. Display beautifully annotated source code to see which functions
are covered with `<leader>c`.
```vim
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
```
By default the mapping `gd` is enabled, which opens the target identifier in
current buffer. You can also open the definition/declaration, in a new vertical,
horizontal, or tab, for the word under your cursor:
```vim
au FileType go nmap <leader>ds <Plug>(go-def-split)
au FileType go nmap <leader>dv <Plug>(go-def-vertical)
au FileType go nmap <leader>dt <Plug>(go-def-tab)
```
Open the relevant Godoc for the word under the cursor with `<leader>gd` or open
it vertically with `<leader>gv`
```vim
au FileType go nmap <leader>gd <Plug>(go-doc)
au FileType go nmap <leader>gv <Plug>(go-doc-vertical)
```
Or open the Godoc in browser
```vim
au FileType go nmap <leader>gb <Plug>(go-doc-browser)
```
Show a list of interfaces which is implemented by the type under your cursor
with `<leader>s`
```vim
au FileType go nmap <leader>s <Plug>(go-implements)
```
Show type info for the word under your cursor with `<leader>i` (useful if you
have disabled auto showing type info via `g:go_auto_type_info`)
```vim
au FileType go nmap <leader>i <Plug>(go-info)
```
Rename the identifier under the cursor to a new name
```vim
au FileType go nmap <leader>e <Plug>(go-rename)
```
More `<Plug>` mappings can be seen with `:he go-mappings`. Also these are just
recommendations, you are free to create more advanced mappings or functions
based on `:he go-commands`.
## Settings
Below are some settings you might find useful. For the full list see `:he
go-settings`.
By default syntax-highlighting for Functions, Methods and Structs is disabled.
To change it:
```vim
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
```
Enable goimports to automatically insert import paths instead of gofmt:
```vim
let g:go_fmt_command = "goimports"
```
By default vim-go shows errors for the fmt command, to disable it:
```vim
let g:go_fmt_fail_silently = 1
```
Disable auto fmt on save:
```vim
let g:go_fmt_autosave = 0
```
Disable opening browser after posting your snippet to `play.golang.org`:
```vim
let g:go_play_open_browser = 0
```
By default when `:GoInstallBinaries` is called, the binaries are installed to
`$GOBIN` or `$GOPATH/bin`. To change it:
```vim
let g:go_bin_path = expand("~/.gotools")
let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path
```
Disable updating dependencies when installing/updating binaries:
```vim
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
Neovim in vim-go you're always welcome!
Run `:GoRun` in a new tab, horizontal split or vertical split terminal
```vim
au FileType go nmap <leader>rt <Plug>(go-run-tab)
au FileType go nmap <leader>rs <Plug>(go-run-split)
au FileType go nmap <leader>rv <Plug>(go-run-vertical)
```
By default new terminals are opened in a vertical split. To change it
```vim
let g:go_term_mode = "split"
```
By default the testing commands run asynchronously in the background and
display results with `go#jobcontrol#Statusline()`. To make them run in a new
terminal
```vim
let g:go_term_enabled = 1
```
### Using with Syntastic
Sometimes when using both `vim-go` and `syntastic` Vim will start lagging while
saving and opening files. The following fixes this:
```vim
let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck']
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
```
Another issue with `vim-go` and `syntastic` is that the location list window
that contains the output of commands such as `:GoBuild` and `:GoTest` might not appear.
To resolve this:
```vim
let g:go_list_type = "quickfix"
```
## More info
Check out the [Wiki](https://github.com/fatih/vim-go/wiki) page for more
information. It includes
[Screencasts](https://github.com/fatih/vim-go/wiki/Screencasts), an [FAQ
section](https://github.com/fatih/vim-go/wiki/FAQ-Troubleshooting), and many
other [various pieces](https://github.com/fatih/vim-go/wiki) of information.
## Development & Testing
vim-go supports now test files. Please check `autoload` folder for examples. If
you add a new feature be sure you also include the `_test.vim` file next to the
script. Test functions should be starting with `Test_`, example:
```viml
function Test_run_fmt()
call assert_equal(expected, actual)
...
endfunction
```
You can locally test it by running:
Official documentation can be found under [doc/vim-go.txt](doc/vim-go.txt). You can display it from within Vim with:
```
make
:help vim-go
```
This will run all tests and print either `PASS` or `FAIL` to indicate the final
status of all tests.
Additionally, each new pull request will trigger a new Travis-ci job.
## Donation
People have asked for this for a long time, now you can be a fully supporter by
[being a patron](https://www.patreon.com/fatih)!
By being a patron, you are enabling vim-go to grow and mature, helping me to
invest in bug fixes, new documentation, and improving both current and future
features. It's completely optional and is just a direct way to support Vim-go's
ongoing development. Thanks!
[https://www.patreon.com/fatih](https://www.patreon.com/fatih)
## Credits
* Go Authors for official vim plugins
* Gocode, Godef, Golint, Guru, Goimports, Gotags, Errcheck projects and
authors of those projects.
* Other vim-plugins, thanks for inspiration (vim-golang, go.vim, vim-gocode,
vim-godef)
* [Contributors](https://github.com/fatih/vim-go/graphs/contributors) of vim-go
We also have an [official vim-go
tutorial](https://github.com/fatih/vim-go-tutorial).
## License
The BSD 3-Clause License - see `LICENSE` for more details
The BSD 3-Clause License - see [`LICENSE`](LICENSE) for more details

View File

@ -445,7 +445,7 @@ function s:cmd_job(args) abort
let start_options = {
\ 'callback': callbacks.callback,
\ 'close_cb': callbacks.close_cb,
\ 'exit_cb': callbacks.exit_cb,
\ }
" modify GOPATH if needed

View File

@ -288,7 +288,7 @@ function s:coverage_job(args)
let start_options = {
\ 'callback': callbacks.callback,
\ 'close_cb': callbacks.close_cb,
\ 'exit_cb': callbacks.exit_cb,
\ }
" modify GOPATH if needed

View File

@ -303,7 +303,7 @@ function s:def_job(args) abort
let start_options = {
\ 'callback': callbacks.callback,
\ 'close_cb': callbacks.close_cb,
\ 'exit_cb': callbacks.exit_cb,
\ }
if &modified

View File

@ -155,21 +155,12 @@ function! s:async_guru(args) abort
endif
endif
function! s:close_cb(chan) closure
let messages = []
while ch_status(a:chan, {'part': 'out'}) == 'buffered'
let msg = ch_read(a:chan, {'part': 'out'})
call add(messages, msg)
endwhile
while ch_status(a:chan, {'part': 'err'}) == 'buffered'
let msg = ch_read(a:chan, {'part': 'err'})
call add(messages, msg)
endwhile
let l:job = ch_getjob(a:chan)
let l:info = job_info(l:job)
let messages = []
function! s:callback(chan, msg) closure
call add(messages, a:msg)
endfunction
function! s:exit_cb(job, exitval) closure
let out = join(messages, "\n")
let status = {
@ -178,21 +169,22 @@ function! s:async_guru(args) abort
\ 'state': "finished",
\ }
if l:info.exitval
if a:exitval
let status.state = "failed"
endif
call go#statusline#Update(status_dir, status)
if has_key(a:args, 'custom_parse')
call a:args.custom_parse(l:info.exitval, out)
call a:args.custom_parse(a:exitval, out)
else
call s:parse_guru_output(l:info.exitval, out, a:args.mode)
call s:parse_guru_output(a:exitval, out, a:args.mode)
endif
endfunction
let start_options = {
\ 'close_cb': funcref("s:close_cb"),
\ 'callback': funcref("s:callback"),
\ 'exit_cb': funcref("s:exit_cb"),
\ }
if has_key(result, 'stdin_content')

View File

@ -30,28 +30,17 @@ function go#job#Spawn(args)
call add(self.messages, a:msg)
endfunction
function cbs.close_cb(chan) dict
let l:job = ch_getjob(a:chan)
let l:status = job_status(l:job)
" the job might be in fail status, we assume by default it's failed.
" However if it's dead, we can use the real exitval
let exitval = 1
if l:status == "dead"
let l:info = job_info(l:job)
let exitval = l:info.exitval
endif
function cbs.exit_cb(job, exitval) dict
if has_key(self, 'custom_cb')
call self.custom_cb(l:job, exitval, self.messages)
call self.custom_cb(a:job, a:exitval, self.messages)
endif
if has_key(self, 'error_info_cb')
call self.error_info_cb(l:job, exitval, self.messages)
call self.error_info_cb(a:job, a:exitval, self.messages)
endif
if get(g:, 'go_echo_command_info', 1)
if exitval == 0
if a:exitval == 0
call go#util#EchoSuccess("SUCCESS")
else
call go#util#EchoError("FAILED")
@ -59,7 +48,7 @@ function go#job#Spawn(args)
endif
let l:listtype = go#list#Type("quickfix")
if exitval == 0
if a:exitval == 0
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
return
@ -99,9 +88,9 @@ function go#job#Spawn(args)
let cbs.callback = a:args.callback
endif
" override close callback handler if user provided it
if has_key(a:args, 'close_cb')
let cbs.close_cb = a:args.close_cb
" override exit callback handler if user provided it
if has_key(a:args, 'exit_cb')
let cbs.exit_cb = a:args.exit_cb
endif
return cbs

View File

@ -10,6 +10,10 @@ if !exists("g:go_metalinter_enabled")
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
endif
if !exists("g:go_metalinter_excludes")
let g:go_metalinter_excludes = []
endif
if !exists("g:go_golint_bin")
let g:go_golint_bin = "golint"
endif
@ -40,6 +44,10 @@ function! go#lint#Gometa(autosave, ...) abort
let cmd += ["--enable=".linter]
endfor
for exclude in g:go_metalinter_excludes
let cmd += ["--exclude=".exclude]
endfor
" path
let cmd += [expand('%:p:h')]
else
@ -252,23 +260,14 @@ function s:lint_job(args)
copen
endfunction
function! s:close_cb(chan) closure
let l:job = ch_getjob(a:chan)
let l:status = job_status(l:job)
let exitval = 1
if l:status == "dead"
let l:info = job_info(l:job)
let exitval = l:info.exitval
endif
function! s:exit_cb(job, exitval) closure
let status = {
\ 'desc': 'last status',
\ 'type': "gometaliner",
\ 'state': "finished",
\ }
if exitval
if a:exitval
let status.state = "failed"
endif
@ -297,7 +296,7 @@ function s:lint_job(args)
let start_options = {
\ 'callback': funcref("s:callback"),
\ 'close_cb': funcref("s:close_cb"),
\ 'exit_cb': funcref("s:exit_cb"),
\ }
call job_start(a:args.cmd, start_options)

View File

@ -71,28 +71,25 @@ function s:rename_job(args)
let status_dir = expand('%:p:h')
function! s:close_cb(chan) closure
let l:job = ch_getjob(a:chan)
let l:info = job_info(l:job)
function! s:exit_cb(job, exitval) closure
let status = {
\ 'desc': 'last status',
\ 'type': "gorename",
\ 'state': "finished",
\ }
if l:info.exitval
if a:exitval
let status.state = "failed"
endif
call go#statusline#Update(status_dir, status)
call s:parse_errors(l:info.exitval, a:args.bang, messages)
call s:parse_errors(a:exitval, a:args.bang, messages)
endfunction
let start_options = {
\ 'callback': funcref("s:callback"),
\ 'close_cb': funcref("s:close_cb"),
\ 'exit_cb': funcref("s:exit_cb"),
\ }
" modify GOPATH if needed

View File

@ -21,8 +21,10 @@ CONTENTS *go-contents*
5. Text Objects.................................|go-text-objects|
6. Functions....................................|go-functions|
7. Settings.....................................|go-settings|
8. Troubleshooting..............................|go-troubleshooting|
9. Credits......................................|go-credits|
8. FAQ/Troubleshooting..........................|go-troubleshooting|
9. Development..................................|go-development|
10. Donation.....................................|go-donation|
11. Credits......................................|go-credits|
==============================================================================
INTRO *go-intro*
@ -100,7 +102,7 @@ command.
Plugin 'fatih/vim-go'
* Vim |packages| (since Vim 7.4.1528)
* Vim |packages|
>
git clone https://github.com/fatih/vim-go.git \
~/.vim/pack/plugins/start/vim-go
@ -1349,6 +1351,13 @@ Specifies the currently enabled linters for the |:GoMetaLinter| command. By
default it's using `vet`, `golint` and `errcheck`.
>
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
<
*'g:go_metalinter_excludes'*
Specifies the linters to be excluded from the |:GoMetaLinter| command. By
default it's empty
>
let g:go_metalinter_excludes = []
<
*'g:go_metalinter_command'*
@ -1530,7 +1539,29 @@ default it's 60 seconds. Must be in milliseconds.
let g:go_statusline_duration = 60000
<
==============================================================================
TROUBLESHOOTING *go-troubleshooting*
DEVELOPMENT *go-development*
vim-go supports test files written in VimL. Please check `autoload` folder for
examples. If you add a new feature be sure you also include the `_test.vim`
file next to the script. Test functions should be starting with `Test_`,
example:
>
function Test_run_fmt()
call assert_equal(expected, actual)
...
endfunction
<
You can locally test it by running:
>
make
<
This will run all tests and print either `PASS` or `FAIL` to indicate the final
status of all tests. Additionally, each new pull request will trigger a new
Travis-ci job.
==============================================================================
FAQ TROUBLESHOOTING *go-troubleshooting*
I get "not an editor command" error when I invoke :GoXXX~
@ -1568,15 +1599,63 @@ If you see errors like this:
>
Error installing golang.org/x/tools/cmd/goimports
<
that means your local Go setup is broken or the remote website is down. For
that means your local Go setup is broken or the remote website is down. For
example sometimes code.google.com times out. To test, just execute a simple
`go get`:
>
go get golang.org/x/tools/cmd/goimports
<
You'll see a more detailed error. If this works, vim-go will work too.
How do I use vim-go with syntastic?~
Sometimes when using both `vim-go` and `syntastic` Vim will start lagging
while saving and opening files. The following fixes this:
>
let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck']
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
<
Another issue with `vim-go` and `syntastic` is that the location list window
that contains the output of commands such as `:GoBuild` and `:GoTest` might
not appear. To resolve this:
>
let g:go_list_type = "quickfix"
<
Using with NeoVim~
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
Neovim in vim-go you're always welcome!
Run `:GoRun` in a new tab, horizontal split or vertical split terminal
>
au FileType go nmap <leader>rt <Plug>(go-run-tab)
au FileType go nmap <leader>rs <Plug>(go-run-split)
au FileType go nmap <leader>rv <Plug>(go-run-vertical)
<
By default new terminals are opened in a vertical split. To change it
>
let g:go_term_mode = "split"
>
==============================================================================
DONATION *go-donation*
People have asked for this for a long time, now you can be a fully supporter
by being a patreon at: https://www.patreon.com/fatih
By being a patron, you are enabling vim-go to grow and mature, helping me to
invest in bug fixes, new documentation, and improving both current and future
features. It's completely optional and is just a direct way to support Vim-go's
ongoing development. Thanks!
Check it out: https://www.patreon.com/fatih
==============================================================================
CREDITS *go-credits*