mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
# vim-go
|
||||
|
||||
Go (golang) support for Vim. It comes with pre-defined sensible settings (like
|
||||
auto gofmt on save), has autocomplete, snippet support, improved syntax
|
||||
highlighting, go toolchain commands, etc... If needed vim-go installs all
|
||||
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.
|
||||
@ -11,40 +11,44 @@ disabled/enabled easily.
|
||||
|
||||
## Features
|
||||
|
||||
* Improved Syntax highlighting, such as Functions, Operators, Methods..
|
||||
* Improved Syntax highlighting with items such as Functions, Operators, Methods.
|
||||
* Auto completion support via `gocode`
|
||||
* Better `gofmt` on save, keeps cursor position and doesn't break your undo
|
||||
* 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.
|
||||
* 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`
|
||||
* `:GoRun` quickly your current file/files
|
||||
* Run `:GoTest` and see any errors in quickfix window
|
||||
* Automatic `GOPATH` detection based on the directory structure (i.e: `godep`
|
||||
vendored projects)
|
||||
* Compile your package with `:GoBuild`, install it with `:GoInstall` or test
|
||||
them with `:GoTest` (also supports running single tests via `:GoTestFunc`)
|
||||
* 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 in browser 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 tool with oracle, such as `:GoImplements`,
|
||||
`:GoCallees`, `:GoReferrers`
|
||||
* Run your code through `:GoVet` to catch static errors
|
||||
* Advanced source analysis tools utilizing oracle, such as `:GoImplements`,
|
||||
`:GoCallees`, and `:GoReferrers`
|
||||
* Precise type-safe renaming of identifiers with `:GoRename`
|
||||
* List all source files and dependencies
|
||||
* Checking with `:GoErrCheck` for unchecked errors.
|
||||
* Integrated and improved snippets. Supports `ultisnips` or `neosnippet`
|
||||
* 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.
|
||||
* Tagbar support to show tags of the source code in a sidebar with `gotags`
|
||||
* Custom vim text objects, such a `a function` or `inner function`
|
||||
* Custom vim text objects such as `a function` or `inner function`
|
||||
* All commands support collecting and displaying errors in Vim's location
|
||||
list.
|
||||
|
||||
## Install
|
||||
|
||||
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 plugins. For Pathogen just clone the repo, for other plugin managers
|
||||
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.
|
||||
|
||||
* [Pathogen](https://github.com/tpope/vim-pathogen)
|
||||
@ -57,21 +61,21 @@ add the appropriate lines and execute the plugin's install command.
|
||||
* `Plugin 'fatih/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 you invoke it, all necessary binaries will be
|
||||
`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`). It requires `git` for fetching the individual Go
|
||||
packages.
|
||||
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.
|
||||
|
||||
### Optional
|
||||
|
||||
* Autocompletion is enabled by default via `<C-x><C-o>`, to get real-time
|
||||
* Autocompletion is enabled by default via `<C-x><C-o>`. To get real-time
|
||||
completion (completion by type) install:
|
||||
[YCM](https://github.com/Valloric/YouCompleteMe) or
|
||||
[neocomplete](https://github.com/Shougo/neocomplete.vim).
|
||||
* To get displayed source code tag informations on a sidebar install
|
||||
* To display source code tag information on a sidebar install
|
||||
[tagbar](https://github.com/majutsushi/tagbar).
|
||||
* For snippet feature install:
|
||||
* For snippet features install:
|
||||
[ultisnips](https://github.com/SirVer/ultisnips) or
|
||||
[neosnippet](https://github.com/Shougo/neosnippet.vim).
|
||||
* Screenshot color scheme is a slightly modified molokai: [fatih/molokai](https://github.com/fatih/molokai).
|
||||
@ -79,7 +83,7 @@ completion (completion by type) install:
|
||||
|
||||
## Usage
|
||||
|
||||
Many of the [features](#features) are enabled by default. There are no
|
||||
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).
|
||||
@ -92,9 +96,9 @@ After that just open the help page to see all commands:
|
||||
vim-go has several `<Plug>` mappings which can be used to create custom
|
||||
mappings. Below are some examples you might find useful:
|
||||
|
||||
Run commands, such as `go run` with `<leader>r` for the current file or `go
|
||||
build` and `go test` for the current package with `<leader>b` and `<leader>t`.
|
||||
Display a beautiful annotated source code to see which functions are covered
|
||||
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
|
||||
@ -104,9 +108,9 @@ 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:
|
||||
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)
|
||||
@ -152,6 +156,19 @@ 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`.
|
||||
|
||||
### Location list navigation
|
||||
|
||||
All commands support collecting and displaying errors in Vim's location
|
||||
list.
|
||||
|
||||
Quickly navigate through these location lists with `:lne` for next error and `:lp`
|
||||
for previous. You can also bind these to keys, for example:
|
||||
|
||||
```vim
|
||||
map <C-n> :lne<CR>
|
||||
map <C-m> :lp<CR>
|
||||
```
|
||||
|
||||
## Settings
|
||||
Below are some settings you might find useful. For the full list see `:he go-settings`.
|
||||
|
||||
@ -183,7 +200,7 @@ Disable auto fmt on save:
|
||||
let g:go_fmt_autosave = 0
|
||||
```
|
||||
|
||||
Disable opening browser after posting to your snippet to `play.golang.org`:
|
||||
Disable opening browser after posting your snippet to `play.golang.org`:
|
||||
|
||||
```vim
|
||||
let g:go_play_open_browser = 0
|
||||
@ -197,23 +214,19 @@ let g:go_bin_path = expand("~/.gotools")
|
||||
let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path
|
||||
```
|
||||
|
||||
## 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'] }
|
||||
```
|
||||
|
||||
## More info
|
||||
|
||||
Check out the Wiki page for more information. It includes Screencasts, FAQ
|
||||
section and many various piece of information:
|
||||
|
||||
[https://github.com/fatih/vim-go/wiki](https://github.com/fatih/vim-go/wiki)
|
||||
|
||||
|
||||
## Donations
|
||||
|
||||
Vim-go is an open source project and I'm working on it on my free times. I'm
|
||||
spending a lot of time and thoughts to make it stable, fixing bugs, adding new
|
||||
features, etc... If you like vim-go and find it helpful, you might give me a
|
||||
gift from some of the books (kindle) I have in my wish list:
|
||||
|
||||
[Amazon.com Fatih's Wish List](http://amzn.com/w/3RUTKZC0U30P6). Thanks!
|
||||
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.
|
||||
|
||||
## Credits
|
||||
|
||||
|
@ -8,41 +8,50 @@ function! go#cmd#autowrite()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" Build buils the source code without producting any output binary. We live in
|
||||
" an editor so the best is to build it to catch errors and fix them. By
|
||||
" default it tries to call simply 'go build', but it first tries to get all
|
||||
" dependent files for the current folder and passes it to go build.
|
||||
function! go#cmd#Build(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let l:tmpname = tempname()
|
||||
|
||||
if v:shell_error
|
||||
let &makeprg = "go build . errors"
|
||||
else
|
||||
let &makeprg = "go build -o /dev/null " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
" :make expands '%' and '#' wildcards, so they must also be escaped
|
||||
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
|
||||
let gofiles = go#util#Shelljoin(go#tool#Files(), 1)
|
||||
let &makeprg = "go build -o " . l:tmpname . ' ' . goargs . ' ' . gofiles
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "building ..."| echohl None
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
silent! exe 'lmake!'
|
||||
endif
|
||||
redraw!
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
|
||||
let errors = go#list#Get()
|
||||
call go#list#Window(len(errors))
|
||||
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None
|
||||
endif
|
||||
|
||||
|
||||
call delete(l:tmpname)
|
||||
let &makeprg = default_makeprg
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
@ -52,13 +61,11 @@ endfunction
|
||||
" suitable for long running apps, because vim is blocking by default and
|
||||
" calling long running apps will block the whole UI.
|
||||
function! go#cmd#Run(bang, ...)
|
||||
let goFiles = '"' . join(go#tool#Files(), '" "') . '"'
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
if go#util#IsWin()
|
||||
exec '!go run ' . goFiles
|
||||
exec '!go run ' . go#util#Shelljoin(go#tool#Files())
|
||||
if v:shell_error
|
||||
redraws! | echon "vim-go: [run] " | echohl ErrorMsg | echon "FAILED"| echohl None
|
||||
else
|
||||
@ -69,23 +76,46 @@ function! go#cmd#Run(bang, ...)
|
||||
return
|
||||
endif
|
||||
|
||||
" :make expands '%' and '#' wildcards, so they must also be escaped
|
||||
let default_makeprg = &makeprg
|
||||
if !len(a:000)
|
||||
let &makeprg = 'go run ' . goFiles
|
||||
if a:0 == 0
|
||||
let &makeprg = 'go run ' . go#util#Shelljoin(go#tool#Files(), 1)
|
||||
else
|
||||
let &makeprg = "go run " . expand(a:1)
|
||||
let &makeprg = "go run " . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
|
||||
endif
|
||||
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make!'
|
||||
silent! exe 'Make'
|
||||
else
|
||||
exe 'make!'
|
||||
exe 'lmake!'
|
||||
endif
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
" Remove any nonvalid filename from the location list to avoid opening an
|
||||
" empty buffer. See https://github.com/fatih/vim-go/issues/287 for
|
||||
" details.
|
||||
let items = go#list#Get()
|
||||
let errors = []
|
||||
let is_readable = {}
|
||||
|
||||
for item in items
|
||||
let filename = bufname(item.bufnr)
|
||||
if !has_key(is_readable, filename)
|
||||
let is_readable[filename] = filereadable(filename)
|
||||
endif
|
||||
if is_readable[filename]
|
||||
call add(errors, item)
|
||||
endif
|
||||
endfor
|
||||
|
||||
for k in keys(filter(is_readable, '!v:val'))
|
||||
echo "vim-go: " | echohl Identifier | echon "[run] Dropped " | echohl Constant | echon '"' . k . '"'
|
||||
echohl Identifier | echon " from location list (nonvalid filename)" | echohl None
|
||||
endfor
|
||||
|
||||
call go#list#Populate(errors)
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
@ -93,21 +123,23 @@ function! go#cmd#Run(bang, ...)
|
||||
endfunction
|
||||
|
||||
" Install installs the package by simple calling 'go install'. If any argument
|
||||
" is given(which are passed directly to 'go insta'') it tries to install those
|
||||
" packages. Errors are populated in the quickfix window.
|
||||
" is given(which are passed directly to 'go instal') it tries to install those
|
||||
" packages. Errors are populated in the location window.
|
||||
function! go#cmd#Install(bang, ...)
|
||||
let pkgs = join(a:000, '" "')
|
||||
let command = 'go install "' . pkgs . '"'
|
||||
let command = 'go install ' . go#util#Shelljoin(a:000)
|
||||
call go#cmd#autowrite()
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(errors)
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
return
|
||||
else
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
|
||||
@ -122,15 +154,15 @@ function! go#cmd#Test(bang, compile, ...)
|
||||
" don't run the test, only compile it. Useful to capture and fix errors or
|
||||
" to create a test binary.
|
||||
if a:compile
|
||||
let command .= "-c"
|
||||
let command .= "-c "
|
||||
endif
|
||||
|
||||
if len(a:000)
|
||||
let command .= expand(a:1)
|
||||
endif
|
||||
|
||||
if len(a:000) == 2
|
||||
let command .= a:2
|
||||
if a:0
|
||||
let command .= go#util#Shelljoin(map(copy(a:000), "expand(v:val)"))
|
||||
else
|
||||
" only add this if no custom flags are passed
|
||||
let timeout = get(g:, 'go_test_timeout', '10s')
|
||||
let command .= "-timeout=" . timeout . " "
|
||||
endif
|
||||
|
||||
call go#cmd#autowrite()
|
||||
@ -143,16 +175,16 @@ function! go#cmd#Test(bang, compile, ...)
|
||||
redraw
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(errors)
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None
|
||||
else
|
||||
call setqflist([])
|
||||
cwindow
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None
|
||||
@ -182,17 +214,13 @@ function! go#cmd#TestFunc(bang, ...)
|
||||
|
||||
let line = getline(test)
|
||||
let name = split(split(line, " ")[1], "(")[0]
|
||||
let flag = "-run \"" . name . "$\""
|
||||
let args = [a:bang, 0, "-run", name . "$"]
|
||||
|
||||
let a1 = ""
|
||||
if len(a:000)
|
||||
let a1 = a:1
|
||||
|
||||
" add extra space
|
||||
let flag = " " . flag
|
||||
if a:0
|
||||
call extend(args, a:000)
|
||||
endif
|
||||
|
||||
call go#cmd#Test(a:bang, 0, a1, flag)
|
||||
call call('go#cmd#Test', args)
|
||||
endfunction
|
||||
|
||||
" Coverage creates a new cover profile with 'go test -coverprofile' and opens
|
||||
@ -200,76 +228,58 @@ endfunction
|
||||
function! go#cmd#Coverage(bang, ...)
|
||||
let l:tmpname=tempname()
|
||||
|
||||
let command = "go test -coverprofile=".l:tmpname
|
||||
let command = "go test -coverprofile=" . l:tmpname . ' ' . go#util#Shelljoin(a:000)
|
||||
|
||||
call go#cmd#autowrite()
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(errors)
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
else
|
||||
" clear previous quick fix window
|
||||
call setqflist([])
|
||||
" clear previous location list
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
|
||||
let openHTML = 'go tool cover -html='.l:tmpname
|
||||
call go#tool#ExecuteInDir(openHTML)
|
||||
endif
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
|
||||
call delete(l:tmpname)
|
||||
endfunction
|
||||
|
||||
" Vet calls "go vet' on the current directory. Any warnings are populated in
|
||||
" the quickfix window
|
||||
function! go#cmd#Vet(bang)
|
||||
call go#cmd#autowrite()
|
||||
echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None
|
||||
let out = go#tool#ExecuteInDir('go vet')
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
else
|
||||
call setqflist([])
|
||||
endif
|
||||
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
"
|
||||
" Generate runs 'go generate' in similar fashion to go#cmd#Build()
|
||||
function! go#cmd#Generate(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
" :make expands '%' and '#' wildcards, so they must also be escaped
|
||||
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
|
||||
if v:shell_error
|
||||
let &makeprg = "go generate " . join(a:000, ' ')
|
||||
let &makeprg = "go generate " . goargs
|
||||
else
|
||||
let &makeprg = "go generate " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
let gofiles = go#util#Shelljoin(go#tool#Files(), 1)
|
||||
let &makeprg = "go generate " . goargs . ' ' . gofiles
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
silent! exe 'lmake!'
|
||||
endif
|
||||
redraw!
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
let errors = go#list#Get()
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None
|
||||
@ -280,4 +290,3 @@ function! go#cmd#Generate(bang, ...)
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
"
|
||||
|
@ -19,13 +19,21 @@ fu! s:gocodeCurrentBuffer()
|
||||
return file
|
||||
endf
|
||||
|
||||
|
||||
if go#vimproc#has_vimproc()
|
||||
let s:vim_system = get(g:, 'gocomplete#system_function', 'vimproc#system2')
|
||||
let s:vim_shell_error = get(g:, 'gocomplete#shell_error_function', 'vimproc#get_last_status')
|
||||
else
|
||||
let s:vim_system = get(g:, 'gocomplete#system_function', 'system')
|
||||
let s:vim_shell_error = ''
|
||||
endif
|
||||
|
||||
fu! s:shell_error()
|
||||
if empty(s:vim_shell_error)
|
||||
return v:shell_error
|
||||
endif
|
||||
return call(s:vim_shell_error, [])
|
||||
endf
|
||||
|
||||
fu! s:system(str, ...)
|
||||
return call(s:vim_system, [a:str] + a:000)
|
||||
endf
|
||||
@ -65,7 +73,7 @@ fu! s:gocodeCommand(cmd, preargs, args)
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
|
||||
if v:shell_error != 0
|
||||
if s:shell_error() != 0
|
||||
return "[\"0\", []]"
|
||||
else
|
||||
if &encoding != 'utf-8'
|
||||
|
@ -1,54 +0,0 @@
|
||||
if !exists("g:go_errcheck_bin")
|
||||
let g:go_errcheck_bin = "errcheck"
|
||||
endif
|
||||
|
||||
function! go#errcheck#Run(...) abort
|
||||
if a:0 == 0
|
||||
let package = go#package#ImportPath(expand('%:p:h'))
|
||||
if package == -1
|
||||
echohl Error | echomsg "vim-go: package is not inside GOPATH src" | echohl None
|
||||
return
|
||||
endif
|
||||
else
|
||||
let package = a:1
|
||||
end
|
||||
|
||||
let bin_path = go#path#CheckBinPath(g:go_errcheck_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "errcheck analysing ..." | echohl None
|
||||
let out = system(bin_path . ' ' . package)
|
||||
if v:shell_error
|
||||
let errors = []
|
||||
let mx = '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)'
|
||||
for line in split(out, '\n')
|
||||
let tokens = matchlist(line, mx)
|
||||
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": expand(go#path#Default() . "/src/" . tokens[1]),
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4]})
|
||||
endif
|
||||
endfor
|
||||
|
||||
if empty(errors)
|
||||
echohl Error | echomsg "GoErrCheck returned error" | echohl None
|
||||
echo out
|
||||
endif
|
||||
|
||||
if !empty(errors)
|
||||
redraw | echo
|
||||
call setqflist(errors, 'r')
|
||||
endif
|
||||
else
|
||||
redraw | echo
|
||||
call setqflist([])
|
||||
endif
|
||||
|
||||
cwindow
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
@ -43,8 +43,6 @@ if !exists("g:go_fmt_experimental")
|
||||
let g:go_fmt_experimental = 0
|
||||
endif
|
||||
|
||||
let s:got_fmt_error = 0
|
||||
|
||||
" we have those problems :
|
||||
" http://stackoverflow.com/questions/12741977/prevent-vim-from-updating-its-undo-tree
|
||||
" http://stackoverflow.com/questions/18532692/golang-formatter-and-vim-how-to-destroy-history-record?rq=1
|
||||
@ -57,10 +55,9 @@ function! go#fmt#Format(withGoimport)
|
||||
" save cursor position and many other things
|
||||
let l:curw=winsaveview()
|
||||
|
||||
" needed for testing if gofmt fails or not
|
||||
let l:tmpname=tempname()
|
||||
call writefile(getline(1,'$'), l:tmpname)
|
||||
|
||||
" Write current unsaved buffer to a temp file
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" save our undo file to be restored after we are done. This is needed to
|
||||
@ -77,16 +74,15 @@ function! go#fmt#Format(withGoimport)
|
||||
let fmt_command = g:go_goimports_bin
|
||||
endif
|
||||
|
||||
" if it's something else than gofmt, we need to check the existing of that
|
||||
" binary. For example if it's goimports, let us check if it's installed,
|
||||
" check if the user has installed command binary.
|
||||
" For example if it's goimports, let us check if it's installed,
|
||||
" if not the user get's a warning via go#path#CheckBinPath()
|
||||
if fmt_command != "gofmt"
|
||||
" check if the user has installed goimports
|
||||
let bin_path = go#path#CheckBinPath(fmt_command)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
let bin_path = go#path#CheckBinPath(fmt_command)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if fmt_command != "gofmt"
|
||||
" change GOPATH too, so goimports can pick up the correct library
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
@ -95,17 +91,18 @@ function! go#fmt#Format(withGoimport)
|
||||
endif
|
||||
|
||||
" populate the final command with user based fmt options
|
||||
let command = fmt_command . ' ' . g:go_fmt_options
|
||||
let command = fmt_command . ' -w '
|
||||
if a:withGoimport != 1
|
||||
let command = command . g:go_fmt_options
|
||||
endif
|
||||
|
||||
" execute our command...
|
||||
let out = system(command . " " . l:tmpname)
|
||||
let splitted = split(out, '\n')
|
||||
|
||||
if fmt_command != "gofmt"
|
||||
let $GOPATH = old_gopath
|
||||
endif
|
||||
|
||||
|
||||
"if there is no error on the temp file replace the output with the current
|
||||
"file (if this fails, we can always check the outputs first line with:
|
||||
"splitted =~ 'package \w\+')
|
||||
@ -113,34 +110,19 @@ function! go#fmt#Format(withGoimport)
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
" do not include stderr to the buffer, this is due to goimports/gofmt
|
||||
" tha fails with a zero exit return value (sad yeah).
|
||||
let default_srr = &srr
|
||||
set srr=>%s
|
||||
" Replace current file with temp file, then reload buffer
|
||||
let old_fileformat = &fileformat
|
||||
call rename(l:tmpname, expand('%'))
|
||||
silent edit!
|
||||
let &fileformat = old_fileformat
|
||||
let &syntax = &syntax
|
||||
|
||||
" delete any leftover before we replace the whole file. Suppose the
|
||||
" file had 20 lines, but new output has 10 lines, only 1-10 are
|
||||
" replaced with setline, remaining lines 11-20 won't get touched. So
|
||||
" remove them.
|
||||
if line('$') > len(splitted)
|
||||
execute len(splitted) .',$delete'
|
||||
endif
|
||||
|
||||
" setline iterates over the list and replaces each line
|
||||
call setline(1, splitted)
|
||||
|
||||
" only clear quickfix if it was previously set, this prevents closing
|
||||
" other quickfixes
|
||||
if s:got_fmt_error
|
||||
let s:got_fmt_error = 0
|
||||
call setqflist([])
|
||||
cwindow
|
||||
endif
|
||||
|
||||
" put back the users srr setting
|
||||
let &srr = default_srr
|
||||
" clean up previous location list
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
elseif g:go_fmt_fail_silently == 0
|
||||
"otherwise get the errors and put them to quickfix window
|
||||
let splitted = split(out, '\n')
|
||||
"otherwise get the errors and put them to location list
|
||||
let errors = []
|
||||
for line in splitted
|
||||
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
|
||||
@ -155,11 +137,14 @@ function! go#fmt#Format(withGoimport)
|
||||
% | " Couldn't detect gofmt error format, output errors
|
||||
endif
|
||||
if !empty(errors)
|
||||
call setqflist(errors, 'r')
|
||||
call go#list#Populate(errors)
|
||||
echohl Error | echomsg "Gofmt returned error" | echohl None
|
||||
endif
|
||||
let s:got_fmt_error = 1
|
||||
cwindow
|
||||
|
||||
call go#list#Window(len(errors))
|
||||
|
||||
" We didn't use the temp file, so clean up
|
||||
call delete(l:tmpname)
|
||||
endif
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
@ -169,7 +154,6 @@ function! go#fmt#Format(withGoimport)
|
||||
endif
|
||||
|
||||
" restore our cursor/windows positions
|
||||
call delete(l:tmpname)
|
||||
call winrestview(l:curw)
|
||||
endfunction
|
||||
|
||||
|
@ -2,46 +2,11 @@
|
||||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" import.vim: Vim commands to import/drop Go packages.
|
||||
" Check out the docs for more information at /doc/vim-go.txt
|
||||
"
|
||||
" This filetype plugin adds three new commands for go buffers:
|
||||
"
|
||||
" :GoImport {path}
|
||||
"
|
||||
" Import ensures that the provided package {path} is imported
|
||||
" in the current Go buffer, using proper style and ordering.
|
||||
" If {path} is already being imported, an error will be
|
||||
" displayed and the buffer will be untouched.
|
||||
"
|
||||
" :GoImportAs {localname} {path}
|
||||
"
|
||||
" Same as Import, but uses a custom local name for the package.
|
||||
"
|
||||
" :GoDrop {path}
|
||||
"
|
||||
" Remove the import line for the provided package {path}, if
|
||||
" present in the current Go buffer. If {path} is not being
|
||||
" imported, an error will be displayed and the buffer will be
|
||||
" untouched.
|
||||
"
|
||||
" If you would like to add shortcuts, you can do so by doing the following:
|
||||
"
|
||||
" Import fmt
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>f :Import fmt<CR>
|
||||
"
|
||||
" Drop fmt
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>F :Drop fmt<CR>
|
||||
"
|
||||
" Import the word under your cursor
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>k
|
||||
" \ :exe 'Import ' . expand('<cword>')<CR>
|
||||
"
|
||||
" The backslash '\' is the default maplocalleader, so it is possible that
|
||||
" your vim is set to use a different character (:help maplocalleader).
|
||||
"
|
||||
function! go#import#SwitchImport(enabled, localname, path)
|
||||
function! go#import#SwitchImport(enabled, localname, path, bang)
|
||||
let view = winsaveview()
|
||||
let path = a:path
|
||||
let path = substitute(a:path, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
" Quotes are not necessary, so remove them if provided.
|
||||
if path[0] == '"'
|
||||
@ -61,6 +26,12 @@ function! go#import#SwitchImport(enabled, localname, path)
|
||||
return
|
||||
endif
|
||||
|
||||
if a:bang == "!"
|
||||
let out = system("go get -u -v ".shellescape(path))
|
||||
if v:shell_error
|
||||
call s:Error("Can't find import: " . path . ":" . out)
|
||||
endif
|
||||
endif
|
||||
let exists = go#tool#Exists(path)
|
||||
if exists == -1
|
||||
call s:Error("Can't find import: " . path)
|
||||
|
@ -1,30 +1,199 @@
|
||||
" Copyright 2013 The Go Authors. All rights reserved.
|
||||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" lint.vim: Vim command to lint Go files with golint.
|
||||
"
|
||||
" https://github.com/golang/lint
|
||||
"
|
||||
" This filetype plugin add a new commands for go buffers:
|
||||
"
|
||||
" :GoLint
|
||||
"
|
||||
" Run golint for the current Go file.
|
||||
"
|
||||
if !exists("g:go_metalinter_command")
|
||||
let g:go_metalinter_command = ""
|
||||
endif
|
||||
|
||||
if !exists("g:go_metalinter_autosave_enabled")
|
||||
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
|
||||
endif
|
||||
|
||||
if !exists("g:go_metalinter_enabled")
|
||||
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
|
||||
endif
|
||||
|
||||
if !exists("g:go_metalinter_deadline")
|
||||
let g:go_metalinter_deadline = "5s"
|
||||
endif
|
||||
|
||||
if !exists("g:go_golint_bin")
|
||||
let g:go_golint_bin = "golint"
|
||||
endif
|
||||
|
||||
function! go#lint#Run() abort
|
||||
if !exists("g:go_errcheck_bin")
|
||||
let g:go_errcheck_bin = "errcheck"
|
||||
endif
|
||||
|
||||
function! go#lint#Gometa(autosave, ...) abort
|
||||
if a:0 == 0
|
||||
let goargs = expand('%:p:h')
|
||||
else
|
||||
let goargs = go#util#Shelljoin(a:000)
|
||||
endif
|
||||
|
||||
let meta_command = "gometalinter --disable-all"
|
||||
if a:autosave || empty(g:go_metalinter_command)
|
||||
let bin_path = go#path#CheckBinPath("gometalinter")
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if a:autosave
|
||||
" include only messages for the active buffer
|
||||
let meta_command .= " --include='^" . expand('%:p') . ".*$'"
|
||||
endif
|
||||
|
||||
" linters
|
||||
let linters = a:autosave ? g:go_metalinter_autosave_enabled : g:go_metalinter_enabled
|
||||
for linter in linters
|
||||
let meta_command .= " --enable=".linter
|
||||
endfor
|
||||
|
||||
" deadline
|
||||
let meta_command .= " --deadline=" . g:go_metalinter_deadline
|
||||
|
||||
" path
|
||||
let meta_command .= " " . goargs
|
||||
else
|
||||
" the user wants something else, let us use it.
|
||||
let meta_command = g:go_metalinter_command
|
||||
endif
|
||||
|
||||
" comment out the following two lines for debugging
|
||||
" echo meta_command
|
||||
" return
|
||||
|
||||
let out = go#tool#ExecuteInDir(meta_command)
|
||||
|
||||
if v:shell_error == 0
|
||||
redraw | echo
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None
|
||||
else
|
||||
" GoMetaLinter can output one of the two, so we look for both:
|
||||
" <file>:<line>:[<column>]: <message> (<linter>)
|
||||
" <file>:<line>:: <message> (<linter>)
|
||||
" This can be defined by the following errorformat:
|
||||
let errformat = "%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m"
|
||||
|
||||
" Parse and populate our location list
|
||||
call go#list#ParseFormat(errformat, split(out, "\n"))
|
||||
|
||||
let errors = go#list#Get()
|
||||
call go#list#Window(len(errors))
|
||||
|
||||
if !a:autosave
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
endif
|
||||
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
|
||||
endif
|
||||
|
||||
silent cexpr system(bin_path . " " . shellescape(expand('%')))
|
||||
cwindow
|
||||
if a:0 == 0
|
||||
let goargs = shellescape(expand('%'))
|
||||
else
|
||||
let goargs = go#util#Shelljoin(a:000)
|
||||
endif
|
||||
|
||||
let out = system(bin_path . " " . goargs)
|
||||
if empty(out)
|
||||
echon "vim-go: " | echohl Function | echon "[lint] PASS" | echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
call go#list#Parse(out)
|
||||
let errors = go#list#Get()
|
||||
call go#list#Window(len(errors))
|
||||
call go#list#JumpToFirst()
|
||||
endfunction
|
||||
|
||||
" Vet calls 'go vet' on the current directory. Any warnings are populated in
|
||||
" the location list
|
||||
function! go#lint#Vet(bang, ...)
|
||||
call go#cmd#autowrite()
|
||||
echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None
|
||||
if a:0 == 0
|
||||
let out = go#tool#ExecuteInDir('go vet')
|
||||
else
|
||||
let out = go#tool#ExecuteInDir('go tool vet ' . go#util#Shelljoin(a:000))
|
||||
endif
|
||||
if v:shell_error
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(errors)
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
echon "vim-go: " | echohl ErrorMsg | echon "[vet] FAIL" | echohl None
|
||||
else
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in
|
||||
" the location list
|
||||
function! go#lint#Errcheck(...) abort
|
||||
if a:0 == 0
|
||||
let goargs = go#package#ImportPath(expand('%:p:h'))
|
||||
if goargs == -1
|
||||
echohl Error | echomsg "vim-go: package is not inside GOPATH src" | echohl None
|
||||
return
|
||||
endif
|
||||
else
|
||||
let goargs = go#util#Shelljoin(a:000)
|
||||
endif
|
||||
|
||||
let bin_path = go#path#CheckBinPath(g:go_errcheck_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "errcheck analysing ..." | echohl None
|
||||
redraw
|
||||
|
||||
let command = bin_path . ' ' . goargs
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
|
||||
if v:shell_error
|
||||
let errors = []
|
||||
let mx = '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)'
|
||||
for line in split(out, '\n')
|
||||
let tokens = matchlist(line, mx)
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": expand(go#path#Default() . "/src/" . tokens[1]),
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4]})
|
||||
endif
|
||||
endfor
|
||||
|
||||
if empty(errors)
|
||||
echohl Error | echomsg "GoErrCheck returned error" | echohl None
|
||||
echo out
|
||||
return
|
||||
endif
|
||||
|
||||
if !empty(errors)
|
||||
call go#list#Populate(errors)
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors)
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
endif
|
||||
else
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
67
sources_non_forked/vim-go/autoload/go/list.vim
Normal file
67
sources_non_forked/vim-go/autoload/go/list.vim
Normal file
@ -0,0 +1,67 @@
|
||||
" Window opens the location list with the given height up to 10 lines maximum.
|
||||
" Otherwise g:go_loclist_height is used. If no or zero height is given it
|
||||
" closes the window
|
||||
function! go#list#Window(...)
|
||||
" we don't use lwindow to close the location list as we need also the
|
||||
" ability to resize the window. So, we are going to use lopen and cclose
|
||||
" for a better user experience. If the number of errors in a current
|
||||
" location list increases/decreases, cwindow will not resize when a new
|
||||
" updated height is passed. lopen in the other hand resizes the screen.
|
||||
if !a:0 || a:1 == 0
|
||||
lclose
|
||||
return
|
||||
endif
|
||||
|
||||
let height = get(g:, "go_loclist_height", 0)
|
||||
if height == 0
|
||||
" prevent creating a large location height for a large set of numbers
|
||||
if a:1 > 10
|
||||
let height = 10
|
||||
else
|
||||
let height = a:1
|
||||
endif
|
||||
endif
|
||||
|
||||
exe 'lopen '. height
|
||||
endfunction
|
||||
|
||||
|
||||
" Get returns the current list of items from the location list
|
||||
function! go#list#Get()
|
||||
return getloclist(0)
|
||||
endfunction
|
||||
|
||||
" Populate populate the location list with the given items
|
||||
function! go#list#Populate(items)
|
||||
call setloclist(0, a:items, 'r')
|
||||
endfunction
|
||||
|
||||
" Parse parses the given items based on the specified errorformat nad
|
||||
" populates the location list.
|
||||
function! go#list#ParseFormat(errformat, items)
|
||||
" backup users errorformat, will be restored once we are finished
|
||||
let old_errorformat = &errorformat
|
||||
|
||||
" parse and populate the location list
|
||||
let &errorformat = a:errformat
|
||||
lgetexpr a:items
|
||||
|
||||
"restore back
|
||||
let &errorformat = old_errorformat
|
||||
endfunction
|
||||
|
||||
" Parse parses the given items based on the global errorformat nad
|
||||
" populates the location list.
|
||||
function! go#list#Parse(items)
|
||||
lgetexpr a:items
|
||||
endfunction
|
||||
|
||||
" JumpToFirst jumps to the first item in the location list
|
||||
function! go#list#JumpToFirst()
|
||||
ll 1
|
||||
endfunction
|
||||
|
||||
" Clean cleans the location list
|
||||
function! go#list#Clean()
|
||||
lex []
|
||||
endfunction
|
@ -10,9 +10,9 @@ if !exists("g:go_oracle_bin")
|
||||
endif
|
||||
|
||||
" Parses (via regex) Oracle's 'plain' format output and puts them into a
|
||||
" quickfix list.
|
||||
func! s:qflist(output)
|
||||
let qflist = []
|
||||
" location list
|
||||
func! s:loclist(output)
|
||||
let llist = []
|
||||
" Parse GNU-style 'file:line.col-line.col: message' format.
|
||||
let mx = '^\(\a:[\\/][^:]\+\|[^:]\+\):\(\d\+\):\(\d\+\):\(.*\)$'
|
||||
for line in split(a:output, "\n")
|
||||
@ -33,17 +33,17 @@ func! s:qflist(output)
|
||||
if bnr != -1
|
||||
let item['bufnr'] = bnr
|
||||
endif
|
||||
call add(qflist, item)
|
||||
call add(llist, item)
|
||||
endfor
|
||||
call setqflist(qflist)
|
||||
cwindow
|
||||
call go#list#Populate(llist)
|
||||
call go#list#Window(len(llist))
|
||||
endfun
|
||||
|
||||
" This uses Vim's errorformat to parse the output from Oracle's 'plain output
|
||||
" and put it into quickfix list. I believe using errorformat is much more
|
||||
" and put it into location list. I believe using errorformat is much more
|
||||
" easier to use. If we need more power we can always switch back to parse it
|
||||
" via regex.
|
||||
func! s:qflistSecond(output)
|
||||
func! s:loclistSecond(output)
|
||||
" backup users errorformat, will be restored once we are finished
|
||||
let old_errorformat = &errorformat
|
||||
|
||||
@ -53,15 +53,13 @@ func! s:qflistSecond(output)
|
||||
" 'file:line:col: message'
|
||||
"
|
||||
" We discard line2 and col2 for the first errorformat, because it's not
|
||||
" useful and quickfix only has the ability to show one line and column
|
||||
" useful and location only has the ability to show one line and column
|
||||
" number
|
||||
let &errorformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
let errformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
call go#list#ParseFormat(errformat, split(a:output, "\n"))
|
||||
|
||||
" create the quickfix list and open it
|
||||
cgetexpr split(a:output, "\n")
|
||||
cwindow
|
||||
|
||||
let &errorformat = old_errorformat
|
||||
let errors = go#list#Get()
|
||||
call go#list#Window(len(errors))
|
||||
endfun
|
||||
|
||||
func! s:getpos(l, c)
|
||||
@ -73,7 +71,7 @@ func! s:getpos(l, c)
|
||||
return line2byte(a:l) + (a:c-2)
|
||||
endfun
|
||||
|
||||
func! s:RunOracle(mode, selected) range abort
|
||||
func! s:RunOracle(mode, selected, needs_package) range abort
|
||||
let fname = expand('%:p')
|
||||
let dname = expand('%:p:h')
|
||||
let pkg = go#package#ImportPath(dname)
|
||||
@ -81,14 +79,10 @@ func! s:RunOracle(mode, selected) range abort
|
||||
if exists('g:go_oracle_scope')
|
||||
" let the user defines the scope, must be a space separated string,
|
||||
" example: 'fmt math net/http'
|
||||
let unescaped_scopes = split(get(g:, 'go_oracle_scope'))
|
||||
let scopes = []
|
||||
for unescaped_scope in unescaped_scopes
|
||||
call add(scopes, shellescape(unescaped_scope))
|
||||
endfor
|
||||
elseif exists('g:go_oracle_include_tests') && pkg != -1
|
||||
let scopes = split(get(g:, 'go_oracle_scope'))
|
||||
elseif a:needs_package || exists('g:go_oracle_include_tests') && pkg != -1
|
||||
" give import path so it includes all _test.go files too
|
||||
let scopes = [shellescape(pkg)]
|
||||
let scopes = [pkg]
|
||||
else
|
||||
" best usable way, only pass the package itself, without the test
|
||||
" files
|
||||
@ -100,27 +94,31 @@ func! s:RunOracle(mode, selected) 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
|
||||
for scope in scopes
|
||||
let cmd .= ' ' . scope
|
||||
endfor
|
||||
let cmd .= ' ' . go#util#Shelljoin(scopes)
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "analysing ..." | echohl None
|
||||
|
||||
@ -143,9 +141,9 @@ func! s:RunOracle(mode, selected) range abort
|
||||
endfunc
|
||||
|
||||
function! go#oracle#Scope(...)
|
||||
if len(a:000)
|
||||
if len(a:000) == 1 && a:1 == '""'
|
||||
let g:go_oracle_scope = ""
|
||||
if a:0
|
||||
if a:0 == 1 && a:1 == '""'
|
||||
unlet g:go_oracle_scope
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is cleared"| echohl None
|
||||
else
|
||||
let g:go_oracle_scope = join(a:000, ' ')
|
||||
@ -155,59 +153,85 @@ function! go#oracle#Scope(...)
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists(g:go_oracle_scope)
|
||||
if !exists('g:go_oracle_scope')
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is not set"| echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "current oracle scope: '". g:go_oracle_scope ."'" | echohl None
|
||||
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)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('implements', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Describe selected syntax: definition, methods, etc
|
||||
function! go#oracle#Describe(selected)
|
||||
let out = s:RunOracle('describe', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('describe', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show possible targets of selected function call
|
||||
function! go#oracle#Callees(selected)
|
||||
let out = s:RunOracle('callees', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callees', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show possible callers of selected function
|
||||
function! go#oracle#Callers(selected)
|
||||
let out = s:RunOracle('callers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callers', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show path from callgraph root to selected function
|
||||
function! go#oracle#Callstack(selected)
|
||||
let out = s:RunOracle('callstack', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callstack', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show free variables of selection
|
||||
function! go#oracle#Freevars(selected)
|
||||
let out = s:RunOracle('freevars', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
" Freevars requires a selection
|
||||
if a:selected == -1
|
||||
echon "vim-go: " | echohl Statement | echon "GoFreevars requires a selection (range) of code "| echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let out = s:RunOracle('freevars', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show send/receive corresponding to selected channel op
|
||||
function! go#oracle#ChannelPeers(selected)
|
||||
let out = s:RunOracle('peers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('peers', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show all refs to entity denoted by selected identifier
|
||||
function! go#oracle#Referrers(selected)
|
||||
let out = s:RunOracle('referrers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('referrers', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
@ -66,7 +66,8 @@ function! go#package#ImportPath(arg)
|
||||
return -1
|
||||
endif
|
||||
|
||||
return substitute(path, workspace . '/src/', '', '')
|
||||
let srcdir = substitute(workspace . '/src/', '//', '/', '')
|
||||
return substitute(path, srcdir, '', '')
|
||||
endfunction
|
||||
|
||||
function! go#package#FromPath(arg)
|
||||
|
@ -65,10 +65,10 @@ function! go#path#HasPath(path)
|
||||
return hasA || hasB
|
||||
endfunction
|
||||
|
||||
" Detect returns the current GOPATH. If a package manager is used, such
|
||||
" as Godeps or something like gb (not supported yet), it will modify the
|
||||
" GOPATH so those directories take precedence over the current GOPATH. It also
|
||||
" detects diretories whose are outside GOPATH.
|
||||
" Detect returns the current GOPATH. If a package manager is used, such as
|
||||
" Godeps, GB, it will modify the GOPATH so those directories take precedence
|
||||
" over the current GOPATH. It also detects diretories whose are outside
|
||||
" GOPATH.
|
||||
function! go#path#Detect()
|
||||
let gopath = $GOPATH
|
||||
|
||||
|
@ -2,7 +2,7 @@ if !exists("g:go_gorename_bin")
|
||||
let g:go_gorename_bin = "gorename"
|
||||
endif
|
||||
|
||||
function! go#rename#Rename(...)
|
||||
function! go#rename#Rename(bang, ...)
|
||||
let to = ""
|
||||
if a:0 == 0
|
||||
let from = expand("<cword>")
|
||||
@ -13,7 +13,6 @@ function! go#rename#Rename(...)
|
||||
let to = a:1
|
||||
endif
|
||||
|
||||
|
||||
"return with a warning if the bin doesn't exist
|
||||
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
|
||||
if empty(bin_path)
|
||||
@ -31,12 +30,23 @@ function! go#rename#Rename(...)
|
||||
let clean = split(out, '\n')
|
||||
|
||||
if v:shell_error
|
||||
redraw | echon "vim-go: " | echohl Statement | echon clean[0] | echohl None
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(errors)
|
||||
call go#list#Window(len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
call go#list#JumpToFirst()
|
||||
endif
|
||||
return
|
||||
else
|
||||
call go#list#Clean()
|
||||
call go#list#Window()
|
||||
redraw | echon "vim-go: " | echohl Function | echon clean[0] | echohl None
|
||||
endif
|
||||
|
||||
" refresh the buffer so we can see the new content
|
||||
" TODO(arslan): also find all other buffers and refresh them too. For this
|
||||
" we need a way to get the list of changes from gorename upon an success
|
||||
" change.
|
||||
silent execute ":e"
|
||||
endfunction
|
||||
|
||||
|
@ -40,19 +40,10 @@ function! go#tool#Imports()
|
||||
return imports
|
||||
endfunction
|
||||
|
||||
function! go#tool#ShowErrors(out)
|
||||
" cd into the current files directory. This is important so fnamemodify
|
||||
" does create a full path for outputs when the token is only a single file
|
||||
" name (such as for a go test output, i.e.: 'demo_test.go'). For other
|
||||
" outputs, such as 'go install' we already get an absolute path (i.e.:
|
||||
" '../foo/foo.go') and fnamemodify successfuly creates the full path.
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let current_dir = getcwd()
|
||||
execute cd . fnameescape(expand("%:p:h"))
|
||||
|
||||
function! go#tool#ParseErrors(lines)
|
||||
let errors = []
|
||||
|
||||
for line in split(a:out, '\n')
|
||||
for line in a:lines
|
||||
let fatalerrors = matchlist(line, '^\(fatal error:.*\)$')
|
||||
let tokens = matchlist(line, '^\s*\(.\{-}\):\(\d\+\):\s*\(.*\)')
|
||||
|
||||
@ -71,18 +62,7 @@ function! go#tool#ShowErrors(out)
|
||||
endif
|
||||
endfor
|
||||
|
||||
" return back to old dir once we are finished with populating the errors
|
||||
execute cd . fnameescape(current_dir)
|
||||
|
||||
if !empty(errors)
|
||||
call setqflist(errors, 'r')
|
||||
return
|
||||
endif
|
||||
|
||||
if empty(errors)
|
||||
" Couldn't detect error format, output errors
|
||||
echo a:out
|
||||
endif
|
||||
return errors
|
||||
endfunction
|
||||
|
||||
function! go#tool#ExecuteInDir(cmd) abort
|
||||
|
@ -27,7 +27,7 @@ endfunction
|
||||
|
||||
" IsWin returns 1 if current OS is Windows or 0 otherwise
|
||||
function! go#util#IsWin()
|
||||
let win = ['win16', 'win32', 'win32unix', 'win64', 'win95']
|
||||
let win = ['win16', 'win32', 'win64', 'win95']
|
||||
for w in win
|
||||
if (has(w))
|
||||
return 1
|
||||
@ -48,4 +48,12 @@ function! go#util#StripPathSep(path)
|
||||
return a:path
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
" Shelljoin returns a shell-safe string representation of arglist. The
|
||||
" {special} argument of shellescape() may optionally be passed.
|
||||
function! go#util#Shelljoin(arglist, ...)
|
||||
if a:0
|
||||
return join(map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')'), ' ')
|
||||
else
|
||||
return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ')
|
||||
endif
|
||||
endfunction
|
||||
|
@ -21,14 +21,19 @@ else
|
||||
CompilerSet makeprg=go\ build
|
||||
endif
|
||||
|
||||
CompilerSet errorformat=
|
||||
\%-G#\ %.%#,
|
||||
\%-G%.%#panic:\ %m,
|
||||
\%Ecan\'t\ load\ package:\ %m,
|
||||
\%A%f:%l:%c:\ %m,
|
||||
\%A%f:%l:\ %m,
|
||||
\%C%*\\s%m,
|
||||
\%-G%.%#
|
||||
" Define the patterns that will be recognized by QuickFix when parsing the
|
||||
" output of Go command that use this errorforamt (when called make, cexpr or
|
||||
" lmake, lexpr). This is the global errorformat, however some command might
|
||||
" use a different output, for those we define them directly and modify the
|
||||
" errorformat ourselves. More information at:
|
||||
" http://vimdoc.sourceforge.net/htmldoc/quickfix.html#errorformat
|
||||
CompilerSet errorformat =%-G#\ %.%# " Ignore lines beginning with '#' ('# command-line-arguments' line sometimes appears?)
|
||||
CompilerSet errorformat+=%-G%.%#panic:\ %m " Ignore lines containing 'panic: message'
|
||||
CompilerSet errorformat+=%Ecan\'t\ load\ package:\ %m " Start of multiline error string is 'can\'t load package'
|
||||
CompilerSet errorformat+=%A%f:%l:%c:\ %m " Start of multiline unspecified string is 'filename:linenumber:columnnumber:'
|
||||
CompilerSet errorformat+=%A%f:%l:\ %m " Start of multiline unspecified string is 'filename:linenumber:'
|
||||
CompilerSet errorformat+=%C%*\\s%m " Continuation of multiline error message is indented
|
||||
CompilerSet errorformat+=%-G%.%# " All lines not matching any of the above patterns are ignored
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
@ -33,29 +33,38 @@ support, improved syntax highlighting, go toolchain commands, etc... It's
|
||||
highly customizable and each individual feature can be disabled/enabled
|
||||
easily.
|
||||
|
||||
* Improved Syntax highlighting, such as Functions, Operators, Methods..
|
||||
* Improved Syntax highlighting with items such as Functions, Operators, Methods.
|
||||
* Auto completion support via `gocode`
|
||||
* Better `gofmt` on save, keeps cursor position and doesn't break your undo
|
||||
* 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 `goimports`
|
||||
* Compile and `go build` your package, install it with `go install`
|
||||
* `go run` quickly your current file/files
|
||||
* Run `go test` and see any errors in quickfix window
|
||||
* Create a coverage profile and display annotated source code in browser to
|
||||
see which functions are covered.
|
||||
* Lint your code with `golint`
|
||||
* Run your code trough `go vet` to catch static errors.
|
||||
* Advanced source analysis tool with `oracle`
|
||||
* Precise type-safe renaming of identifiers with `gorename`
|
||||
* 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`)
|
||||
* 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 in browser 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 oracle, such as `:GoImplements`,
|
||||
`:GoCallees`, and `:GoReferrers`
|
||||
* Precise type-safe renaming of identifiers with `:GoRename`
|
||||
* List all source files and dependencies
|
||||
* Checking with `errcheck` for unchecked errors.
|
||||
* Integrated and improved snippets. Supports `ultisnips` or `neosnippet`
|
||||
* Share your current code to play.golang.org
|
||||
* On-the-fly type information about the word under the cursor
|
||||
* 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.
|
||||
* Tagbar support to show tags of the source code in a sidebar with `gotags`
|
||||
* Custom vim text objects, such a `a function` or `inner function`
|
||||
* Custom vim text objects such as `a function` or `inner function`
|
||||
* All commands support collecting and displaying errors in Vim's location
|
||||
list.
|
||||
|
||||
===============================================================================
|
||||
INSTALL *go-install*
|
||||
@ -113,18 +122,20 @@ COMMANDS *go-commands*
|
||||
*:GoPath*
|
||||
:GoPath [path]
|
||||
|
||||
GoPath sets and ovverides GOPATH with the given {path}. If no {path} is
|
||||
GoPath sets and overrides GOPATH with the given {path}. If no {path} is
|
||||
given it shows the current GOPATH. If `""` is given as path, it clears
|
||||
current `GOPATH` which was set with |GoPath| and restores `GOPATH` back to
|
||||
the inital value which was sourced when Vim was started.
|
||||
the initial value which was sourced when Vim was started.
|
||||
|
||||
*:GoImport*
|
||||
:GoImport [path]
|
||||
:GoImport[!] [path]
|
||||
|
||||
Import ensures that the provided package {path} is imported in the current
|
||||
Go buffer, using proper style and ordering. If {path} is already being
|
||||
Go buffer, using proper style and ordering. If {path} is already being
|
||||
imported, an error will be displayed and the buffer will be untouched.
|
||||
|
||||
If [!] is given it will download the package with `go get`
|
||||
|
||||
*:GoImportAs*
|
||||
:GoImportAs [localname] [path]
|
||||
|
||||
@ -138,9 +149,9 @@ COMMANDS *go-commands*
|
||||
displayed and the buffer will be untouched.
|
||||
|
||||
*:GoLint*
|
||||
:GoLint
|
||||
:GoLint [packages]
|
||||
|
||||
Run golint for the current Go file.
|
||||
Run golint for the current Go file, or for given packages.
|
||||
|
||||
*:GoDoc*
|
||||
:GoDoc [word]
|
||||
@ -177,7 +188,7 @@ COMMANDS *go-commands*
|
||||
'xterm-clipboard' otherwise it's get yanked into the `""` register.
|
||||
|
||||
*:GoVet*
|
||||
:GoVet[!]
|
||||
:GoVet[!] [options]
|
||||
|
||||
Run `go vet` for the directory under your current file. Vet examines Go
|
||||
source code and reports suspicious constructs, such as Printf calls whose
|
||||
@ -185,6 +196,10 @@ COMMANDS *go-commands*
|
||||
guarantee all reports are genuine problems, but it can find errors not caught
|
||||
by the compilers.
|
||||
|
||||
You may optionally pass any valid go tool vet flags/options. In this case,
|
||||
`go tool vet` is run in place of `go vet`. For a full list please see
|
||||
`go tool vet -h`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoDef*
|
||||
@ -202,42 +217,48 @@ COMMANDS *go-commands*
|
||||
current file is used. If an argument is passed, 'expand' is used as file
|
||||
selector. For example use `:GoRun %` to select the current file only.
|
||||
|
||||
You may optionally pass any valid go run flags/options. For a full list
|
||||
please see `go help run`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoBuild*
|
||||
:GoBuild[!] [options]
|
||||
:GoBuild[!] [expand]
|
||||
|
||||
Build your package with `go build`. It automatically builds only the files
|
||||
that depends on the current file. GoBuild doesn't produce a result file.
|
||||
Use 'make' to create a result file.
|
||||
|
||||
You may optionally pass any valid go build flags/options. For a full list
|
||||
please see `go help build`.
|
||||
please see `go help build`. Options are expanded with 'expand'.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoGenerate*
|
||||
:GoGenerate[!] [options]
|
||||
:GoGenerate[!] [expand]
|
||||
|
||||
Creates or updates your auto-generated source files by running `go
|
||||
generate`.
|
||||
|
||||
You may optionally pass any valid go generate flags/options. For a full list
|
||||
please see `go help generate`.
|
||||
please see `go help generate`. Options are expanded with 'expand'.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoInfo*
|
||||
:GoInfo
|
||||
Show type information about the identifer under the cursor. For example
|
||||
Show type information about the identifier under the cursor. For example
|
||||
putting it above a function call is going to show the full function
|
||||
signature. It uses gocode to get the type informations.
|
||||
|
||||
|
||||
*:GoInstall*
|
||||
:GoInstall[!]
|
||||
:GoInstall[!] [options]
|
||||
|
||||
Install your package with `go install`.
|
||||
Install your package with `go install`.
|
||||
|
||||
You may optionally pass any valid go install flags/options. For a full list
|
||||
please see `go help install`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
@ -245,9 +266,16 @@ COMMANDS *go-commands*
|
||||
:GoTest[!] [expand]
|
||||
|
||||
Run the tests on your _test.go files via in your current directory. Errors
|
||||
are populated in quickfix window. If an argument is passed, 'expand' is
|
||||
are populated in location list. If an argument is passed, 'expand' is
|
||||
used as file selector (useful for cases like `:GoTest ./...`).
|
||||
|
||||
You may optionally pass any valid go test flags/options. For a full list
|
||||
please see `go help test`.
|
||||
|
||||
GoTest timesout automatically after 10 seconds. To customize the timeout
|
||||
use |g:go_test_timeout|. This feature is disabled if any arguments are
|
||||
passed to the `:GoTest` command.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoTestFunc*
|
||||
@ -266,7 +294,7 @@ COMMANDS *go-commands*
|
||||
:GoTestCompile[!] [expand]
|
||||
|
||||
Compile your _test.go files via in your current directory. Errors are
|
||||
populated in quickfix window. If an argument is passed, 'expand' is used
|
||||
populated in location list. If an argument is passed, 'expand' is used
|
||||
as file selector (useful for cases like `:GoTest ./...`). Useful to not
|
||||
run the tests and capture/fix errors before running the tests or to
|
||||
create test binary.
|
||||
@ -274,18 +302,24 @@ COMMANDS *go-commands*
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoCoverage*
|
||||
:GoCoverage[!]
|
||||
:GoCoverage[!] [options]
|
||||
|
||||
Create a coverage profile and open a browser to display the annotated
|
||||
source code of the current package.
|
||||
|
||||
You may optionally pass any valid go test flags/options, such as
|
||||
`-covermode set,count,atomic`. For a full list please see `go help test`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoErrCheck*
|
||||
:GoErrCheck
|
||||
:GoErrCheck [options]
|
||||
|
||||
Check for unchecked errors in you current package. Errors are populated in
|
||||
quickfix window.
|
||||
location list.
|
||||
|
||||
You may optionally pass any valid errcheck flags/options. For a full list
|
||||
please see `errcheck -h`.
|
||||
|
||||
*:GoFiles*
|
||||
:GoFiles
|
||||
@ -315,13 +349,15 @@ COMMANDS *go-commands*
|
||||
|
||||
Show 'implements' relation for a selected package. A list of interfaces
|
||||
for the type that implements an interface under the cursor (or selected
|
||||
package) is shown quickfix list.
|
||||
package) is shown location list.
|
||||
*:GoRename*
|
||||
:GoRename [to]
|
||||
:GoRename[!] [to]
|
||||
|
||||
Rename the identifier under the cursor to the desired new name. If no
|
||||
argument is given a prompt will ask for the desired identifier.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
|
||||
*:GoOracleScope*
|
||||
:GoOracleScope [path1] [path2] ...
|
||||
@ -336,13 +372,13 @@ COMMANDS *go-commands*
|
||||
|
||||
Show 'callees' relation for a selected package. A list of possible call
|
||||
targets for the type under the cursor (or selected package) is shown in a
|
||||
quickfix list.
|
||||
location list.
|
||||
|
||||
*:GoCallers*
|
||||
:GoCallers
|
||||
|
||||
Show 'callers' relation for a selected function. A list of possible
|
||||
callers for the selected function under the cursor is shown in a quickfix
|
||||
callers for the selected function under the cursor is shown in a location
|
||||
list.
|
||||
|
||||
*:GoDescribe*
|
||||
@ -359,7 +395,7 @@ COMMANDS *go-commands*
|
||||
|
||||
Shows 'callstack' relation for the selected function. An arbitrary path
|
||||
from the root of the callgraph to the selected function is showed in a
|
||||
quickfix list. This may be useful to understand how the function is
|
||||
location list. This may be useful to understand how the function is
|
||||
reached in a given program.
|
||||
|
||||
*:GoFreevars*
|
||||
@ -395,6 +431,26 @@ COMMANDS *go-commands*
|
||||
object as does the selected identifier, within any package in the analysis
|
||||
scope.
|
||||
|
||||
*:GoMetaLinter*
|
||||
:GoMetaLinter [path]
|
||||
|
||||
Calls the underlying `gometalinter` tool and displays all warnings and
|
||||
errors in a location list. By default the following linters are enabled:
|
||||
"'vet', 'golint', 'errcheck'". This can be changed with the
|
||||
|g:go_metalinter_enabled| variable. To override the command completely use
|
||||
the variable |g:go_metalinter_command|. To override the maximum linters
|
||||
execution time use |g:go_metalinter_deadline| variable.
|
||||
|
||||
*:GoOracleTags*
|
||||
:GoOracleTags [tags]
|
||||
|
||||
Changes the custom |g:go_oracle_tags| setting and overrides it with the
|
||||
given build tags. This command cooperate with GoReferrers command when
|
||||
there exist mulitiple build tags in your project,then you can set one
|
||||
of the build tags for GoReferrers to find more accurate.
|
||||
The custom build tags is cleared (unset) if `""` is given. If no arguments
|
||||
is given it prints the current custom build tags.
|
||||
|
||||
|
||||
===============================================================================
|
||||
MAPPINGS *go-mappings*
|
||||
@ -544,6 +600,9 @@ Show send/receive corresponding to selected channel op
|
||||
|
||||
Show all refs to entity denoted by selected identifier
|
||||
|
||||
*(go-metalinter)*
|
||||
|
||||
Calls `go-metalinter` for the current directory
|
||||
|
||||
===============================================================================
|
||||
TEXT OBJECTS *go-text-objects*
|
||||
@ -564,6 +623,14 @@ if "inside a function", select contents of a function,
|
||||
===============================================================================
|
||||
SETTINGS *go-settings*
|
||||
|
||||
*'g:go_test_timeout'*
|
||||
|
||||
Use this option to change the test timeout of |:GoTest|. By default it is
|
||||
set to 10 seconds . >
|
||||
|
||||
let g:go_test_timeout= '10s'
|
||||
<
|
||||
|
||||
*'g:go_play_browser_command'*
|
||||
|
||||
Use this option to change the browser that is used to open the snippet url
|
||||
@ -571,7 +638,7 @@ posted to play.golang.org with |:GoPlay| or for the relevant documentation
|
||||
used with |:GoDocBrowser|. By default it tries to find it automatically for
|
||||
the current OS. >
|
||||
|
||||
let g:play_browser_command = ''
|
||||
let g:go_play_browser_command = ''
|
||||
<
|
||||
*'g:go_play_open_browser'*
|
||||
|
||||
@ -623,7 +690,7 @@ is empty. >
|
||||
|
||||
*'g:go_fmt_fail_silently'*
|
||||
|
||||
Use this option to disable showing a quickfix window when |g:go_fmt_command|
|
||||
Use this option to disable showing a location list when |g:go_fmt_command|
|
||||
fails. By default it's disabled. >
|
||||
|
||||
let g:go_fmt_fail_silently = 0
|
||||
@ -772,6 +839,13 @@ Highlights build constraints. By default it's disabled. >
|
||||
|
||||
let g:go_highlight_build_constraints = 0
|
||||
<
|
||||
*'g:go_highlight_string_spellcheck*
|
||||
|
||||
Specifies spell checking enabled for strings. Spelling errors are highlighted
|
||||
if |spell| is enabled. By default it's enabled. >
|
||||
|
||||
let g:go_highlight_string_spellcheck = 1
|
||||
<
|
||||
|
||||
*'g:go_autodetect_gopath'*
|
||||
|
||||
@ -779,7 +853,7 @@ Automatically modifies GOPATH for certain directory structures, such as for
|
||||
the tool godep which has his own dependencies via the `Godeps` folder. What
|
||||
this means is that all tools are now working with the newly modified GOPATH.
|
||||
So |GoDef| for example jumps to the source inside the `Godeps` (vendored)
|
||||
source. Currently only `godep` is supported, in the near future more tool
|
||||
source. Currently `godep` and `gb` is supported, in the near future more tool
|
||||
supports will be added. By default it's enabled. >
|
||||
|
||||
let g:go_autodetect_gopath = 1
|
||||
@ -789,12 +863,56 @@ supports will be added. By default it's enabled. >
|
||||
Adds custom text objects. By default it's enabled. >
|
||||
|
||||
let g:go_textobj_enabled = 1
|
||||
<
|
||||
*'g:go_metalinter_autosave'*
|
||||
|
||||
Use this option to auto |:GoMetaLinter| on save. Only linter messages for
|
||||
the active buffer will be shown. By default it's disabled >
|
||||
|
||||
let g:go_metalinter_autosave = 0
|
||||
<
|
||||
*'g:go_metalinter_autosave_enabled'*
|
||||
|
||||
Specifies the enabled linters for auto |GoMetaLinter| on save. By
|
||||
default it's using `vet` and `golint`
|
||||
>
|
||||
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
|
||||
<
|
||||
*'g:go_metalinter_enabled'*
|
||||
|
||||
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_command'*
|
||||
|
||||
Overrides the command to be executed when |GoMetaLinter| is called. This is
|
||||
an advanced settings and is for users who want to have a complete control
|
||||
over of how `gometalinter` should be executed. By default it's empty.
|
||||
>
|
||||
let g:go_metalinter_command = ""
|
||||
<
|
||||
*'g:go_metalinter_deadline'*
|
||||
|
||||
Overrides the maximum time the linters have to complete. By default it's 5
|
||||
seconds.
|
||||
>
|
||||
let g:go_metalinter_deadline = "5s"
|
||||
<
|
||||
*'g:go_loclist_height'*
|
||||
|
||||
Specifies the current location list height for all location lists. The default
|
||||
value (empty) sets automatically the height to the number of errors (maximum
|
||||
up to 10 errors to prevent large heights). Setting the value explicitly
|
||||
overrides this behavior. To get default Vim behavior set it to 10.
|
||||
>
|
||||
let g:go_loclist_height = 0
|
||||
|
||||
===============================================================================
|
||||
TROUBLESHOOTING *go-troubleshooting*
|
||||
|
||||
I'm using Fish shell but have some problems using Vim-go~
|
||||
I'm using Fish shell but have some problems using vim-go~
|
||||
|
||||
First environment variables in Fish are applied differently, it should be like:
|
||||
>
|
||||
@ -802,7 +920,7 @@ First environment variables in Fish are applied differently, it should be like:
|
||||
<
|
||||
Second, Vim needs a POSIX compatible shell (more info here:
|
||||
https://github.com/dag/vim-fish#teach-a-vim-to-fish). If you use Fish to open
|
||||
vim, it will make certainx shell based commands fail (means vim-go will fail
|
||||
Vim, it will make certain shell based commands fail (means vim-go will fail
|
||||
too). To overcome this problem change the default shell by adding the
|
||||
following into your .vimrc (on the top of the file):
|
||||
>
|
||||
@ -815,7 +933,7 @@ or
|
||||
set shell='/bin/sh'
|
||||
>
|
||||
|
||||
I'm seeing weirds errors during installation of binaries with
|
||||
I'm seeing weird errors during installation of binaries with
|
||||
GoInstallBinaries:
|
||||
|
||||
If you see errors like this:
|
||||
@ -835,7 +953,7 @@ You'll see a more detailed error. If this works, vim-go will work too.
|
||||
===============================================================================
|
||||
CREDITS *go-credits*
|
||||
|
||||
* Go Authors for offical vim plugins
|
||||
* Go Authors for official vim plugins
|
||||
* Gocode, Godef, Golint, Oracle, Goimports, Errcheck projects and authors of
|
||||
those projects.
|
||||
* Other vim-plugins, thanks for inspiration (vim-golang, go.vim, vim-gocode,
|
||||
|
@ -18,7 +18,7 @@ function! s:gofiletype_post()
|
||||
let &g:fileencodings = s:current_fileencodings
|
||||
endfunction
|
||||
|
||||
au BufNewFile *.go setlocal filetype=go fileencoding=utf-8 fileformat=unix
|
||||
au BufNewFile *.go setfiletype go | setlocal fileencoding=utf-8 fileformat=unix
|
||||
au BufRead *.go call s:gofiletype_pre()
|
||||
au BufReadPost *.go call s:gofiletype_post()
|
||||
|
||||
|
@ -1,62 +1,8 @@
|
||||
if exists("g:go_loaded_commands")
|
||||
finish
|
||||
endif
|
||||
let g:go_loaded_commands = 1
|
||||
|
||||
" go_jump_to_error defines whether we should pass the bang attribute to the
|
||||
" command or not. This is only used for mappings, because the user can't pass
|
||||
" the bang attribute to the plug mappings below. So instead of hardcoding it
|
||||
" as 0 (no '!' attribute) or 1 (with '!' attribute) we pass the user setting,
|
||||
" which by default is enabled. For commands the user has the ability to pass
|
||||
" the '!', such as :GoBuild or :GoBuild!
|
||||
if !exists("g:go_jump_to_error")
|
||||
let g:go_jump_to_error = 1
|
||||
endif
|
||||
|
||||
|
||||
" Some handy plug mappings
|
||||
nnoremap <silent> <Plug>(go-run) :<C-u>call go#cmd#Run(!g:go_jump_to_error,expand('%'))<CR>
|
||||
nnoremap <silent> <Plug>(go-build) :<C-u>call go#cmd#Build(!g:go_jump_to_error,'')<CR>
|
||||
nnoremap <silent> <Plug>(go-generate) :<C-u>call go#cmd#Generate(!g:go_jump_to_error,'')<CR>
|
||||
nnoremap <silent> <Plug>(go-install) :<C-u>call go#cmd#Install(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-test) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 0, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-test-func) :<C-u>call go#cmd#TestFunc(!g:go_jump_to_error, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-test-compile) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 1, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-coverage) :<C-u>call go#cmd#Coverage(!g:go_jump_to_error, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#cmd#Vet(!g:go_jump_to_error)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-files) :<C-u>call go#tool#Files()<CR>
|
||||
nnoremap <silent> <Plug>(go-deps) :<C-u>call go#tool#Deps()<CR>
|
||||
nnoremap <silent> <Plug>(go-info) :<C-u>call go#complete#Info()<CR>
|
||||
nnoremap <silent> <Plug>(go-import) :<C-u>call go#import#SwitchImport(1, '', expand('<cword>'))<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-implements) :<C-u>call go#oracle#Implements(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callees) :<C-u>call go#oracle#Callees(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callers) :<C-u>call go#oracle#Callers(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-describe) :<C-u>call go#oracle#Describe(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callstack) :<C-u>call go#oracle#Callstack(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-freevars) :<C-u>call go#oracle#Freevars(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-channelpeers) :<C-u>call go#oracle#ChannelPeers(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-referrers) :<C-u>call go#oracle#Referrers(-1)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-rename) :<C-u>call go#rename#Rename()<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-def) :<C-u>call go#def#Jump()<CR>
|
||||
nnoremap <silent> <Plug>(go-def-vertical) :<C-u>call go#def#JumpMode("vsplit")<CR>
|
||||
nnoremap <silent> <Plug>(go-def-split) :<C-u>call go#def#JumpMode("split")<CR>
|
||||
nnoremap <silent> <Plug>(go-def-tab) :<C-u>call go#def#JumpMode("tab")<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-doc) :<C-u>call go#doc#Open("new", "split")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-tab) :<C-u>call go#doc#Open("tabnew", "tabe")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-vertical) :<C-u>call go#doc#Open("vnew", "vsplit")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-split) :<C-u>call go#doc#Open("new", "split")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-browser) :<C-u>call go#doc#OpenBrowser()<CR>
|
||||
|
||||
|
||||
" gorename
|
||||
command! -nargs=? GoRename call go#rename#Rename(<f-args>)
|
||||
command! -nargs=? GoRename call go#rename#Rename(<bang>0,<f-args>)
|
||||
|
||||
" oracle
|
||||
command! -nargs=* -complete=customlist,go#package#Complete GoOracleScope call go#oracle#Scope(<f-args>)
|
||||
command! -range=% GoImplements call go#oracle#Implements(<count>)
|
||||
command! -range=% GoCallees call go#oracle#Callees(<count>)
|
||||
command! -range=% GoDescribe call go#oracle#Describe(<count>)
|
||||
@ -65,8 +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=* -complete=customlist,go#package#Complete GoOracleScope call go#oracle#Scope(<f-args>)
|
||||
command! -nargs=? GoOracleTags call go#oracle#Tags(<f-args>)
|
||||
|
||||
" tool
|
||||
command! -nargs=0 GoFiles echo go#tool#Files()
|
||||
@ -82,7 +27,6 @@ command! -nargs=* -bang GoTest call go#cmd#Test(<bang>0, 0, <f-args>)
|
||||
command! -nargs=* -bang GoTestFunc call go#cmd#TestFunc(<bang>0, <f-args>)
|
||||
command! -nargs=* -bang GoTestCompile call go#cmd#Test(<bang>0, 1, <f-args>)
|
||||
command! -nargs=* -bang GoCoverage call go#cmd#Coverage(<bang>0, <f-args>)
|
||||
command! -nargs=0 -bang GoVet call go#cmd#Vet(<bang>0)
|
||||
|
||||
" -- play
|
||||
command! -nargs=0 -range=% GoPlay call go#play#Share(<count>, <line1>, <line2>)
|
||||
@ -99,14 +43,14 @@ command! -nargs=0 GoFmt call go#fmt#Format(-1)
|
||||
command! -nargs=0 GoImports call go#fmt#Format(1)
|
||||
|
||||
" -- import
|
||||
command! -nargs=? -complete=customlist,go#package#Complete GoDrop call go#import#SwitchImport(0, '', <f-args>)
|
||||
command! -nargs=1 -complete=customlist,go#package#Complete GoImport call go#import#SwitchImport(1, '', <f-args>)
|
||||
command! -nargs=* -complete=customlist,go#package#Complete GoImportAs call go#import#SwitchImport(1, <f-args>)
|
||||
command! -nargs=? -complete=customlist,go#package#Complete GoDrop call go#import#SwitchImport(0, '', <f-args>, '')
|
||||
command! -nargs=1 -bang -complete=customlist,go#package#Complete GoImport call go#import#SwitchImport(1, '', <f-args>, '<bang>')
|
||||
command! -nargs=* -bang -complete=customlist,go#package#Complete GoImportAs call go#import#SwitchImport(1, <f-args>, '<bang>')
|
||||
|
||||
" -- lint
|
||||
command! GoLint call go#lint#Run()
|
||||
|
||||
" -- errcheck
|
||||
command! -nargs=? -complete=customlist,go#package#Complete GoErrCheck call go#errcheck#Run(<f-args>)
|
||||
" -- linters
|
||||
command! -nargs=* GoMetaLinter call go#lint#Gometa(0, <f-args>)
|
||||
command! -nargs=* GoLint call go#lint#Golint(<f-args>)
|
||||
command! -nargs=* -bang GoVet call go#lint#Vet(<bang>0, <f-args>)
|
||||
command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck(<f-args>)
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
52
sources_non_forked/vim-go/ftplugin/go/mappings.vim
Normal file
52
sources_non_forked/vim-go/ftplugin/go/mappings.vim
Normal file
@ -0,0 +1,52 @@
|
||||
" go_jump_to_error defines whether we should pass the bang attribute to the
|
||||
" command or not. This is only used for mappings, because the user can't pass
|
||||
" the bang attribute to the plug mappings below. So instead of hardcoding it
|
||||
" as 0 (no '!' attribute) or 1 (with '!' attribute) we pass the user setting,
|
||||
" which by default is enabled. For commands the user has the ability to pass
|
||||
" the '!', such as :GoBuild or :GoBuild!
|
||||
if !exists("g:go_jump_to_error")
|
||||
let g:go_jump_to_error = 1
|
||||
endif
|
||||
|
||||
|
||||
" Some handy plug mappings
|
||||
nnoremap <silent> <Plug>(go-run) :<C-u>call go#cmd#Run(!g:go_jump_to_error, '%')<CR>
|
||||
nnoremap <silent> <Plug>(go-build) :<C-u>call go#cmd#Build(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-generate) :<C-u>call go#cmd#Generate(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-install) :<C-u>call go#cmd#Install(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-test) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 0)<CR>
|
||||
nnoremap <silent> <Plug>(go-test-func) :<C-u>call go#cmd#TestFunc(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-test-compile) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 1)<CR>
|
||||
nnoremap <silent> <Plug>(go-coverage) :<C-u>call go#cmd#Coverage(!g:go_jump_to_error)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-files) :<C-u>call go#tool#Files()<CR>
|
||||
nnoremap <silent> <Plug>(go-deps) :<C-u>call go#tool#Deps()<CR>
|
||||
nnoremap <silent> <Plug>(go-info) :<C-u>call go#complete#Info()<CR>
|
||||
nnoremap <silent> <Plug>(go-import) :<C-u>call go#import#SwitchImport(1, '', expand('<cword>'), '')<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-implements) :<C-u>call go#oracle#Implements(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callees) :<C-u>call go#oracle#Callees(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callers) :<C-u>call go#oracle#Callers(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-describe) :<C-u>call go#oracle#Describe(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callstack) :<C-u>call go#oracle#Callstack(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-freevars) :<C-u>call go#oracle#Freevars(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-channelpeers) :<C-u>call go#oracle#ChannelPeers(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-referrers) :<C-u>call go#oracle#Referrers(-1)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-rename) :<C-u>call go#rename#Rename(!g:go_jump_to_error)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-def) :<C-u>call go#def#Jump()<CR>
|
||||
nnoremap <silent> <Plug>(go-def-vertical) :<C-u>call go#def#JumpMode("vsplit")<CR>
|
||||
nnoremap <silent> <Plug>(go-def-split) :<C-u>call go#def#JumpMode("split")<CR>
|
||||
nnoremap <silent> <Plug>(go-def-tab) :<C-u>call go#def#JumpMode("tab")<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-doc) :<C-u>call go#doc#Open("new", "split")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-tab) :<C-u>call go#doc#Open("tabnew", "tabe")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-vertical) :<C-u>call go#doc#Open("vnew", "vsplit")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-split) :<C-u>call go#doc#Open("new", "split")<CR>
|
||||
nnoremap <silent> <Plug>(go-doc-browser) :<C-u>call go#doc#OpenBrowser()<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-metalinter) :<C-u>call go#lint#Gometa(0)<CR>
|
||||
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#lint#Vet(!g:go_jump_to_error)<CR>
|
||||
|
||||
|
@ -9,6 +9,7 @@ let g:go_loaded_install = 1
|
||||
" needed by the user with GoInstallBinaries
|
||||
let s:packages = [
|
||||
\ "github.com/nsf/gocode",
|
||||
\ "github.com/alecthomas/gometalinter",
|
||||
\ "golang.org/x/tools/cmd/goimports",
|
||||
\ "github.com/rogpeppe/godef",
|
||||
\ "golang.org/x/tools/cmd/oracle",
|
||||
@ -132,6 +133,11 @@ augroup vim-go
|
||||
autocmd BufWritePre *.go call go#fmt#Format(-1)
|
||||
endif
|
||||
|
||||
" run gometalinter on save
|
||||
if get(g:, "go_metalinter_autosave", 0)
|
||||
autocmd BufWritePost *.go call go#lint#Gometa(1)
|
||||
endif
|
||||
|
||||
augroup END
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
" let OPTION_NAME = 0
|
||||
" in your ~/.vimrc file to disable particular options. You can also write:
|
||||
" let OPTION_NAME = 1
|
||||
" to enable particular options.
|
||||
" to enable particular options.
|
||||
" At present, all options default to on, except highlight of:
|
||||
" functions, methods and structs.
|
||||
"
|
||||
@ -25,6 +25,8 @@
|
||||
" Highlights instances of tabs following spaces.
|
||||
" - go_highlight_trailing_whitespace_error
|
||||
" Highlights trailing white space.
|
||||
" - go_highlight_string_spellcheck
|
||||
" Specifies that strings should be spell checked
|
||||
|
||||
" Quit when a (custom) syntax file was already loaded
|
||||
if exists("b:current_syntax")
|
||||
@ -52,23 +54,27 @@ if !exists("g:go_highlight_trailing_whitespace_error")
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_operators")
|
||||
let g:go_highlight_operators = 0
|
||||
let g:go_highlight_operators = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_functions")
|
||||
let g:go_highlight_functions = 0
|
||||
let g:go_highlight_functions = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_methods")
|
||||
let g:go_highlight_methods = 0
|
||||
let g:go_highlight_methods = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_structs")
|
||||
let g:go_highlight_structs = 0
|
||||
let g:go_highlight_structs = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_build_constraints")
|
||||
let g:go_highlight_build_constraints = 0
|
||||
let g:go_highlight_build_constraints = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_string_spellcheck")
|
||||
let g:go_highlight_string_spellcheck = 1
|
||||
endif
|
||||
|
||||
syn case match
|
||||
@ -111,8 +117,8 @@ syn match goDeclaration /\<func\>/
|
||||
|
||||
|
||||
" Predefined functions and values
|
||||
syn keyword goBuiltins append cap close complex copy delete imag len
|
||||
syn keyword goBuiltins make new panic print println real recover
|
||||
syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/
|
||||
syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/
|
||||
syn keyword goBoolean iota true false nil
|
||||
|
||||
hi def link goBuiltins Keyword
|
||||
@ -145,13 +151,18 @@ hi def link goEscapeError Error
|
||||
|
||||
" Strings and their contents
|
||||
syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
|
||||
syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
|
||||
syn region goRawString start=+`+ end=+`+
|
||||
if g:go_highlight_string_spellcheck != 0
|
||||
syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup,@Spell
|
||||
syn region goRawString start=+`+ end=+`+ contains=@Spell
|
||||
else
|
||||
syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
|
||||
syn region goRawString start=+`+ end=+`+
|
||||
endif
|
||||
syn match goFormatSpecifier /%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)*[vTtbcdoqxXUeEfgGsp]/ contained containedin=goString
|
||||
|
||||
hi def link goString String
|
||||
hi def link goRawString String
|
||||
hi def link goFormatSpecifier goSpecialString
|
||||
hi def link goFormatSpecifier goSpecialString
|
||||
|
||||
" Characters; their contents
|
||||
syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU
|
||||
@ -234,57 +245,76 @@ syn keyword goTodo contained NOTE
|
||||
hi def link goTodo Todo
|
||||
|
||||
|
||||
" Operators;
|
||||
" Operators;
|
||||
if g:go_highlight_operators != 0
|
||||
" match single-char operators: - + % < > ! & | ^ * =
|
||||
" and corresponding two-char operators: -= += %= <= >= != &= |= ^= *= ==
|
||||
syn match goOperator /[-+%<>!&|^*=]=\?/
|
||||
" match / and /=
|
||||
syn match goOperator /\/\%(=\|\ze[^/*]\)/
|
||||
" match two-char operators: << >> &^
|
||||
" and corresponding three-char operators: <<= >>= &^=
|
||||
syn match goOperator /\%(<<\|>>\|&^\)=\?/
|
||||
" match remaining two-char operators: := && || <- ++ --
|
||||
syn match goOperator /:=\|||\|<-\|++\|--/
|
||||
" match ...
|
||||
syn match goOperator /\.\.\./
|
||||
" match single-char operators: - + % < > ! & | ^ * =
|
||||
" and corresponding two-char operators: -= += %= <= >= != &= |= ^= *= ==
|
||||
syn match goOperator /[-+%<>!&|^*=]=\?/
|
||||
" match / and /=
|
||||
syn match goOperator /\/\%(=\|\ze[^/*]\)/
|
||||
" match two-char operators: << >> &^
|
||||
" and corresponding three-char operators: <<= >>= &^=
|
||||
syn match goOperator /\%(<<\|>>\|&^\)=\?/
|
||||
" match remaining two-char operators: := && || <- ++ --
|
||||
syn match goOperator /:=\|||\|<-\|++\|--/
|
||||
" match ...
|
||||
syn match goOperator /\.\.\./
|
||||
endif
|
||||
hi def link goOperator Operator
|
||||
hi def link goOperator Operator
|
||||
|
||||
" Functions;
|
||||
" Functions;
|
||||
if g:go_highlight_functions != 0
|
||||
syn match goFunction /\(func\s\+\)\@<=\w\+\((\)\@=/
|
||||
syn match goFunction /\()\s\+\)\@<=\w\+\((\)\@=/
|
||||
syn match goFunction /\(func\s\+\)\@<=\w\+\((\)\@=/
|
||||
syn match goFunction /\()\s\+\)\@<=\w\+\((\)\@=/
|
||||
endif
|
||||
hi def link goFunction Function
|
||||
hi def link goFunction Function
|
||||
|
||||
" Methods;
|
||||
" Methods;
|
||||
if g:go_highlight_methods != 0
|
||||
syn match goMethod /\(\.\)\@<=\w\+\((\)\@=/
|
||||
syn match goMethod /\(\.\)\@<=\w\+\((\)\@=/
|
||||
endif
|
||||
hi def link goMethod Type
|
||||
hi def link goMethod Type
|
||||
|
||||
" Structs;
|
||||
" Structs;
|
||||
if g:go_highlight_structs != 0
|
||||
syn match goStruct /\(.\)\@<=\w\+\({\)\@=/
|
||||
syn match goStructDef /\(type\s\+\)\@<=\w\+\(\s\+struct\s\+{\)\@=/
|
||||
syn match goStruct /\(.\)\@<=\w\+\({\)\@=/
|
||||
syn match goStructDef /\(type\s\+\)\@<=\w\+\(\s\+struct\s\+{\)\@=/
|
||||
endif
|
||||
hi def link goStruct Function
|
||||
hi def link goStruct Function
|
||||
hi def link goStructDef Function
|
||||
|
||||
" Build Constraints
|
||||
if g:go_highlight_build_constraints != 0
|
||||
syn keyword goBuildOs contained ignore cgo android darwin dragonfly freebsd linux nacl netbsd openbsd plan9 solaris windows
|
||||
syn keyword goBuildArch contained 386 amd64 amd64p32 arm
|
||||
syn match goBuildDirective display contained "+build"
|
||||
syn region goBuildComment start="//\s*+build" end="$" contains=goBuildDirective,goBuildOs,goBuildArch
|
||||
syn region goBuildComment start="/\*\s*+build" end="\*/" contains=goBuildDirective,goBuildOs,goBuildArch
|
||||
endif
|
||||
syn match goBuildKeyword display contained "+build"
|
||||
" Highlight the known values of GOOS, GOARCH, and other +build options.
|
||||
syn keyword goBuildDirectives contained
|
||||
\ android darwin dragonfly freebsd linux nacl netbsd openbsd plan9
|
||||
\ solaris windows 386 amd64 amd64p32 arm armbe arm64 arm64be ppc64
|
||||
\ ppc64le mips mipsle mips64 mips64le mips64p32 mips64p32le ppc
|
||||
\ s390 s390x sparc sparc64 cgo ignore race
|
||||
|
||||
hi def link goBuildComment Comment
|
||||
hi def link goBuildOs Type
|
||||
hi def link goBuildArch Type
|
||||
hi def link goBuildDirective PreProc
|
||||
" Other words in the build directive are build tags not listed above, so
|
||||
" avoid highlighting them as comments by using a matchgroup just for the
|
||||
" start of the comment.
|
||||
" The rs=s+2 option lets the \s*+build portion be part of the inner region
|
||||
" instead of the matchgroup so it will be highlighted as a goBuildKeyword.
|
||||
syn region goBuildComment matchgroup=goBuildCommentStart
|
||||
\ start="//\s*+build\s"rs=s+2 end="$"
|
||||
\ contains=goBuildKeyword,goBuildDirectives
|
||||
hi def link goBuildCommentStart Comment
|
||||
hi def link goBuildDirectives Type
|
||||
hi def link goBuildKeyword PreProc
|
||||
|
||||
" One or more line comments that are followed immediately by a "package"
|
||||
" declaration are treated like package documentation, so these must be
|
||||
" matched as comments to avoid looking like working build constraints.
|
||||
" The he, me, and re options let the "package" itself be highlighted by
|
||||
" the usual rules.
|
||||
syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/
|
||||
\ end=/\v\n\s*package/he=e-7,me=e-7,re=e-7
|
||||
\ contains=@goCommentGroup,@Spell
|
||||
hi def link goPackageComment Comment
|
||||
endif
|
||||
|
||||
|
||||
" Search backwards for a global declaration to start processing the syntax.
|
||||
|
@ -37,7 +37,7 @@ hi def link goRawString String
|
||||
|
||||
" Characters; their contents
|
||||
syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU
|
||||
syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup
|
||||
syn region goCharacter contained start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup
|
||||
|
||||
hi def link goCharacter Character
|
||||
|
||||
@ -65,8 +65,8 @@ hi def link goImaginary Number
|
||||
syn cluster gotplLiteral contains=goString,goRawString,goCharacter,@goInt,goFloat,goImaginary
|
||||
syn keyword gotplControl contained if else end range with template
|
||||
syn keyword gotplFunctions contained and html index js len not or print printf println urlquery eq ne lt le gt ge
|
||||
syn match gotplVariable contained /\$[^ ]*\>/
|
||||
syn match goTplIdentifier contained /\.[^ ]*\>/
|
||||
syn match gotplVariable contained /\$[a-zA-Z0-9_]*\>/
|
||||
syn match goTplIdentifier contained /\.[^\s}]*\>/
|
||||
|
||||
hi def link gotplControl Keyword
|
||||
hi def link gotplFunctions Function
|
||||
|
Reference in New Issue
Block a user