From 940367226adc66442f1953003be5a98f4dee8ed2 Mon Sep 17 00:00:00 2001 From: Marin Bek Date: Mon, 7 Mar 2016 14:13:48 +0100 Subject: [PATCH] vim-go update --- bundle/pristine/vim-go/README.md | 109 +++-- .../pristine/vim-go/autoload/go/alternate.vim | 30 ++ bundle/pristine/vim-go/autoload/go/asmfmt.vim | 52 +++ bundle/pristine/vim-go/autoload/go/cmd.vim | 258 +++++++---- .../pristine/vim-go/autoload/go/complete.vim | 26 +- bundle/pristine/vim-go/autoload/go/def.vim | 21 +- .../pristine/vim-go/autoload/go/errcheck.vim | 58 --- bundle/pristine/vim-go/autoload/go/fmt.vim | 101 +++-- bundle/pristine/vim-go/autoload/go/import.vim | 2 +- .../vim-go/autoload/go/jobcontrol.vim | 179 ++++++++ bundle/pristine/vim-go/autoload/go/lint.vim | 198 ++++++++- bundle/pristine/vim-go/autoload/go/list.vim | 126 ++++++ bundle/pristine/vim-go/autoload/go/oracle.vim | 78 ++-- .../pristine/vim-go/autoload/go/package.vim | 21 +- bundle/pristine/vim-go/autoload/go/path.vim | 10 +- bundle/pristine/vim-go/autoload/go/rename.vim | 41 +- bundle/pristine/vim-go/autoload/go/term.vim | 128 ++++++ bundle/pristine/vim-go/autoload/go/tool.vim | 69 +-- bundle/pristine/vim-go/autoload/go/util.vim | 102 +++-- bundle/pristine/vim-go/compiler/go.vim | 21 +- bundle/pristine/vim-go/doc/vim-go.txt | 400 ++++++++++++++---- .../pristine/vim-go/ftdetect/gofiletype.vim | 10 +- bundle/pristine/vim-go/ftplugin/asm.vim | 17 + .../pristine/vim-go/ftplugin/go/commands.vim | 73 +--- .../pristine/vim-go/ftplugin/go/mappings.vim | 60 +++ .../vim-go/gosnippets/snippets/go.snip | 5 +- bundle/pristine/vim-go/indent/gohtmltmpl.vim | 39 ++ bundle/pristine/vim-go/plugin/go.vim | 36 +- bundle/pristine/vim-go/scripts/test.sh | 0 bundle/pristine/vim-go/syntax/go.vim | 148 ++++--- bundle/pristine/vim-go/syntax/gotexttmpl.vim | 6 +- 31 files changed, 1888 insertions(+), 536 deletions(-) create mode 100644 bundle/pristine/vim-go/autoload/go/alternate.vim create mode 100644 bundle/pristine/vim-go/autoload/go/asmfmt.vim delete mode 100644 bundle/pristine/vim-go/autoload/go/errcheck.vim create mode 100644 bundle/pristine/vim-go/autoload/go/jobcontrol.vim create mode 100644 bundle/pristine/vim-go/autoload/go/list.vim create mode 100644 bundle/pristine/vim-go/autoload/go/term.vim create mode 100644 bundle/pristine/vim-go/ftplugin/asm.vim create mode 100644 bundle/pristine/vim-go/ftplugin/go/mappings.vim mode change 100644 => 100755 bundle/pristine/vim-go/scripts/test.sh diff --git a/bundle/pristine/vim-go/README.md b/bundle/pristine/vim-go/README.md index b33b3fa..1394c39 100644 --- a/bundle/pristine/vim-go/README.md +++ b/bundle/pristine/vim-go/README.md @@ -18,14 +18,16 @@ disabled/enabled easily. * 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` +* 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` -* Run `:GoTest` and see any errors in the quickfix window -* Automatic `GOPATH` detection based on the directory structure (i.e. `godep` - vendored projects) +* 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`, @@ -37,15 +39,23 @@ disabled/enabled easily. * Share your current code to [play.golang.org](http://play.golang.org) with `:GoPlay` * On-the-fly type information about the word under the cursor. Plug it into your custom vim function. +* Go asm formatting on save * Tagbar support to show tags of the source code in a sidebar with `gotags` * Custom vim text objects such as `a function` or `inner function` + list. +* A async launcher for the go command is implemented for Neovim, fully async + building and testing (beta). +* Integrated with the Neovim terminal, launch `:GoRun` and other go commands + in their own new terminal. (beta) +* Alternate between implementation and test code with `:GoAlternate` ## 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 oriented vim plugins. For Pathogen just clone the repo. For other plugin managers -add the appropriate lines and execute the plugin's install command. +Vim-go follows the standard runtime path structure, so I highly recommend to +use a common and well known plugin manager to install vim-go. Do not use vim-go +with other Go oriented vim plugins. For Pathogen just clone the repo. For other +plugin managers add the appropriate lines and execute the plugin's install +command. * [Pathogen](https://github.com/tpope/vim-pathogen) * `git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go` @@ -60,22 +70,26 @@ Please be sure all necessary binaries are installed (such as `gocode`, `godef`, `goimports`, etc.). You can easily install them with the included `:GoInstallBinaries` command. If invoked, all necessary binaries will be automatically downloaded and installed to your `$GOBIN` environment (if not set -it will use `$GOPATH/bin`). Note that this command requires `git` for fetching the individual Go -packages. +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 ``. To get real-time completion (completion by type) install: -[YCM](https://github.com/Valloric/YouCompleteMe) or -[neocomplete](https://github.com/Shougo/neocomplete.vim). +[neocomplete](https://github.com/Shougo/neocomplete.vim) for Vim or +[deoplete](https://github.com/Shougo/deoplete.nvim) and +[deoplete-go](https://github.com/zchee/deoplete-go) for NeoVim * To display source code tag information on a sidebar install [tagbar](https://github.com/majutsushi/tagbar). * 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). -* For a better documentation viewer checkout: [go-explorer](https://github.com/garyburd/go-explorer). +[neosnippet](https://github.com/Shougo/neosnippet.vim) or +[ultisnips](https://github.com/SirVer/ultisnips). +* Screenshot color scheme is a slightly modified molokai: + [fatih/molokai](https://github.com/fatih/molokai). +* For a better documentation viewer checkout: + [go-explorer](https://github.com/garyburd/go-explorer). ## Usage @@ -93,9 +107,9 @@ vim-go has several `` mappings which can be used to create custom mappings. Below are some examples you might find useful: Run commands such as `go run` for the current file with `r` or `go -build` and `go test` for the current package with `b` and `t` respectively. -Display beautifully annotated source code to see which functions are covered -with `c`. +build` and `go test` for the current package with `b` and `t` +respectively. Display beautifully annotated source code to see which functions +are covered with `c`. ```vim au FileType go nmap r (go-run) @@ -153,7 +167,8 @@ recommendations, you are free to create more advanced mappings or functions based on `:he go-commands`. ## Settings -Below are some settings you might find useful. For the full list see `:he go-settings`. +Below are some settings you might find useful. For the full list see `:he +go-settings`. By default syntax-highlighting for Functions, Methods and Structs is disabled. To change it: @@ -161,6 +176,7 @@ To change it: let g:go_highlight_functions = 1 let g:go_highlight_methods = 1 let g:go_highlight_structs = 1 +let g:go_highlight_interfaces = 1 let g:go_highlight_operators = 1 let g:go_highlight_build_constraints = 1 ``` @@ -197,25 +213,58 @@ let g:go_bin_path = expand("~/.gotools") let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path ``` +### Using with Neovim (beta) -## More info +Note: Neovim currently is not a first class citizen for vim-go. You are free +to open bugs but I'm not going to look at them. Even though I'm using Neovim +myself, Neovim itself is still alpha. So vim-go might not work well as good as +in Vim. I'm happy to accept pull requests or very detailed bug reports. + + +Run `:GoRun` in a new tab, horizontal split or vertical split terminal -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. +```vim +au FileType go nmap rt (go-run-tab) +au FileType go nmap rs (go-run-split) +au FileType go nmap rv (go-run-vertical) +``` + +By default new terminals are opened in a vertical split. To change it + +```vim +let g:go_term_mode = "split" +``` -## Donations +By default the testing commands run asynchronously in the background and +display results with `go#jobcontrol#Statusline()`. To make them run in a new +terminal -Vim-go is an open source project that I'm working on in my free time. I'm -putting in a lot of time and thought 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: +```vim +let g:go_term_enabled = 1 +``` + +### Using with Syntastic +Sometimes when using both `vim-go` and `syntastic` Vim will start lagging while +saving and opening files. The following fixes this: + +```vim +let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck'] +let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] } +``` + +## More info -[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 * Go Authors for official vim plugins -* Gocode, Godef, Golint, Oracle, Goimports, Gotags, Errcheck projects and authors of those projects. +* Gocode, Godef, Golint, Oracle, Goimports, Gotags, Errcheck projects and + authors of those projects. * Other vim-plugins, thanks for inspiration (vim-golang, go.vim, vim-gocode, vim-godef) * [Contributors](https://github.com/fatih/vim-go/graphs/contributors) of vim-go diff --git a/bundle/pristine/vim-go/autoload/go/alternate.vim b/bundle/pristine/vim-go/autoload/go/alternate.vim new file mode 100644 index 0000000..83951cf --- /dev/null +++ b/bundle/pristine/vim-go/autoload/go/alternate.vim @@ -0,0 +1,30 @@ +" By default use edit (current buffer view) to switch +if !exists("g:go_alternate_mode") + let g:go_alternate_mode = "edit" +endif + +" Test alternates between the implementation of code and the test code. +function! go#alternate#Switch(bang, cmd) + let l:file = go#alternate#Filename(fnameescape(expand("%"))) + if !filereadable(l:file) && !bufexists(l:file) && !a:bang + redraws! | echon "vim-go: " | echohl ErrorMsg | echon "couldn't find ".file | echohl None + return + elseif empty(a:cmd) + execute ":" . g:go_alternate_mode . " " . file + else + execute ":" . a:cmd . " " . file + endif +endfunction + +" Filename returns the name of the test file or implementation file +" depending on the arguments +function! go#alternate#Filename(path) + if empty(matchstr(a:path, "_test")) + let l:root = split(a:path, ".go$")[0] + let l:file = l:root . "_test.go" + else + let l:root = split(a:path, "_test.go$")[0] + let l:file = l:root . ".go" + endif + return l:file +endfunction diff --git a/bundle/pristine/vim-go/autoload/go/asmfmt.vim b/bundle/pristine/vim-go/autoload/go/asmfmt.vim new file mode 100644 index 0000000..0b42794 --- /dev/null +++ b/bundle/pristine/vim-go/autoload/go/asmfmt.vim @@ -0,0 +1,52 @@ +" asmfmt.vim: Vim command to format Go asm files with asmfmt +" (github.com/klauspost/asmfmt). +" +" This filetype plugin adds new commands for asm buffers: +" +" :Fmt +" +" Filter the current asm buffer through asmfmt. +" It tries to preserve cursor position and avoids +" replacing the buffer with stderr output. +" +" Options: +" +" g:go_asmfmt_autosave [default=1] +" +" Flag to automatically call :Fmt when file is saved. + +let s:got_fmt_error = 0 + +" This is a trimmed-down version of the logic in fmt.vim. + +function! go#asmfmt#Format() + " Save state. + let l:curw = winsaveview() + + " Write the current buffer to a tempfile. + let l:tmpname = tempname() + call writefile(getline(1, '$'), l:tmpname) + + " Run asmfmt. + let path = go#path#CheckBinPath("asmfmt") + if empty(path) + return + endif + let out = system(path . ' -w ' . l:tmpname) + + " If there's no error, replace the current file with the output. + if v:shell_error == 0 + " Remove undo point caused by BufWritePre. + try | silent undojoin | catch | endtry + + " Replace the current file with the temp file; then reload the buffer. + let old_fileformat = &fileformat + call rename(l:tmpname, expand('%')) + silent edit! + let &fileformat = old_fileformat + let &syntax = &syntax + endif + + " Restore the cursor/window positions. + call winrestview(l:curw) +endfunction diff --git a/bundle/pristine/vim-go/autoload/go/cmd.vim b/bundle/pristine/vim-go/autoload/go/cmd.vim index a42bbef..c90a053 100644 --- a/bundle/pristine/vim-go/autoload/go/cmd.vim +++ b/bundle/pristine/vim-go/autoload/go/cmd.vim @@ -8,52 +8,91 @@ function! go#cmd#autowrite() endif endfunction -" Build buils the source code without producting any output binary. We live in + +" Build builds 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 + " expand all wildcards(i.e: '%' to the current file name) + let goargs = map(copy(a:000), "expand(v:val)") - let old_gopath = $GOPATH - let $GOPATH = go#path#Detect() + " escape all shell arguments before we pass it to make + let goargs = go#util#Shelllist(goargs, 1) - if v:shell_error - let &makeprg = "go build . errors" - else - " :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 /dev/null " . goargs . ' ' . gofiles - endif + " create our command arguments. go build discards any results when it + " compiles multiple packages. So we pass the `errors` package just as an + " placeholder with the current folder (indicated with '.') + let args = ["build"] + goargs + [".", "errors"] - echon "vim-go: " | echohl Identifier | echon "building ..."| echohl None - if g:go_dispatch_enabled && exists(':Make') == 2 - silent! exe 'Make' - else - silent! exe 'make!' + " if we have nvim, call it asynchronously and return early ;) + if has('nvim') + call go#util#EchoProgress("building dispatched ...") + call go#jobcontrol#Spawn(a:bang, "build", args) + return endif - redraw! - cwindow - let errors = getqflist() - if !empty(errors) + let old_gopath = $GOPATH + let $GOPATH = go#path#Detect() + let default_makeprg = &makeprg + let &makeprg = "go " . join(args, ' ') + + let l:listtype = go#list#Type("quickfix") + " execute make inside the source folder so we can parse the errors + " correctly + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' + let dir = getcwd() + try + execute cd . fnameescape(expand("%:p:h")) + if g:go_dispatch_enabled && exists(':Make') == 2 + call go#util#EchoProgress("building dispatched ...") + silent! exe 'Make' + elseif l:listtype == "locationlist" + silent! exe 'lmake!' + else + silent! exe 'make!' + endif + redraw! + finally + execute cd . fnameescape(dir) + endtry + + let errors = go#list#Get(l:listtype) + call go#list#Window(l:listtype, len(errors)) + + if !empty(errors) if !a:bang - cc 1 "jump to first error if there is any + call go#list#JumpToFirst(l:listtype) endif else - redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None + call go#util#EchoSuccess("[build] SUCCESS") endif let &makeprg = default_makeprg let $GOPATH = old_gopath endfunction + +" Run runs the current file (and their dependencies if any) in a new terminal. +function! go#cmd#RunTerm(bang, mode, files) + if empty(a:files) + let cmd = "go run ". go#util#Shelljoin(go#tool#Files()) + else + let cmd = "go run ". go#util#Shelljoin(map(copy(a:files), "expand(v:val)"), 1) + endif + call go#term#newmode(a:bang, cmd, a:mode) +endfunction + " Run runs the current file (and their dependencies if any) and outputs it. " This is intented to test small programs and play with them. It's not " 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, ...) + if has('nvim') + call go#cmd#RunTerm(a:bang, '', a:000) + return + endif + let old_gopath = $GOPATH let $GOPATH = go#path#Detect() @@ -77,16 +116,23 @@ function! go#cmd#Run(bang, ...) let &makeprg = "go run " . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1) endif + let l:listtype = go#list#Type("quickfix") + if g:go_dispatch_enabled && exists(':Make') == 2 silent! exe 'Make' + elseif l:listtype == "locationlist" + exe 'lmake!' else exe 'make!' endif - cwindow - let errors = getqflist() + let items = go#list#Get(l:listtype) + let errors = go#tool#FilterValids(items) + + call go#list#Populate(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) if !empty(errors) && !a:bang - cc 1 "jump to first error if there is any + call go#list#JumpToFirst(l:listtype) endif let $GOPATH = old_gopath @@ -94,61 +140,118 @@ 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 install') it tries to install those +" packages. Errors are populated in the location window. function! go#cmd#Install(bang, ...) - 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() - if !empty(errors) && !a:bang - cc 1 "jump to first error if there is any + let default_makeprg = &makeprg + + " :make expands '%' and '#' wildcards, so they must also be escaped + let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1) + let &makeprg = "go install " . goargs + + let l:listtype = go#list#Type("quickfix") + " execute make inside the source folder so we can parse the errors + " correctly + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' + let dir = getcwd() + try + execute cd . fnameescape(expand("%:p:h")) + if g:go_dispatch_enabled && exists(':Make') == 2 + call go#util#EchoProgress("building dispatched ...") + silent! exe 'Make' + elseif l:listtype == "locationlist" + silent! exe 'lmake!' + else + silent! exe 'make!' endif - return + redraw! + finally + execute cd . fnameescape(dir) + endtry + + let errors = go#list#Get(l:listtype) + call go#list#Window(l:listtype, len(errors)) + if !empty(errors) + if !a:bang + call go#list#JumpToFirst(l:listtype) + endif + else + redraws! | echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None endif - echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None + let &makeprg = default_makeprg endfunction " Test runs `go test` in the current directory. If compile is true, it'll " compile the tests instead of running them (useful to catch errors in the " test files). Any other argument is appendend to the final `go test` command function! go#cmd#Test(bang, compile, ...) - let command = "go test " + let args = ["test"] " 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 " + call add(args, "-c") endif if a:0 - let command .= go#util#Shelljoin(map(copy(a:000), "expand(v:val)")) + " expand all wildcards(i.e: '%' to the current file name) + let goargs = map(copy(a:000), "expand(v:val)") + + call extend(args, goargs, 1) + else + " only add this if no custom flags are passed + let timeout = get(g:, 'go_test_timeout', '10s') + call add(args, printf("-timeout=%s", timeout)) endif - call go#cmd#autowrite() if a:compile echon "vim-go: " | echohl Identifier | echon "compiling tests ..." | echohl None else echon "vim-go: " | echohl Identifier | echon "testing ..." | echohl None endif + if has('nvim') + if get(g:, 'go_term_enabled', 0) + call go#term#new(a:bang, ["go"] + args) + else + call go#jobcontrol#Spawn(a:bang, "test", args) + endif + return + endif + + call go#cmd#autowrite() redraw + + let command = "go " . join(args, ' ') + let out = go#tool#ExecuteInDir(command) + + let l:listtype = "quickfix" + if v:shell_error - call go#tool#ShowErrors(out) - cwindow - let errors = getqflist() + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' + let dir = getcwd() + try + execute cd fnameescape(expand("%:p:h")) + let errors = go#tool#ParseErrors(split(out, '\n')) + let errors = go#tool#FilterValids(errors) + finally + execute cd . fnameescape(dir) + endtry + + call go#list#Populate(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) if !empty(errors) && !a:bang - cc 1 "jump to first error if there is any + call go#list#JumpToFirst(l:listtype) + elseif empty(errors) + " failed to parse errors, output the original content + call go#util#EchoError(out) endif echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None else - call setqflist([]) - cwindow + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) if a:compile echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None @@ -194,51 +297,29 @@ function! go#cmd#Coverage(bang, ...) let command = "go test -coverprofile=" . l:tmpname . ' ' . go#util#Shelljoin(a:000) + + let l:listtype = "quickfix" 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(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) + if !empty(errors) && !a:bang + call go#list#JumpToFirst(l:listtype) + endif else - " clear previous quick fix window - call setqflist([]) + " clear previous location list + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) 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 - 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 - 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 @@ -255,19 +336,23 @@ function! go#cmd#Generate(bang, ...) let &makeprg = "go generate " . goargs . ' ' . gofiles endif + let l:listtype = go#list#Type("quickfix") + echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None if g:go_dispatch_enabled && exists(':Make') == 2 silent! exe 'Make' + elseif l:listtype == "locationlist" + silent! exe 'lmake!' else silent! exe 'make!' endif redraw! - cwindow - let errors = getqflist() + let errors = go#list#Get(l:listtype) + call go#list#Window(l:listtype, len(errors)) if !empty(errors) if !a:bang - cc 1 "jump to first error if there is any + call go#list#JumpToFirst(l:listtype) endif else redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None @@ -278,4 +363,3 @@ function! go#cmd#Generate(bang, ...) endfunction " vim:ts=4:sw=4:et -" diff --git a/bundle/pristine/vim-go/autoload/go/complete.vim b/bundle/pristine/vim-go/autoload/go/complete.vim index a0f9da7..d295257 100644 --- a/bundle/pristine/vim-go/autoload/go/complete.vim +++ b/bundle/pristine/vim-go/autoload/go/complete.vim @@ -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' @@ -79,7 +87,7 @@ fu! s:gocodeCurrentBufferOpt(filename) return '-in=' . a:filename endf -fu! s:gocodeCursor() +fu! go#complete#gocodeCursor() if &encoding != 'utf-8' let sep = &l:fileformat == 'dos' ? "\r\n" : "\n" let c = col('.') @@ -87,6 +95,7 @@ fu! s:gocodeCursor() let buf .= c == 1 ? "" : getline('.')[:c-2] return printf('%d', len(iconv(buf, &encoding, "utf-8"))) endif + return printf('%d', line2byte(line('.')) + (col('.')-2)) endf @@ -94,16 +103,16 @@ fu! s:gocodeAutocomplete() let filename = s:gocodeCurrentBuffer() let result = s:gocodeCommand('autocomplete', \ [s:gocodeCurrentBufferOpt(filename), '-f=vim'], - \ [expand('%:p'), s:gocodeCursor()]) + \ [expand('%:p'), go#complete#gocodeCursor()]) call delete(filename) return result endf -function! go#complete#GetInfo() +function! go#complete#GetInfoFromOffset(offset) let filename = s:gocodeCurrentBuffer() let result = s:gocodeCommand('autocomplete', \ [s:gocodeCurrentBufferOpt(filename), '-f=godit'], - \ [expand('%:p'), s:gocodeCursor()]) + \ [expand('%:p'), a:offset]) call delete(filename) " first line is: Charcount,,NumberOfCandidates, i.e: 8,,1 @@ -139,6 +148,11 @@ function! go#complete#GetInfo() return "" endfunction +function! go#complete#GetInfo() + let offset = go#complete#gocodeCursor() + return go#complete#GetInfoFromOffset(offset) +endfunction + function! go#complete#Info() let result = go#complete#GetInfo() if !empty(result) diff --git a/bundle/pristine/vim-go/autoload/go/def.vim b/bundle/pristine/vim-go/autoload/go/def.vim index 6b1c716..ae9bf11 100644 --- a/bundle/pristine/vim-go/autoload/go/def.vim +++ b/bundle/pristine/vim-go/autoload/go/def.vim @@ -2,6 +2,15 @@ if !exists("g:go_godef_bin") let g:go_godef_bin = "godef" endif +if go#vimproc#has_vimproc() + let s:vim_system = get(g:, 'gocomplete#system_function', 'vimproc#system2') +else + let s:vim_system = get(g:, 'gocomplete#system_function', 'system') +endif + +fu! s:system(str, ...) + return call(s:vim_system, [a:str] + a:000) +endf " modified and improved version of vim-godef function! go#def#Jump(...) @@ -21,10 +30,11 @@ function! go#def#Jump(...) let old_gopath = $GOPATH let $GOPATH = go#path#Detect() - let command = bin_path . " -f=" . shellescape(expand("%:p")) . " -i " . shellescape(arg) + let fname = fnamemodify(expand("%"), ':p:gs?\\?/?') + let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg) " get output of godef - let out=system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding())) + let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding())) " jump to it call s:godefJump(out, "") @@ -43,10 +53,11 @@ function! go#def#JumpMode(mode) let old_gopath = $GOPATH let $GOPATH = go#path#Detect() - let command = bin_path . " -f=" . shellescape(expand("%:p")) . " -i " . shellescape(arg) + let fname = fnamemodify(expand("%"), ':p:gs?\\?/?') + let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg) " get output of godef - let out=system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding())) + let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding())) call s:godefJump(out, a:mode) let $GOPATH = old_gopath @@ -74,7 +85,7 @@ function! s:godefJump(out, mode) let &errorformat = "%f:%l:%c" if a:out =~ 'godef: ' - let out=substitute(a:out, go#util#LineEnding() . '$', '', '') + let out = substitute(a:out, go#util#LineEnding() . '$', '', '') echom out else let parts = split(a:out, ':') diff --git a/bundle/pristine/vim-go/autoload/go/errcheck.vim b/bundle/pristine/vim-go/autoload/go/errcheck.vim deleted file mode 100644 index a87fe1f..0000000 --- a/bundle/pristine/vim-go/autoload/go/errcheck.vim +++ /dev/null @@ -1,58 +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 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 - endif - - if !empty(errors) - redraw | echo - call setqflist(errors, 'r') - endif - else - redraw | echo - call setqflist([]) - echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None - endif - - cwindow -endfunction - -" vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/autoload/go/fmt.vim b/bundle/pristine/vim-go/autoload/go/fmt.vim index b09e7d7..56c6ee7 100644 --- a/bundle/pristine/vim-go/autoload/go/fmt.vim +++ b/bundle/pristine/vim-go/autoload/go/fmt.vim @@ -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 @@ -54,8 +52,25 @@ let s:got_fmt_error = 0 " this and have VimL experience, please look at the function for " improvements, patches are welcome :) function! go#fmt#Format(withGoimport) - " save cursor position and many other things - let l:curw=winsaveview() + if g:go_fmt_experimental == 1 + " Using winsaveview to save/restore cursor state has the problem of + " closing folds on save: + " https://github.com/fatih/vim-go/issues/502 + " One fix is to use mkview instead. Unfortunately, this sometimes causes + " other bad side effects: + " https://github.com/fatih/vim-go/issues/728 + " and still closes all folds if foldlevel>0: + " https://github.com/fatih/vim-go/issues/732 + let l:curw = {} + try + mkview! + catch + let l:curw=winsaveview() + endtry + else + " Save cursor position and many other things. + let l:curw=winsaveview() + endif " Write current unsaved buffer to a temp file let l:tmpname = tempname() @@ -76,16 +91,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() @@ -94,7 +108,28 @@ function! go#fmt#Format(withGoimport) endif " populate the final command with user based fmt options - let command = fmt_command . ' -w ' . g:go_fmt_options + let command = fmt_command . ' -w ' + if a:withGoimport != 1 + let command = command . g:go_fmt_options + endif + + if fmt_command == "goimports" + if !exists('b:goimports_vendor_compatible') + let out = system("goimports --help") + if out !~ "-srcdir" + echohl WarningMsg + echomsg "vim-go: goimports does not support srcdir." + echomsg " update with: :GoUpdateBinaries" + echohl None + else + let b:goimports_vendor_compatible = 1 + endif + endif + + if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible + let command = command . '-srcdir ' . fnameescape(expand("%:p:h")) + endif + endif " execute our command... let out = system(command . " " . l:tmpname) @@ -103,7 +138,7 @@ function! go#fmt#Format(withGoimport) let $GOPATH = old_gopath endif - + let l:listtype = "locationlist" "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\+') @@ -112,20 +147,21 @@ function! go#fmt#Format(withGoimport) try | silent undojoin | catch | endtry " 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 - " 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 + " clean up previous location list, but only if it's due to fmt + if exists('b:got_fmt_error') && b:got_fmt_error + let b:got_fmt_error = 0 + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) endif - elseif g:go_fmt_fail_silently == 0 + elseif g:go_fmt_fail_silently == 0 let splitted = split(out, '\n') - "otherwise get the errors and put them to quickfix window + "otherwise get the errors and put them to location list let errors = [] for line in splitted let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)') @@ -140,11 +176,13 @@ 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(l:listtype, errors) echohl Error | echomsg "Gofmt returned error" | echohl None endif - let s:got_fmt_error = 1 - cwindow + + let b:got_fmt_error = 1 + call go#list#Window(l:listtype, len(errors)) + " We didn't use the temp file, so clean up call delete(l:tmpname) endif @@ -155,8 +193,17 @@ function! go#fmt#Format(withGoimport) call delete(tmpundofile) endif - " restore our cursor/windows positions - call winrestview(l:curw) + if g:go_fmt_experimental == 1 + " Restore our cursor/windows positions, folds, etc. + if empty(l:curw) + silent! loadview + else + call winrestview(l:curw) + endif + else + " Restore our cursor/windows positions. + call winrestview(l:curw) + endif endfunction diff --git a/bundle/pristine/vim-go/autoload/go/import.vim b/bundle/pristine/vim-go/autoload/go/import.vim index a46aa4f..766a4af 100644 --- a/bundle/pristine/vim-go/autoload/go/import.vim +++ b/bundle/pristine/vim-go/autoload/go/import.vim @@ -6,7 +6,7 @@ " 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] == '"' diff --git a/bundle/pristine/vim-go/autoload/go/jobcontrol.vim b/bundle/pristine/vim-go/autoload/go/jobcontrol.vim new file mode 100644 index 0000000..777b054 --- /dev/null +++ b/bundle/pristine/vim-go/autoload/go/jobcontrol.vim @@ -0,0 +1,179 @@ +" s:jobs is a global reference to all jobs started with Spawn() or with the +" internal function s:spawn +let s:jobs = {} + +" Spawn is a wrapper around s:spawn. It can be executed by other files and +" scripts if needed. Desc defines the description for printing the status +" during the job execution (useful for statusline integration). +function! go#jobcontrol#Spawn(bang, desc, args) + " autowrite is not enabled for jobs + call go#cmd#autowrite() + + let job = s:spawn(a:bang, a:desc, a:args) + return job.id +endfunction + +" Statusline returns the current status of the job +function! go#jobcontrol#Statusline() abort + if empty(s:jobs) + return '' + endif + + let import_path = go#package#ImportPath(expand('%:p:h')) + + for job in values(s:jobs) + if job.importpath != import_path + continue + endif + + if job.state == "SUCCESS" + return '' + endif + + return printf("%s ... [%s]", job.desc, job.state) + endfor + + return '' +endfunction + +" spawn spawns a go subcommand with the name and arguments with jobstart. Once +" a job is started a reference will be stored inside s:jobs. spawn changes the +" GOPATH when g:go_autodetect_gopath is enabled. The job is started inside the +" current files folder. +function! s:spawn(bang, desc, args) + let job = { + \ 'desc': a:desc, + \ 'bang': a:bang, + \ 'winnr': winnr(), + \ 'importpath': go#package#ImportPath(expand('%:p:h')), + \ 'state': "RUNNING", + \ 'stderr' : [], + \ 'stdout' : [], + \ 'on_stdout': function('s:on_stdout'), + \ 'on_stderr': function('s:on_stderr'), + \ 'on_exit' : function('s:on_exit'), + \ } + + " modify GOPATH if needed + let old_gopath = $GOPATH + let $GOPATH = go#path#Detect() + + " execute go build in the files directory + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' + + " cleanup previous jobs for this file + for jb in values(s:jobs) + if jb.importpath == job.importpath + unlet s:jobs[jb.id] + endif + endfor + + let dir = getcwd() + let jobdir = fnameescape(expand("%:p:h")) + execute cd . jobdir + + " append the subcommand, such as 'build' + let argv = ['go'] + a:args + + " run, forrest, run! + let id = jobstart(argv, job) + let job.id = id + let job.dir = jobdir + let s:jobs[id] = job + + execute cd . fnameescape(dir) + + " restore back GOPATH + let $GOPATH = old_gopath + + return job +endfunction + +" on_exit is the exit handler for jobstart(). It handles cleaning up the job +" references and also displaying errors in the quickfix window collected by +" on_stderr handler. If there are no errors and a quickfix window is open, +" it'll be closed. +function! s:on_exit(job_id, exit_status) + let std_combined = self.stderr + self.stdout + if a:exit_status == 0 + call go#list#Clean(0) + call go#list#Window(0) + + let self.state = "SUCCESS" + call go#util#EchoSuccess("SUCCESS") + return + endif + + let self.state = "FAILED" + call go#util#EchoError("FAILED") + + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' + let dir = getcwd() + try + execute cd self.dir + let errors = go#tool#ParseErrors(std_combined) + let errors = go#tool#FilterValids(errors) + finally + execute cd . fnameescape(dir) + endtry + + if !len(errors) + " failed to parse errors, output the original content + call go#util#EchoError(std_combined[0]) + return + endif + + " if we are still in the same windows show the list + if self.winnr == winnr() + let l:listtype = "locationlist" + call go#list#Populate(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) + if !empty(errors) && !self.bang + call go#list#JumpToFirst(l:listtype) + endif + endif +endfunction + +" on_stdout is the stdout handler for jobstart(). It collects the output of +" stderr and stores them to the jobs internal stdout list. +function! s:on_stdout(job_id, data) + call extend(self.stdout, a:data) +endfunction + +" on_stderr is the stderr handler for jobstart(). It collects the output of +" stderr and stores them to the jobs internal stderr list. +function! s:on_stderr(job_id, data) + call extend(self.stderr, a:data) +endfunction + +" abort_all aborts all current jobs created with s:spawn() +function! s:abort_all() + if empty(s:jobs) + return + endif + + for id in keys(s:jobs) + if id > 0 + silent! call jobstop(id) + endif + endfor + + let s:jobs = {} +endfunction + +" abort aborts the job with the given name, where name is the first argument +" passed to s:spawn() +function! s:abort(path) + if empty(s:jobs) + return + endif + + for job in values(s:jobs) + if job.importpath == path && job.id > 0 + silent! call jobstop(job.id) + unlet s:jobs['job.id'] + endif + endfor +endfunction + +" vim:ts=2:sw=2:et diff --git a/bundle/pristine/vim-go/autoload/go/lint.vim b/bundle/pristine/vim-go/autoload/go/lint.vim index a7bd454..91247ad 100644 --- a/bundle/pristine/vim-go/autoload/go/lint.vim +++ b/bundle/pristine/vim-go/autoload/go/lint.vim @@ -1,22 +1,96 @@ -" 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 [options] -" -" 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) + + let l:listtype = "quickfix" + if v:shell_error == 0 + redraw | echo + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) + echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None + else + " GoMetaLinter can output one of the two, so we look for both: + " ::[]: () + " ::: () + " 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(l:listtype, errformat, split(out, "\n")) + + let errors = go#list#Get(l:listtype) + call go#list#Window(l:listtype, len(errors)) + + if !a:autosave + call go#list#JumpToFirst(l:listtype) + 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 @@ -27,9 +101,99 @@ function! go#lint#Run(...) abort else let goargs = go#util#Shelljoin(a:000) endif - silent cexpr system(bin_path . " " . goargs) - cwindow + + let out = system(bin_path . " " . goargs) + if empty(out) + echon "vim-go: " | echohl Function | echon "[lint] PASS" | echohl None + return + endif + + let l:listtype = "quickfix" + call go#list#Parse(l:listtype, out) + let errors = go#list#Get(l:listtype) + call go#list#Window(l:listtype, len(errors)) + call go#list#JumpToFirst(l:listtype) 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 + + let l:listtype = "quickfix" + if v:shell_error + let errors = go#tool#ParseErrors(split(out, '\n')) + call go#list#Populate(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) + if !empty(errors) && !a:bang + call go#list#JumpToFirst(l:listtype) + endif + echon "vim-go: " | echohl ErrorMsg | echon "[vet] FAIL" | echohl None + else + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) + 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 . ' -abspath ' . goargs + let out = go#tool#ExecuteInDir(command) + + let l:listtype = "quickfix" + if v:shell_error + let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m" + + " Parse and populate our location list + call go#list#ParseFormat(l:listtype, errformat, split(out, "\n")) + + let errors = go#list#Get(l:listtype) + + if empty(errors) + echohl Error | echomsg "GoErrCheck returned error" | echohl None + echo out + return + endif + + if !empty(errors) + call go#list#Populate(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) + if !empty(errors) + call go#list#JumpToFirst(l:listtype) + endif + endif + else + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) + echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None + endif + +endfunction " vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/autoload/go/list.vim b/bundle/pristine/vim-go/autoload/go/list.vim new file mode 100644 index 0000000..d91cfb1 --- /dev/null +++ b/bundle/pristine/vim-go/autoload/go/list.vim @@ -0,0 +1,126 @@ +if !exists("g:go_list_type") + let g:go_list_type = "" +endif + +" Window opens the 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(listtype, ...) + let l:listtype = go#list#Type(a:listtype) + " 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 lclose + " 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 + if l:listtype == "locationlist" + lclose + else + cclose + endif + return + endif + + let height = get(g:, "go_list_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 + + if l:listtype == "locationlist" + exe 'lopen ' . height + else + exe 'copen ' . height + endif +endfunction + + +" Get returns the current list of items from the location list +function! go#list#Get(listtype) + let l:listtype = go#list#Type(a:listtype) + if l:listtype == "locationlist" + return getloclist(0) + else + return getqflist() + endif +endfunction + +" Populate populate the location list with the given items +function! go#list#Populate(listtype, items) + let l:listtype = go#list#Type(a:listtype) + if l:listtype == "locationlist" + call setloclist(0, a:items, 'r') + else + call setqflist(a:items, 'r') + endif +endfunction + +function! go#list#PopulateWin(winnr, items) + call setloclist(a:winnr, a:items, 'r') +endfunction + +" Parse parses the given items based on the specified errorformat nad +" populates the location list. +function! go#list#ParseFormat(listtype, errformat, items) + let l:listtype = go#list#Type(a:listtype) + " backup users errorformat, will be restored once we are finished + let old_errorformat = &errorformat + + " parse and populate the location list + let &errorformat = a:errformat + if l:listtype == "locationlist" + lgetexpr a:items + else + cgetexpr a:items + endif + + "restore back + let &errorformat = old_errorformat +endfunction + +" Parse parses the given items based on the global errorformat and +" populates the location list. +function! go#list#Parse(listtype, items) + let l:listtype = go#list#Type(a:listtype) + if l:listtype == "locationlist" + lgetexpr a:items + else + cgetexpr a:items + endif +endfunction + +" JumpToFirst jumps to the first item in the location list +function! go#list#JumpToFirst(listtype) + let l:listtype = go#list#Type(a:listtype) + if l:listtype == "locationlist" + ll 1 + else + cc 1 + endif +endfunction + +" Clean cleans the location list +function! go#list#Clean(listtype) + let l:listtype = go#list#Type(a:listtype) + if l:listtype == "locationlist" + lex [] + else + cex [] + endif +endfunction + +function! go#list#Type(listtype) + if g:go_list_type == "locationlist" + return "locationlist" + elseif g:go_list_type == "quickfix" + return "quickfix" + else + return a:listtype + endif +endfunction + +" vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/autoload/go/oracle.vim b/bundle/pristine/vim-go/autoload/go/oracle.vim index cd75473..9b2ec1c 100644 --- a/bundle/pristine/vim-go/autoload/go/oracle.vim +++ b/bundle/pristine/vim-go/autoload/go/oracle.vim @@ -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("locationlist", llist) + call go#list#Window("locationlist", 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("locationlist", 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("locationlist") + call go#list#Window("locationlist", len(errors)) endfun func! s:getpos(l, c) @@ -96,18 +94,24 @@ func! s:RunOracle(mode, selected, needs_package) range abort if empty(bin_path) return endif + + if exists('g:go_oracle_tags') + let tags = get(g:, 'go_oracle_tags') + else + let tags = "" + endif if a:selected != -1 let pos1 = s:getpos(line("'<"), col("'<")) let pos2 = s:getpos(line("'>"), col("'>")) - let cmd = printf('%s -format plain -pos=%s:#%d,#%d %s', + let cmd = printf('%s -format plain -pos=%s:#%d,#%d -tags=%s %s', \ bin_path, - \ shellescape(fname), pos1, pos2, a:mode) + \ shellescape(fname), pos1, pos2, tags, a:mode) else let pos = s:getpos(line('.'), col('.')) - let cmd = printf('%s -format plain -pos=%s:#%d %s', + let cmd = printf('%s -format plain -pos=%s:#%d -tags=%s %s', \ bin_path, - \ shellescape(fname), pos, a:mode) + \ shellescape(fname), pos, tags, a:mode) endif " now append each scope to the end as Oracle's scope parameter. It can be @@ -156,34 +160,54 @@ function! go#oracle#Scope(...) endif endfunction +function! go#oracle#Tags(...) + if a:0 + if a:0 == 1 && a:1 == '""' + unlet g:go_oracle_tags + echon "vim-go: " | echohl Function | echon "oracle tags is cleared"| echohl None + else + let g:go_oracle_tags = a:1 + echon "vim-go: " | echohl Function | echon "oracle tags changed to: '". g:go_oracle_tags ."'" | echohl None + endif + + return + endif + + if !exists('g:go_oracle_tags') + echon "vim-go: " | echohl Function | echon "oracle tags is not set"| echohl None + else + echon "vim-go: " | echohl Function | echon "current oracle tags: '". g:go_oracle_tags ."'" | echohl None + endif +endfunction + " Show 'implements' relation for selected package function! go#oracle#Implements(selected) let out = s:RunOracle('implements', a:selected, 0) - call s:qflistSecond(out) + call s:loclistSecond(out) endfunction " Describe selected syntax: definition, methods, etc function! go#oracle#Describe(selected) let out = s:RunOracle('describe', a:selected, 0) - call s:qflistSecond(out) + call s:loclistSecond(out) endfunction " Show possible targets of selected function call function! go#oracle#Callees(selected) let out = s:RunOracle('callees', a:selected, 1) - call s:qflistSecond(out) + call s:loclistSecond(out) endfunction " Show possible callers of selected function function! go#oracle#Callers(selected) let out = s:RunOracle('callers', a:selected, 1) - call s:qflistSecond(out) + 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, 1) - call s:qflistSecond(out) + call s:loclistSecond(out) endfunction " Show free variables of selection @@ -195,19 +219,19 @@ function! go#oracle#Freevars(selected) endif let out = s:RunOracle('freevars', a:selected, 0) - call s:qflistSecond(out) + 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, 1) - call s:qflistSecond(out) + 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, 0) - call s:qflistSecond(out) + call s:loclistSecond(out) endfunction " vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/autoload/go/package.vim b/bundle/pristine/vim-go/autoload/go/package.vim index 764c096..32b38ae 100644 --- a/bundle/pristine/vim-go/autoload/go/package.vim +++ b/bundle/pristine/vim-go/autoload/go/package.vim @@ -31,17 +31,19 @@ endif function! go#package#Paths() let dirs = [] - if executable('go') - let goroot = substitute(system('go env GOROOT'), '\n', '', 'g') - if v:shell_error - echomsg '''go env GOROOT'' failed' + if !exists("s:goroot") + if executable('go') + let s:goroot = substitute(system('go env GOROOT'), '\n', '', 'g') + if v:shell_error + echomsg '''go env GOROOT'' failed' + endif + else + let s:goroot = $GOROOT endif - else - let goroot = $GOROOT endif - if len(goroot) != 0 && isdirectory(goroot) - let dirs += [goroot] + if len(s:goroot) != 0 && isdirectory(s:goroot) + let dirs += [s:goroot] endif let workspaces = split($GOPATH, go#util#PathListSep()) @@ -66,7 +68,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) diff --git a/bundle/pristine/vim-go/autoload/go/path.vim b/bundle/pristine/vim-go/autoload/go/path.vim index 3c17252..7b4b768 100644 --- a/bundle/pristine/vim-go/autoload/go/path.vim +++ b/bundle/pristine/vim-go/autoload/go/path.vim @@ -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 @@ -91,7 +91,7 @@ function! go#path#Detect() " gb vendor plugin " (https://github.com/constabulary/gb/tree/master/cmd/gb-vendor) let gb_vendor_root = src_path . "vendor" . go#util#PathSep() - if !empty(gb_vendor_root) && !go#path#HasPath(gb_vendor_root) + if isdirectory(gb_vendor_root) && !go#path#HasPath(gb_vendor_root) let gopath = gb_vendor_root . go#util#PathListSep() . gopath endif diff --git a/bundle/pristine/vim-go/autoload/go/rename.vim b/bundle/pristine/vim-go/autoload/go/rename.vim index ef91463..f5afef6 100644 --- a/bundle/pristine/vim-go/autoload/go/rename.vim +++ b/bundle/pristine/vim-go/autoload/go/rename.vim @@ -2,22 +2,32 @@ if !exists("g:go_gorename_bin") let g:go_gorename_bin = "gorename" endif -function! go#rename#Rename(...) +if !exists("g:go_gorename_prefill") + let g:go_gorename_prefill = 1 +endif + +function! go#rename#Rename(bang, ...) let to = "" if a:0 == 0 let from = expand("") let ask = printf("vim-go: rename '%s' to: ", from) - let to = input(ask, from) - redraw + if g:go_gorename_prefill + let to = input(ask, from) + else + let to = input(ask) + endif + redraw! + if empty(to) + return + endif else 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) - return + let bin_path = go#path#CheckBinPath(g:go_gorename_bin) + if empty(bin_path) + return endif let fname = expand('%:p') @@ -30,13 +40,28 @@ function! go#rename#Rename(...) " will trigger the 'Hit ENTER to continue' prompt let clean = split(out, '\n') + let l:listtype = "quickfix" 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(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) + if !empty(errors) && !a:bang + call go#list#JumpToFirst(l:listtype) + elseif empty(errors) + " failed to parse errors, output the original content + call go#util#EchoError(out) + endif + return else + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) 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 diff --git a/bundle/pristine/vim-go/autoload/go/term.vim b/bundle/pristine/vim-go/autoload/go/term.vim new file mode 100644 index 0000000..693041e --- /dev/null +++ b/bundle/pristine/vim-go/autoload/go/term.vim @@ -0,0 +1,128 @@ +if has('nvim') && !exists("g:go_term_mode") + let g:go_term_mode = 'vsplit' +endif + +" s:jobs is a global reference to all jobs started with new() +let s:jobs = {} + +" new creates a new terminal with the given command. Mode is set based on the +" global variable g:go_term_mode, which is by default set to :vsplit +function! go#term#new(bang, cmd) + return go#term#newmode(a:bang, a:cmd, g:go_term_mode) +endfunction + +" new creates a new terminal with the given command and window mode. +function! go#term#newmode(bang, cmd, mode) + let mode = a:mode + if empty(mode) + let mode = g:go_term_mode + endif + + " modify GOPATH if needed + let old_gopath = $GOPATH + let $GOPATH = go#path#Detect() + + " execute go build in the files directory + let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' + let dir = getcwd() + + execute cd . fnameescape(expand("%:p:h")) + + execute mode.' __go_term__' + + setlocal filetype=goterm + setlocal bufhidden=delete + setlocal winfixheight + setlocal noswapfile + setlocal nobuflisted + + let job = { + \ 'stderr' : [], + \ 'stdout' : [], + \ 'bang' : a:bang, + \ 'on_stdout': function('s:on_stdout'), + \ 'on_stderr': function('s:on_stderr'), + \ 'on_exit' : function('s:on_exit'), + \ } + + let id = termopen(a:cmd, job) + + execute cd . fnameescape(dir) + + " restore back GOPATH + let $GOPATH = old_gopath + + let job.id = id + startinsert + + " resize new term if needed. + let height = get(g:, 'go_term_height', winheight(0)) + let width = get(g:, 'go_term_width', winwidth(0)) + + " we are careful how to resize. for example it's vertical we don't change + " the height. The below command resizes the buffer + if a:mode == "split" + exe 'resize ' . height + elseif a:mode == "vertical" + exe 'vertical resize ' . width + endif + + " we also need to resize the pty, so there you go... + call jobresize(id, width, height) + + let s:jobs[id] = job + return id +endfunction + +function! s:on_stdout(job_id, data) + if !has_key(s:jobs, a:job_id) + return + endif + let job = s:jobs[a:job_id] + + call extend(job.stdout, a:data) +endfunction + +function! s:on_stderr(job_id, data) + if !has_key(s:jobs, a:job_id) + return + endif + let job = s:jobs[a:job_id] + + call extend(job.stderr, a:data) +endfunction + +function! s:on_exit(job_id, data) + if !has_key(s:jobs, a:job_id) + return + endif + let job = s:jobs[a:job_id] + + let l:listtype = "locationlist" + " usually there is always output so never branch into this clause + if empty(job.stdout) + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) + else + let errors = go#tool#ParseErrors(job.stdout) + let errors = go#tool#FilterValids(errors) + if !empty(errors) + " close terminal we don't need it + close + + call go#list#Populate(l:listtype, errors) + call go#list#Window(l:listtype, len(errors)) + if !self.bang + call go#list#JumpToFirst(l:listtype) + endif + else + call go#list#Clean(l:listtype) + call go#list#Window(l:listtype) + endif + + endif + + unlet s:jobs[a:job_id] +endfunction + +" vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/autoload/go/tool.vim b/bundle/pristine/vim-go/autoload/go/tool.vim index 64bc026..d378b5a 100644 --- a/bundle/pristine/vim-go/autoload/go/tool.vim +++ b/bundle/pristine/vim-go/autoload/go/tool.vim @@ -40,28 +40,24 @@ 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*\(.*\)') if !empty(fatalerrors) call add(errors, {"text": fatalerrors[1]}) elseif !empty(tokens) - call add(errors, {"filename" : fnamemodify(tokens[1], ':p'), - \"lnum": tokens[2], - \"text": tokens[3]}) + " strip endlines of form ^M + let out=substitute(tokens[3], '\r$', '', '') + + call add(errors, { + \ "filename" : fnamemodify(tokens[1], ':p'), + \ "lnum" : tokens[2], + \ "text" : out, + \ }) elseif !empty(errors) " Preserve indented lines. " This comes up especially with multi-line test output. @@ -71,18 +67,43 @@ 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) + return errors +endfunction - if !empty(errors) - call setqflist(errors, 'r') - return - endif +"FilterValids filters the given items with only items that have a valid +"filename. Any non valid filename is filtered out. +function! go#tool#FilterValids(items) + " 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 filtered = [] + let is_readable = {} + + for item in a:items + if has_key(item, 'bufnr') + let filename = bufname(item.bufnr) + elseif has_key(item, 'filename') + let filename = item.filename + else + " nothing to do, add item back to the list + call add(filtered, item) + continue + endif - if empty(errors) - " Couldn't detect error format, output errors - echo a:out - endif + if !has_key(is_readable, filename) + let is_readable[filename] = filereadable(filename) + endif + if is_readable[filename] + call add(filtered, 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 + + return filtered endfunction function! go#tool#ExecuteInDir(cmd) abort diff --git a/bundle/pristine/vim-go/autoload/go/util.vim b/bundle/pristine/vim-go/autoload/go/util.vim index 2248fc3..3808044 100644 --- a/bundle/pristine/vim-go/autoload/go/util.vim +++ b/bundle/pristine/vim-go/autoload/go/util.vim @@ -1,61 +1,101 @@ " PathSep returns the appropriate OS specific path separator. function! go#util#PathSep() - if go#util#IsWin() - return '\' - endif - return '/' + if go#util#IsWin() + return '\' + endif + return '/' endfunction " PathListSep returns the appropriate OS specific path list separator. function! go#util#PathListSep() - if go#util#IsWin() - return ";" - endif - return ":" + if go#util#IsWin() + return ";" + endif + return ":" endfunction " LineEnding returns the correct line ending, based on the current fileformat function! go#util#LineEnding() - if &fileformat == 'dos' - return "\r\n" - elseif &fileformat == 'mac' - return "\r" - endif + if &fileformat == 'dos' + return "\r\n" + elseif &fileformat == 'mac' + return "\r" + endif - return "\n" + return "\n" endfunction " IsWin returns 1 if current OS is Windows or 0 otherwise function! go#util#IsWin() - let win = ['win16', 'win32', 'win32unix', 'win64', 'win95'] - for w in win - if (has(w)) - return 1 - endif - endfor + let win = ['win16', 'win32', 'win64', 'win95'] + for w in win + if (has(w)) + return 1 + endif + endfor - return 0 + return 0 endfunction " StripPath strips the path's last character if it's a path separator. " example: '/foo/bar/' -> '/foo/bar' function! go#util#StripPathSep(path) - let last_char = strlen(a:path) - 1 - if a:path[last_char] == go#util#PathSep() - return strpart(a:path, 0, last_char) - endif + let last_char = strlen(a:path) - 1 + if a:path[last_char] == go#util#PathSep() + return strpart(a:path, 0, last_char) + endif - return a:path + return a:path endfunction " 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 + try + let ssl_save = &shellslash + set noshellslash + if a:0 + return join(map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')'), ' ') + endif + + return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ') + finally + let &shellslash = ssl_save + endtry +endfunction + +" Shelllist returns a shell-safe representation of the items in the given +" arglist. The {special} argument of shellescape() may optionally be passed. +function! go#util#Shelllist(arglist, ...) + try + let ssl_save = &shellslash + set noshellslash + if a:0 + return map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')') + endif + return map(copy(a:arglist), 'shellescape(v:val)') + finally + let &shellslash = ssl_save + endtry +endfunction + +" TODO(arslan): I couldn't parameterize the highlight types. Check if we can +" simplify the following functions + +function! go#util#EchoSuccess(msg) + redraws! | echon "vim-go: " | echohl Function | echon a:msg | echohl None +endfunction + +function! go#util#EchoError(msg) + redraws! | echon "vim-go: " | echohl ErrorMsg | echon a:msg | echohl None +endfunction + +function! go#util#EchoWarning(msg) + redraws! | echon "vim-go: " | echohl WarningMsg | echon a:msg | echohl None +endfunction + +function! go#util#EchoProgress(msg) + redraws! | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None endfunction " vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/compiler/go.vim b/bundle/pristine/vim-go/compiler/go.vim index 2ce350d..7b5a025 100644 --- a/bundle/pristine/vim-go/compiler/go.vim +++ b/bundle/pristine/vim-go/compiler/go.vim @@ -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 diff --git a/bundle/pristine/vim-go/doc/vim-go.txt b/bundle/pristine/vim-go/doc/vim-go.txt index 96d7344..40423d9 100644 --- a/bundle/pristine/vim-go/doc/vim-go.txt +++ b/bundle/pristine/vim-go/doc/vim-go.txt @@ -14,14 +14,15 @@ =============================================================================== CONTENTS *go-contents* - 1. Intro........................................|go-intro| - 2. Install......................................|go-install| - 3. Commands.....................................|go-commands| - 4. Mappings.....................................|go-mappings| - 5. Text Objects.................................|go-text-objects| - 6. Settings.....................................|go-settings| - 7. Troubleshooting..............................|go-troubleshooting| - 8. Credits......................................|go-credits| + 1. Intro........................................|go-intro| + 2. Install......................................|go-install| + 3. Commands.....................................|go-commands| + 4. Mappings.....................................|go-mappings| + 5. Text Objects.................................|go-text-objects| + 6. Functions....................................|go-functions| + 7. Settings.....................................|go-settings| + 8. Troubleshooting..............................|go-troubleshooting| + 9. Credits......................................|go-credits| =============================================================================== INTRO *go-intro* @@ -33,29 +34,42 @@ 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. + * Go asm formatting on save * 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` + * A async launcher for the go command is implemented for neovim, fully async + building and testing. + * Integrated with the neovim terminal, launch `:GoRun` and other go commands + in their own new terminal. + * Alternate between implementation and test code with `:GoAlternate` =============================================================================== INSTALL *go-install* @@ -99,13 +113,15 @@ packages. * Autocompletion is enabled by default via ``, to get real-time completion (completion by type) install: -https://github.com/Valloric/YouCompleteMe or -https://github.com/Shougo/neocomplete.vim +https://github.com/Shougo/neocomplete.vim for Vim or +https://github.com/Shougo/deoplete.nvim and +https://github.com/zchee/deoplete-go for Neovim * To get displayed source code tag informations on a sidebar install https://github.com/majutsushi/tagbar. * For snippet feature install: -https://github.com/SirVer/ultisnips or -https://github.com/Shougo/neosnippet.vim. +https://github.com/Shougo/neosnippet.vim or +https://github.com/SirVer/ultisnips. +* For a better documentation viewer checkout: https://github.com/garyburd/go-explorer =============================================================================== COMMANDS *go-commands* @@ -213,11 +229,15 @@ COMMANDS *go-commands* If [!] is not given the first error is jumped to. + If using neovim then `:GoRun` will run in a new terminal according to + |g:go_term_mode|. + *:GoBuild* :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. + Build your package with `go build`. Errors are populated in the quickfix + window. 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 @@ -225,6 +245,9 @@ COMMANDS *go-commands* If [!] is not given the first error is jumped to. + If using neovim then this command is fully async, it does not block the + UI. + *:GoGenerate* :GoGenerate[!] [expand] @@ -257,14 +280,22 @@ 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 - used as file selector (useful for cases like `:GoTest ./...`). + are populated in the quickfix window. 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. + If using neovim `:GoTest` will run in a new terminal or run asynchronously + in the background according to |g:go_term_enabled|. You can set the mode of + the new terminal with |g:go_term_mode|. + *:GoTestFunc* :GoTestFunc[!] [expand] @@ -277,17 +308,25 @@ COMMANDS *go-commands* If [!] is not given the first error is jumped to. + If using neovim `:GoTestFunc` will run in a new terminal or run asynchronously + in the background according to |g:go_term_enabled|. You can set the mode of + the new terminal with |g:go_term_mode|. + *:GoTestCompile* :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 - as file selector (useful for cases like `:GoTest ./...`). Useful to not - run the tests and capture/fix errors before running the tests or to + populated in the quickfix window. 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. If [!] is not given the first error is jumped to. + If using neovim `:GoTestCompile` will run in a new terminal or run asynchronously + in the background according to |g:go_term_enabled|. You can set the mode of + the new terminal with |g:go_term_mode|. + *:GoCoverage* :GoCoverage[!] [options] @@ -303,7 +342,7 @@ COMMANDS *go-commands* :GoErrCheck [options] Check for unchecked errors in you current package. Errors are populated in - quickfix window. + the quickfix window. You may optionally pass any valid errcheck flags/options. For a full list please see `errcheck -h`. @@ -336,13 +375,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 in a 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] ... @@ -357,13 +398,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* @@ -379,8 +420,8 @@ COMMANDS *go-commands* :GoCallstack 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 + from the root of the callgraph to the selected function is shown in a + location list. This may be useful to understand how the function is reached in a given program. *:GoFreevars* @@ -416,6 +457,52 @@ 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 the quickfix window. 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. + + *:AsmFmt* +:AsmFmt + + Filter the current Go asm buffer through asmfmt. It tries to preserve cursor + position and avoids replacing the buffer with stderr output. + + + *:GoAlternate* +:GoAlternate[!] + + Alternates between the implementation and test code. For example if in main.go, + switch to main_test.go. Uses the |g:go_alternate_mode| setting as the command + to open the file. + + If [!] is given then it switches to the new file even if it does not exist. + + If you would like to override the traditional commands for alternating, add + the following to your .vimrc: +> + augroup go + autocmd! + autocmd Filetype go command! -bang A call go#alternate#Switch(0, 'edit') + autocmd Filetype go command! -bang AV call go#alternate#Switch(0, 'vsplit') + autocmd Filetype go command! -bang AS call go#alternate#Switch(0, 'split') + augroup END +< =============================================================================== MAPPINGS *go-mappings* @@ -434,6 +521,21 @@ documentation in the |go-commands| section. Available keys are: Calls `go run` for the current file + *(go-run-tab)* + +Calls `go run` for the current file in a new terminal tab +This option is neovim only. + + *(go-run-split)* + +Calls `go run` for the current file in a new terminal horizontal split +This option is neovim only. + + *(go-run-vertical)* + +Calls `go run` for the current file in a new terminal vertical split +This option is neovim only. + *(go-build)* @@ -565,6 +667,21 @@ 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 + + *(go-alternate-edit)* + +Alternates between the implementation and test code in the current window + + *(go-alternate-split)* + +Alternates between the implementation and test code in a new horizontal split + + *(go-alternate-vertical)* + +Alternates between the implementation and test code in a new vertical split =============================================================================== TEXT OBJECTS *go-text-objects* @@ -582,9 +699,33 @@ if "inside a function", select contents of a function, +=============================================================================== +FUNCTIONS *go-functions* + + *go#jobcontrol#Statusline()* + +Shows the status of a job running asynchronously. Can be used to plug into the +statusline. It works to show the status per package instead of per +file. Assume you have three files open, all belonging to the same package, +if the package build (`:GoBuild`) is successful, all statusline's will be empty +(means SUCCESS), if you it fails all file's statusline will show FAILED. + + *go#complete#GetInfo()* + +Returns the description of the identifer under the cursor. Can be used to plug +into the statusline. This function is also used for |g:go_auto_type_info|. + =============================================================================== 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 @@ -592,7 +733,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'* @@ -644,8 +785,8 @@ is empty. > *'g:go_fmt_fail_silently'* -Use this option to disable showing a quickfix window when |g:go_fmt_command| -fails. By default it's disabled. > +Use this option to disable showing a location list when |g:go_fmt_command| +fails. By default the location list is shown. > let g:go_fmt_fail_silently = 0 < @@ -661,26 +802,24 @@ it's causing problems on some Vim versions. By default it's disabled. > < *'g:go_doc_keywordprg_enabled'* -Use this option to change the enable GoDoc to run on words under the cursor -with the default K , keywordprg shortcut. This shortcut is by default set to -use the program man. However in go using godoc is more idiomatic. Default is -enabled. > +Use this option to run `godoc` on words under the cursor with the default +K , keywordprg shortcut. Usually this shortcut is set to use the program `man`. +In Go, using `godoc` is more idiomatic. Default is enabled. > let g:go_doc_keywordprg_enabled = 1 < *'g:go_def_mapping_enabled'* -Use this option to enabled/ disable the default mapping (`gd`) for GoDef -enabled. Disabling it allows you to map something else to the mapping `gd`. -Default is enabled. > +Use this option to enable/disable the default mapping of (`gd`) for GoDef. +Disabling it allows you to map something else to `gd`. Default is enabled. > let g:go_def_mapping_enabled = 1 < *'g:go_dispatch_enabled'* Use this option to enable/disable the use of Dispatch to execute the -`:GoRun`, `:GoBuild` and `:GoGenerate` commands. More information about Dispatch is -available at https://github.com/tpope/vim-dispatch. Default is disabled. > +`:GoRun`, `:GoBuild` and `:GoGenerate` commands. More information about Dispatch +is available at https://github.com/tpope/vim-dispatch. Default is disabled. > let g:go_dispatch_enabled = 0 < @@ -716,13 +855,12 @@ is used. Use "neosnippet" for neosnippet.vim: > *'g:go_oracle_scope'* -Use this option to define the scope of the analysis to be passed for Oracle -related commands, such as |GoImplements|, |GoCallers|, etc.. By default it's -not set, so only the current packages go files are passed as scope. You can -change it on-the-fly with |GoOracleScope|. For more -info please have look at Oracle's User Manual: -https://docs.google.com/document/d/1SLk36YRjjMgKqe490mSRzOPYEDe0Y_WQNRv-EiFYUyw/view#heading=h.nwso96pj07q8 -> +Use this option to define the scope of the analysis to be passed for oracle +related commands, such as |GoImplements|, |GoCallers|, etc. By default it's +not set, so only the current package's go files are passed as scope. You can +change it on-the-fly with |GoOracleScope|. For more info, please have a look +at oracle's user manual: +https://golang.org/s/oracle-user-manual#heading=h.nwso96pj07q8 > let g:go_oracle_scope = '' < @@ -736,8 +874,8 @@ Highlights white space after "[]". > *'g:go_highlight_chan_whitespace_error'* -Highlights white space around the communications operator that don't follow -the standard style. > +Highlights white space around the communications operator (`<-`) that doesn't +follow the standard style. > let g:go_highlight_chan_whitespace_error = 1 < @@ -764,7 +902,7 @@ Highlights trailing white space. > < *'g:go_highlight_operators'* -Highlights operators such as `:=` , `==`, `-=`, etc ...By default it's +Highlights operators such as `:=` , `==`, `-=`, etc. By default it's disabled. > let g:go_highlight_operators = 0 @@ -786,6 +924,12 @@ Highlights method names. By default it's disabled. > Highlights struct names. By default it's disabled. > let g:go_highlight_structs = 0 +< + *'g:go_highlight_interfaces'* + +Highlights interface names. By default it's disabled. > + + let g:go_highlight_interfaces = 0 < *'g:go_highlight_build_constraints'* @@ -793,14 +937,21 @@ Highlights build constraints. By default it's disabled. > let g:go_highlight_build_constraints = 0 < + *'g:go_highlight_string_spellcheck* + +Use this option to highlight spelling errors in strings when |spell| is +also enabled. By default it's enabled. > + + let g:go_highlight_string_spellcheck = 1 +< *'g:go_autodetect_gopath'* Automatically modifies GOPATH for certain directory structures, such as for -the tool godep which has his own dependencies via the `Godeps` folder. What +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 @@ -810,12 +961,117 @@ 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 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_list_height'* + +Specifies the window height for the quickfix and location list windows. The +default value (empty) automatically sets the height to the number of items +(maximum up to 10 items to prevent large heights). Setting the value +explicitly overrides this behavior. For standard Vim behavior, set it to 10. +> + let g:go_list_height = 0 +< + *'g:go_list_type'* + +Specifies the type of list to use. The default value (empty) will use the +appropriate kind of list for the command that was called. Supported values are +"", "quickfix", and "locationlist". > + + let g:go_list_type = "" +< + *'g:go_asmfmt_autosave'* + +Use this option to auto |:AsmFmt| on save. By default it's enabled. > + + let g:go_asmfmt_autosave = 1 +< + *g:go_term_mode* + +This option is Neovim only. Use it to change the default command used to +open a new terminal for go commands such as |:GoRun|. +The default is vsplit. +> + let g:go_term_mode = "vsplit" +< + *g:go_term_height* + *g:go_term_width* + +These options are Neovim only. Use them to control the height and width of +a terminal split. By default these are not set, meaning that the height and +width are set automatically by Neovim. The height only applies to a +horizontal split and width only applies to a vertical split. + +For example here is how to set each to 30. +> + let g:go_term_height = 30 + let g:go_term_width = 30 +< + *g:go_term_enabled* + +This option is Neovim only. Use it to change the behavior of the test +commands. If set to 1 it opens the test commands inside a new terminal +according to |g:go_term_mode|, otherwise it will run them in the background +just like `:GoBuild` and then display the status with |go#jobcontrol#Statusline()|. +By default it is disabled. +> + let g:go_term_enabled = 0 +< + *g:go_alternate_mode* + +Specifies the command that |:GoAlternate| uses to open the alternate file. +By default it is set to edit. +> + let g:go_alternate_mode = "edit" +< + *g:go_gorename_prefill* + +Specifies whether |:GoRename| prefills the new identifier name with the +word under the cursor. By default is is enabled. +> + let g:go_gorename_prefill = 1 +< =============================================================================== 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: > @@ -823,7 +1079,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 certain 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): > @@ -836,7 +1092,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: diff --git a/bundle/pristine/vim-go/ftdetect/gofiletype.vim b/bundle/pristine/vim-go/ftdetect/gofiletype.vim index 573dbb0..b5578a6 100644 --- a/bundle/pristine/vim-go/ftdetect/gofiletype.vim +++ b/bundle/pristine/vim-go/ftdetect/gofiletype.vim @@ -5,11 +5,11 @@ let s:current_fileformats = '' let s:current_fileencodings = '' " define fileencodings to open as utf-8 encoding even if it's ascii. -function! s:gofiletype_pre() +function! s:gofiletype_pre(type) let s:current_fileformats = &g:fileformats let s:current_fileencodings = &g:fileencodings set fileencodings=utf-8 fileformats=unix - setlocal filetype=go + let &l:filetype = a:type endfunction " restore fileencodings as others @@ -19,9 +19,13 @@ function! s:gofiletype_post() endfunction au BufNewFile *.go setfiletype go | setlocal fileencoding=utf-8 fileformat=unix -au BufRead *.go call s:gofiletype_pre() +au BufRead *.go call s:gofiletype_pre("go") au BufReadPost *.go call s:gofiletype_post() +au BufNewFile *.s setfiletype asm | setlocal fileencoding=utf-8 fileformat=unix +au BufRead *.s call s:gofiletype_pre("asm") +au BufReadPost *.s call s:gofiletype_post() + au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl " vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/ftplugin/asm.vim b/bundle/pristine/vim-go/ftplugin/asm.vim new file mode 100644 index 0000000..0ac3594 --- /dev/null +++ b/bundle/pristine/vim-go/ftplugin/asm.vim @@ -0,0 +1,17 @@ +" asm.vim: Vim filetype plugin for Go assembler. + +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +let b:undo_ftplugin = "setl fo< com< cms<" + +setlocal formatoptions-=t + +setlocal comments=s1:/*,mb:*,ex:*/,:// +setlocal commentstring=//\ %s + +setlocal noexpandtab + +command! -nargs=0 AsmFmt call go#asmfmt#Format() diff --git a/bundle/pristine/vim-go/ftplugin/go/commands.vim b/bundle/pristine/vim-go/ftplugin/go/commands.vim index cfd6ac7..4c6ddba 100644 --- a/bundle/pristine/vim-go/ftplugin/go/commands.vim +++ b/bundle/pristine/vim-go/ftplugin/go/commands.vim @@ -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 (go-run) :call go#cmd#Run(!g:go_jump_to_error, '%') -nnoremap (go-build) :call go#cmd#Build(!g:go_jump_to_error) -nnoremap (go-generate) :call go#cmd#Generate(!g:go_jump_to_error) -nnoremap (go-install) :call go#cmd#Install(!g:go_jump_to_error) -nnoremap (go-test) :call go#cmd#Test(!g:go_jump_to_error, 0) -nnoremap (go-test-func) :call go#cmd#TestFunc(!g:go_jump_to_error) -nnoremap (go-test-compile) :call go#cmd#Test(!g:go_jump_to_error, 1) -nnoremap (go-coverage) :call go#cmd#Coverage(!g:go_jump_to_error) -nnoremap (go-vet) :call go#cmd#Vet(!g:go_jump_to_error) - -nnoremap (go-files) :call go#tool#Files() -nnoremap (go-deps) :call go#tool#Deps() -nnoremap (go-info) :call go#complete#Info() -nnoremap (go-import) :call go#import#SwitchImport(1, '', expand(''), '') - -nnoremap (go-implements) :call go#oracle#Implements(-1) -nnoremap (go-callees) :call go#oracle#Callees(-1) -nnoremap (go-callers) :call go#oracle#Callers(-1) -nnoremap (go-describe) :call go#oracle#Describe(-1) -nnoremap (go-callstack) :call go#oracle#Callstack(-1) -nnoremap (go-freevars) :call go#oracle#Freevars(-1) -nnoremap (go-channelpeers) :call go#oracle#ChannelPeers(-1) -nnoremap (go-referrers) :call go#oracle#Referrers(-1) - -nnoremap (go-rename) :call go#rename#Rename() - -nnoremap (go-def) :call go#def#Jump() -nnoremap (go-def-vertical) :call go#def#JumpMode("vsplit") -nnoremap (go-def-split) :call go#def#JumpMode("split") -nnoremap (go-def-tab) :call go#def#JumpMode("tab") - -nnoremap (go-doc) :call go#doc#Open("new", "split") -nnoremap (go-doc-tab) :call go#doc#Open("tabnew", "tabe") -nnoremap (go-doc-vertical) :call go#doc#Open("vnew", "vsplit") -nnoremap (go-doc-split) :call go#doc#Open("new", "split") -nnoremap (go-doc-browser) :call go#doc#OpenBrowser() - - " gorename -command! -nargs=? GoRename call go#rename#Rename() +command! -nargs=? GoRename call go#rename#Rename(0,) " oracle +command! -nargs=* -complete=customlist,go#package#Complete GoOracleScope call go#oracle#Scope() command! -range=% GoImplements call go#oracle#Implements() command! -range=% GoCallees call go#oracle#Callees() command! -range=% GoDescribe call go#oracle#Describe() @@ -65,8 +11,7 @@ command! -range=% GoCallstack call go#oracle#Callstack() command! -range=% GoFreevars call go#oracle#Freevars() command! -range=% GoChannelPeers call go#oracle#ChannelPeers() command! -range=% GoReferrers call go#oracle#Referrers() - -command! -nargs=* -complete=customlist,go#package#Complete GoOracleScope call go#oracle#Scope() +command! -nargs=? GoOracleTags call go#oracle#Tags() " tool command! -nargs=0 GoFiles echo go#tool#Files() @@ -82,7 +27,6 @@ command! -nargs=* -bang GoTest call go#cmd#Test(0, 0, ) command! -nargs=* -bang GoTestFunc call go#cmd#TestFunc(0, ) command! -nargs=* -bang GoTestCompile call go#cmd#Test(0, 1, ) command! -nargs=* -bang GoCoverage call go#cmd#Coverage(0, ) -command! -nargs=* -bang GoVet call go#cmd#Vet(0, ) " -- play command! -nargs=0 -range=% GoPlay call go#play#Share(, , ) @@ -103,10 +47,13 @@ command! -nargs=? -complete=customlist,go#package#Complete GoDrop call go#import command! -nargs=1 -bang -complete=customlist,go#package#Complete GoImport call go#import#SwitchImport(1, '', , '') command! -nargs=* -bang -complete=customlist,go#package#Complete GoImportAs call go#import#SwitchImport(1, , '') -" -- lint -command! -nargs=* GoLint call go#lint#Run() +" -- linters +command! -nargs=* GoMetaLinter call go#lint#Gometa(0, ) +command! -nargs=* GoLint call go#lint#Golint() +command! -nargs=* -bang GoVet call go#lint#Vet(0, ) +command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck() -" -- errcheck -command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#errcheck#Run() +" -- alternate +command! -bang GoAlternate call go#alternate#Switch(0, '') " vim:ts=4:sw=4:et diff --git a/bundle/pristine/vim-go/ftplugin/go/mappings.vim b/bundle/pristine/vim-go/ftplugin/go/mappings.vim new file mode 100644 index 0000000..68eacc1 --- /dev/null +++ b/bundle/pristine/vim-go/ftplugin/go/mappings.vim @@ -0,0 +1,60 @@ +" 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 (go-run) :call go#cmd#Run(!g:go_jump_to_error) + +if has("nvim") + nnoremap (go-run-vertical) :call go#cmd#RunTerm(!g:go_jump_to_error, 'vsplit', []) + nnoremap (go-run-split) :call go#cmd#RunTerm(!g:go_jump_to_error, 'split', []) + nnoremap (go-run-tab) :call go#cmd#RunTerm(!g:go_jump_to_error, 'tabe', []) +endif + +nnoremap (go-build) :call go#cmd#Build(!g:go_jump_to_error) +nnoremap (go-generate) :call go#cmd#Generate(!g:go_jump_to_error) +nnoremap (go-install) :call go#cmd#Install(!g:go_jump_to_error) +nnoremap (go-test) :call go#cmd#Test(!g:go_jump_to_error, 0) +nnoremap (go-test-func) :call go#cmd#TestFunc(!g:go_jump_to_error) +nnoremap (go-test-compile) :call go#cmd#Test(!g:go_jump_to_error, 1) +nnoremap (go-coverage) :call go#cmd#Coverage(!g:go_jump_to_error) + +nnoremap (go-files) :call go#tool#Files() +nnoremap (go-deps) :call go#tool#Deps() +nnoremap (go-info) :call go#complete#Info() +nnoremap (go-import) :call go#import#SwitchImport(1, '', expand(''), '') + +nnoremap (go-implements) :call go#oracle#Implements(-1) +nnoremap (go-callees) :call go#oracle#Callees(-1) +nnoremap (go-callers) :call go#oracle#Callers(-1) +nnoremap (go-describe) :call go#oracle#Describe(-1) +nnoremap (go-callstack) :call go#oracle#Callstack(-1) +nnoremap (go-freevars) :call go#oracle#Freevars(-1) +nnoremap (go-channelpeers) :call go#oracle#ChannelPeers(-1) +nnoremap (go-referrers) :call go#oracle#Referrers(-1) + +nnoremap (go-rename) :call go#rename#Rename(!g:go_jump_to_error) + +nnoremap (go-def) :call go#def#Jump() +nnoremap (go-def-vertical) :call go#def#JumpMode("vsplit") +nnoremap (go-def-split) :call go#def#JumpMode("split") +nnoremap (go-def-tab) :call go#def#JumpMode("tab") + +nnoremap (go-doc) :call go#doc#Open("new", "split") +nnoremap (go-doc-tab) :call go#doc#Open("tabnew", "tabe") +nnoremap (go-doc-vertical) :call go#doc#Open("vnew", "vsplit") +nnoremap (go-doc-split) :call go#doc#Open("new", "split") +nnoremap (go-doc-browser) :call go#doc#OpenBrowser() + +nnoremap (go-metalinter) :call go#lint#Gometa(0) +nnoremap (go-vet) :call go#lint#Vet(!g:go_jump_to_error) + +nnoremap (go-alternate-edit) :call go#alternate#Switch(0, "edit") +nnoremap (go-alternate-vertical) :call go#alternate#Switch(0, "vsplit") +nnoremap (go-alternate-split) :call go#alternate#Switch(0, "split") diff --git a/bundle/pristine/vim-go/gosnippets/snippets/go.snip b/bundle/pristine/vim-go/gosnippets/snippets/go.snip index f7f2336..f60aeb5 100644 --- a/bundle/pristine/vim-go/gosnippets/snippets/go.snip +++ b/bundle/pristine/vim-go/gosnippets/snippets/go.snip @@ -124,6 +124,7 @@ abbr if err != nil { ... } if err != nil { return err } + ${0} # error snippet in TestFunc snippet errt abbr if err != nil { ... } @@ -135,11 +136,10 @@ abbr if err != nil { ... } snippet errn, abbr if err != nil { return [...], err } if err != nil { - return ${2}$1, err + return ${1:nil}, err } ${0} - # error snippet handle and return snippet errh abbr if err != nil { return } @@ -153,6 +153,7 @@ abbr if err != nil { return } snippet json abbr \`json:key\` \`json:"${1:keyName}"\` + # fallthrough snippet ft abbr fallthrough diff --git a/bundle/pristine/vim-go/indent/gohtmltmpl.vim b/bundle/pristine/vim-go/indent/gohtmltmpl.vim index 50399f2..94ea135 100644 --- a/bundle/pristine/vim-go/indent/gohtmltmpl.vim +++ b/bundle/pristine/vim-go/indent/gohtmltmpl.vim @@ -3,3 +3,42 @@ if exists("b:did_indent") endif runtime! indent/html.vim + +" Indent Golang HTML templates +setlocal indentexpr=GetGoHTMLTmplIndent(v:lnum) +setlocal indentkeys+==else,=end + +" Only define the function once. +if exists("*GetGoHTMLTmplIndent") + finish +endif + +function! GetGoHTMLTmplIndent(lnum) + " Get HTML indent + if exists('*HtmlIndent') + let ind = HtmlIndent() + else + let ind = HtmlIndentGet(a:lnum) + endif + + " The value of a single shift-width + if exists('*shiftwidth') + let sw = shiftwidth() + else + let sw = &sw + endif + + " If need to indent based on last line + let last_line = getline(a:lnum-1) + if last_line =~ '^\s*{{\s*\%(if\|else\|range\|with\|define\|block\).*}}' + let ind += sw + endif + + " End of FuncMap block + let current_line = getline(a:lnum) + if current_line =~ '^\s*{{\s*\%(else\|end\).*}}' + let ind -= sw + endif + + return ind +endfunction diff --git a/bundle/pristine/vim-go/plugin/go.vim b/bundle/pristine/vim-go/plugin/go.vim index e28b060..63b42ce 100644 --- a/bundle/pristine/vim-go/plugin/go.vim +++ b/bundle/pristine/vim-go/plugin/go.vim @@ -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", @@ -16,6 +17,7 @@ let s:packages = [ \ "github.com/golang/lint/golint", \ "github.com/kisielk/errcheck", \ "github.com/jstemmer/gotags", + \ "github.com/klauspost/asmfmt/cmd/asmfmt", \ ] " These commands are available on any filetypes @@ -118,6 +120,23 @@ endfunction " Autocommands " ============================================================================ +" +function! s:echo_go_info() + if !exists('v:completed_item') || empty(v:completed_item) + return + endif + let item = v:completed_item + + if !has_key(item, "info") + return + endif + + if empty(item.info) + return + endif + + redraws! | echo "vim-go: " | echohl Function | echon item.info | echohl None +endfunction augroup vim-go autocmd! @@ -127,11 +146,26 @@ augroup vim-go autocmd CursorHold *.go nested call go#complete#Info() endif - " code formatting on save + " Echo the identifier information when completion is done. Useful to see + " the signature of a function, etc... + if exists('##CompleteDone') + autocmd CompleteDone *.go nested call s:echo_go_info() + endif + + " Go code formatting on save if get(g:, "go_fmt_autosave", 1) autocmd BufWritePre *.go call go#fmt#Format(-1) endif + " Go asm formatting on save + if get(g:, "go_asmfmt_autosave", 1) + autocmd BufWritePre *.s call go#asmfmt#Format() + endif + + " run gometalinter on save + if get(g:, "go_metalinter_autosave", 0) + autocmd BufWritePost *.go call go#lint#Gometa(1) + endif augroup END diff --git a/bundle/pristine/vim-go/scripts/test.sh b/bundle/pristine/vim-go/scripts/test.sh old mode 100644 new mode 100755 diff --git a/bundle/pristine/vim-go/syntax/go.vim b/bundle/pristine/vim-go/syntax/go.vim index 0c606ec..56722a1 100644 --- a/bundle/pristine/vim-go/syntax/go.vim +++ b/bundle/pristine/vim-go/syntax/go.vim @@ -10,9 +10,9 @@ " 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. +" functions, methods, structs, operators, build constraints and interfaces. " " - go_highlight_array_whitespace_error " Highlights white space after "[]". @@ -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,31 @@ 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_interfaces") + let g:go_highlight_interfaces = 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 +121,8 @@ syn match goDeclaration /\/ " 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 +155,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 @@ -197,9 +212,17 @@ endif " Spacing errors around the 'chan' keyword if g:go_highlight_chan_whitespace_error != 0 " receive-only annotation on chan type - syn match goSpaceError display "\(<-\)\@<=\s\+\(chan\>\)\@=" + " + " \(\\)\@\)\@\)\@=" + " send-only annotation on chan type - syn match goSpaceError display "\(\ (only pick chan when it doesn't come after an arrow) + " this prevents picking up '<-chan <-chan' but not 'chan <-' + syn match goSpaceError display "\(\(<-\)\@\)\@<=\s\+\(<-\)\@=" + " value-ignoring receives in a few contexts syn match goSpaceError display "\(\(^\|[={(,;]\)\s*<-\)\@<=\s\+" endif @@ -234,58 +257,85 @@ 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 +" Interfaces; +if g:go_highlight_interfaces != 0 + syn match goInterface /\(.\)\@<=\w\+\({\)\@=/ + syn match goInterfaceDef /\(type\s\+\)\@<=\w\+\(\s\+interface\s\+{\)\@=/ +endif +hi def link goInterface Function +hi def link goInterfaceDef 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 + 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 + + " 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 -hi def link goBuildComment Comment -hi def link goBuildOs Type -hi def link goBuildArch Type -hi def link goBuildDirective PreProc - " Search backwards for a global declaration to start processing the syntax. "syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/ diff --git a/bundle/pristine/vim-go/syntax/gotexttmpl.vim b/bundle/pristine/vim-go/syntax/gotexttmpl.vim index 50b4653..37c62a9 100644 --- a/bundle/pristine/vim-go/syntax/gotexttmpl.vim +++ b/bundle/pristine/vim-go/syntax/gotexttmpl.vim @@ -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