mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated vimrc
This commit is contained in:
58
sources_non_forked/vim-go/LICENSE
Normal file
58
sources_non_forked/vim-go/LICENSE
Normal file
@ -0,0 +1,58 @@
|
||||
Copyright (c) 2015, Fatih Arslan
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of vim-go nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This software includes some portions from Go. Go is used under the terms of the
|
||||
BSD like license.
|
||||
|
||||
Copyright (c) 2012 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -15,23 +15,28 @@ disabled/enabled easily.
|
||||
* Auto completion support via `gocode`
|
||||
* Better `gofmt` on save, 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
|
||||
* 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`
|
||||
* `:GoRun` quickly your current file/files
|
||||
* Run `:GoTest` and see any errors in quickfix window
|
||||
* Automatic `GOPATH` detection based on the directory structure (i.e: `godep`
|
||||
vendored projects)
|
||||
* Change or display `GOPATH` with `:GoPath`
|
||||
* 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 through `go vet` to catch static errors.
|
||||
* Advanced source analysis tool with `oracle`
|
||||
* Precise type-safe renaming of identifiers with `gorename`
|
||||
which functions are covered with `:GoCoverage`
|
||||
* Lint your code with `:GoLint`
|
||||
* Run your code through `:GoVet` to catch static errors.
|
||||
* Advanced source analysis tool with oracle, such as `:GoImplements`,
|
||||
`:GoCallees`, `:GoReferrers`
|
||||
* Precise type-safe renaming of identifiers with `:GoRename`
|
||||
* List all source files and dependencies
|
||||
* Checking with `errcheck` for unchecked errors.
|
||||
* Checking with `:GoErrCheck` for unchecked errors.
|
||||
* Integrated and improved snippets. Supports `ultisnips` or `neosnippet`
|
||||
* Share your current code to [play.golang.org](http://play.golang.org)
|
||||
* On-the-fly type information about the word under the cursor
|
||||
* Share your current code to [play.golang.org](http://play.golang.org) with `:GoPlay`
|
||||
* On-the-fly type information about the word under the cursor. Plug it into
|
||||
your custom vim function.
|
||||
* Tagbar support to show tags of the source code in a sidebar with `gotags`
|
||||
* Custom vim text objects, such a `a function` or `inner function`
|
||||
|
||||
@ -50,9 +55,6 @@ add the appropriate lines and execute the plugin's install command.
|
||||
* `NeoBundle 'fatih/vim-go'`
|
||||
* [Vundle](https://github.com/gmarik/vundle)
|
||||
* `Plugin 'fatih/vim-go'`
|
||||
* Manual
|
||||
* Copy all of the files into your `~/.vim` directory
|
||||
|
||||
|
||||
Please be sure all necessary binaries are installed (such as `gocode`, `godef`,
|
||||
`goimports`, etc..). You can easily install them with the included
|
||||
@ -73,12 +75,15 @@ completion (completion by type) 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).
|
||||
|
||||
## Usage
|
||||
|
||||
Many of the [features](#features) are enabled by default. There are no
|
||||
additional settings needed. All usages and commands are listed in
|
||||
`doc/vim-go.txt`. Just open the help page to see all commands:
|
||||
`doc/vim-go.txt`. Note that help tags needs to be populated. Check your plugin
|
||||
manager settings to generate the documentation (some do it automatically).
|
||||
After that just open the help page to see all commands:
|
||||
|
||||
:help vim-go
|
||||
|
||||
@ -87,34 +92,6 @@ additional settings needed. All usages and commands are listed in
|
||||
vim-go has several `<Plug>` mappings which can be used to create custom
|
||||
mappings. Below are some examples you might find useful:
|
||||
|
||||
Show a list of interfaces which is implemented by the type under your cursor
|
||||
with `<leader>s`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>s <Plug>(go-implements)
|
||||
```
|
||||
|
||||
Show type info for the word under your cursor with `<leader>i` (useful if you
|
||||
have disabled auto showing type info via `g:go_auto_type_info`)
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>i <Plug>(go-info)
|
||||
```
|
||||
|
||||
Open the relevant Godoc for the word under the cursor with `<leader>gd` or open
|
||||
it vertically with `<leader>gv`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gd <Plug>(go-doc)
|
||||
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
|
||||
```
|
||||
|
||||
Or open the Godoc in browser
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
|
||||
```
|
||||
|
||||
Run commands, such as `go run` with `<leader>r` for the current file or `go
|
||||
build` and `go test` for the current package with `<leader>b` and `<leader>t`.
|
||||
Display a beautiful annotated source code to see which functions are covered
|
||||
@ -137,6 +114,34 @@ au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
|
||||
au FileType go nmap <Leader>dt <Plug>(go-def-tab)
|
||||
```
|
||||
|
||||
Open the relevant Godoc for the word under the cursor with `<leader>gd` or open
|
||||
it vertically with `<leader>gv`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gd <Plug>(go-doc)
|
||||
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
|
||||
```
|
||||
|
||||
Or open the Godoc in browser
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
|
||||
```
|
||||
|
||||
Show a list of interfaces which is implemented by the type under your cursor
|
||||
with `<leader>s`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>s <Plug>(go-implements)
|
||||
```
|
||||
|
||||
Show type info for the word under your cursor with `<leader>i` (useful if you
|
||||
have disabled auto showing type info via `g:go_auto_type_info`)
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>i <Plug>(go-info)
|
||||
```
|
||||
|
||||
Rename the identifier under the cursor to a new name
|
||||
|
||||
```vim
|
||||
@ -150,37 +155,6 @@ based on `:he go-commands`.
|
||||
## Settings
|
||||
Below are some settings you might find useful. For the full list see `:he go-settings`.
|
||||
|
||||
Disable opening browser after posting to your snippet to `play.golang.org`:
|
||||
|
||||
```vim
|
||||
let g:go_play_open_browser = 0
|
||||
```
|
||||
|
||||
By default vim-go shows errors for the fmt command, to disable it:
|
||||
|
||||
```vim
|
||||
let g:go_fmt_fail_silently = 1
|
||||
```
|
||||
|
||||
Enable goimports to automatically insert import paths instead of gofmt:
|
||||
|
||||
```vim
|
||||
let g:go_fmt_command = "goimports"
|
||||
```
|
||||
|
||||
Disable auto fmt on save:
|
||||
|
||||
```vim
|
||||
let g:go_fmt_autosave = 0
|
||||
```
|
||||
|
||||
By default binaries are installed to `$GOBIN` or `$GOPATH/bin`. To change it:
|
||||
|
||||
```vim
|
||||
let g:go_bin_path = expand("~/.gotools")
|
||||
let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path
|
||||
```
|
||||
|
||||
By default syntax-highlighting for Functions, Methods and Structs is disabled.
|
||||
To change it:
|
||||
```vim
|
||||
@ -191,58 +165,53 @@ let g:go_highlight_operators = 1
|
||||
let g:go_highlight_build_constraints = 1
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
Enable goimports to automatically insert import paths instead of gofmt:
|
||||
|
||||
### Command not found
|
||||
```vim
|
||||
let g:go_fmt_command = "goimports"
|
||||
```
|
||||
|
||||
If trying to use `:GoDef`, `:GoInfo` and get a `command not found`, check that you have the binaries installed by using: `:GoInstallBinaries`
|
||||
By default vim-go shows errors for the fmt command, to disable it:
|
||||
|
||||
Before opening vim, check your current `$PATH`:
|
||||
```vim
|
||||
let g:go_fmt_fail_silently = 1
|
||||
```
|
||||
|
||||
echo $PATH
|
||||
Disable auto fmt on save:
|
||||
|
||||
after opening vim, run `:echo $PATH`, the output must be your current `$PATH` + `$GOPATH/bin` (the location where `:GoInstallBinaries` installed the binaries
|
||||
```vim
|
||||
let g:go_fmt_autosave = 0
|
||||
```
|
||||
|
||||
If problem persists and you are using maybe 'csh' or other shell, try adding this to your .vimrc:
|
||||
Disable opening browser after posting to your snippet to `play.golang.org`:
|
||||
|
||||
set shell=/bin/sh
|
||||
```vim
|
||||
let g:go_play_open_browser = 0
|
||||
```
|
||||
|
||||
By default when `:GoInstallBinaries` is called, the binaries are installed to
|
||||
`$GOBIN` or `$GOPATH/bin`. To change it:
|
||||
|
||||
```vim
|
||||
let g:go_bin_path = expand("~/.gotools")
|
||||
let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path
|
||||
```
|
||||
|
||||
|
||||
## More info
|
||||
|
||||
### I'm using Fish shell but have some problems using Vim-go
|
||||
Check out the Wiki page for more information. It includes Screencasts, FAQ
|
||||
section and many various piece of information:
|
||||
|
||||
First environment variables in Fish are applied differently, it should be like:
|
||||
[https://github.com/fatih/vim-go/wiki](https://github.com/fatih/vim-go/wiki)
|
||||
|
||||
set -x GOPATH /your/own/gopath
|
||||
|
||||
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
|
||||
too). To overcome this problem change the default shell by adding the following
|
||||
into your .vimrc (on the top of the file):
|
||||
|
||||
if $SHELL =~ 'fish'
|
||||
set shell='/bin/sh'
|
||||
endif
|
||||
|
||||
or
|
||||
|
||||
set shell='/bin/sh'
|
||||
|
||||
## Why another plugin?
|
||||
|
||||
This plugin/package is born mainly from frustration. I had to re-install my Vim
|
||||
plugins and especially for Go I had to install a lot of separate different
|
||||
plugins, setup the necessary binaries to make them work together and hope not
|
||||
to lose them again. Lots of plugins out there lack proper settings.
|
||||
This plugin is improved and contains all my fixes/changes that I'm using for
|
||||
months under heavy go development environment.
|
||||
|
||||
Give it a try. I hope you like it. Feel free to contribute to the project.
|
||||
|
||||
## Donations
|
||||
|
||||
Vim-go is an open source project and I'm working on it on my free times. I'm spending a lot of time and thoughts to make it stable, fixing bugs, adding new features, etc... If you like vim-go and find it helpful, you might give me a gift from some of the books (kindle) I have in my wish list:
|
||||
Vim-go is an open source project and I'm working on it on my free times. I'm
|
||||
spending a lot of time and thoughts to make it stable, fixing bugs, adding new
|
||||
features, etc... If you like vim-go and find it helpful, you might give me a
|
||||
gift from some of the books (kindle) I have in my wish list:
|
||||
|
||||
[Amazon.com Fatih's Wish List](http://amzn.com/w/3RUTKZC0U30P6). Thanks!
|
||||
|
||||
@ -250,4 +219,10 @@ Vim-go is an open source project and I'm working on it on my free times. I'm spe
|
||||
|
||||
* Go Authors for official vim plugins
|
||||
* 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)
|
||||
* 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
|
||||
|
||||
## License
|
||||
|
||||
The BSD 3-Clause License - see `LICENSE` for more details
|
||||
|
@ -1,11 +1,63 @@
|
||||
if !exists("g:go_jump_to_error")
|
||||
let g:go_jump_to_error = 1
|
||||
if !exists("g:go_dispatch_enabled")
|
||||
let g:go_dispatch_enabled = 0
|
||||
endif
|
||||
|
||||
function! go#cmd#autowrite()
|
||||
if &autowrite == 1
|
||||
silent wall
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Build buils the source code without producting any output binary. We live in
|
||||
" an editor so the best is to build it to catch errors and fix them. By
|
||||
" default it tries to call simply 'go build', but it first tries to get all
|
||||
" dependent files for the current folder and passes it to go build.
|
||||
function! go#cmd#Build(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
if v:shell_error
|
||||
let &makeprg = "go build . errors"
|
||||
else
|
||||
let &makeprg = "go build -o /dev/null " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "building ..."| echohl None
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
endif
|
||||
redraw!
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None
|
||||
endif
|
||||
|
||||
let &makeprg = default_makeprg
|
||||
let $GOPATH = old_gopath
|
||||
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, ...)
|
||||
let goFiles = '"' . join(go#tool#Files(), '" "') . '"'
|
||||
|
||||
if IsWin()
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
if go#util#IsWin()
|
||||
exec '!go run ' . goFiles
|
||||
if v:shell_error
|
||||
redraws! | echon "vim-go: [run] " | echohl ErrorMsg | echon "FAILED"| echohl None
|
||||
@ -13,6 +65,7 @@ function! go#cmd#Run(bang, ...)
|
||||
redraws! | echon "vim-go: [run] " | echohl Function | echon "SUCCESS"| echohl None
|
||||
endif
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
return
|
||||
endif
|
||||
|
||||
@ -23,65 +76,47 @@ function! go#cmd#Run(bang, ...)
|
||||
let &makeprg = "go run " . expand(a:1)
|
||||
endif
|
||||
|
||||
exe 'make!'
|
||||
if !a:bang
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if g:go_jump_to_error
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
endif
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make!'
|
||||
else
|
||||
exe 'make!'
|
||||
endif
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
let &makeprg = default_makeprg
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Install(...)
|
||||
" 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.
|
||||
function! go#cmd#Install(bang, ...)
|
||||
let pkgs = join(a:000, '" "')
|
||||
let command = 'go install "' . pkgs . '"'
|
||||
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
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
if exists("$GOBIN")
|
||||
echon "vim-go: " | echohl Function | echon "installed to ". $GOBIN | echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH . "/bin" | echohl None
|
||||
endif
|
||||
echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Build(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
if v:shell_error
|
||||
let &makeprg = "go build . errors"
|
||||
else
|
||||
let &makeprg = "go build -o /dev/null " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "building ..."| echohl None
|
||||
silent! exe 'make!'
|
||||
redraw!
|
||||
if !a:bang
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if g:go_jump_to_error
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None
|
||||
endif
|
||||
endif
|
||||
|
||||
let &makeprg = default_makeprg
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Test(compile, ...)
|
||||
" 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 "
|
||||
|
||||
" don't run the test, only compile it. Useful to capture and fix errors or
|
||||
@ -94,6 +129,11 @@ function! go#cmd#Test(compile, ...)
|
||||
let command .= expand(a:1)
|
||||
endif
|
||||
|
||||
if len(a:000) == 2
|
||||
let command .= a:2
|
||||
endif
|
||||
|
||||
call go#cmd#autowrite()
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Identifier | echon "compiling tests ..." | echohl None
|
||||
else
|
||||
@ -106,10 +146,8 @@ function! go#cmd#Test(compile, ...)
|
||||
call go#tool#ShowErrors(out)
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if g:go_jump_to_error
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None
|
||||
else
|
||||
@ -124,11 +162,47 @@ function! go#cmd#Test(compile, ...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Coverage(...)
|
||||
" Testfunc runs a single test that surrounds the current cursor position.
|
||||
" Arguments are passed to the `go test` command.
|
||||
function! go#cmd#TestFunc(bang, ...)
|
||||
" search flags legend (used only)
|
||||
" 'b' search backward instead of forward
|
||||
" 'c' accept a match at the cursor position
|
||||
" 'n' do Not move the cursor
|
||||
" 'W' don't wrap around the end of the file
|
||||
"
|
||||
" for the full list
|
||||
" :help search
|
||||
let test = search("func Test", "bcnW")
|
||||
|
||||
if test == 0
|
||||
echo "vim-go: [test] no test found immediate to cursor"
|
||||
return
|
||||
end
|
||||
|
||||
let line = getline(test)
|
||||
let name = split(split(line, " ")[1], "(")[0]
|
||||
let flag = "-run \"" . name . "$\""
|
||||
|
||||
let a1 = ""
|
||||
if len(a:000)
|
||||
let a1 = a:1
|
||||
|
||||
" add extra space
|
||||
let flag = " " . flag
|
||||
endif
|
||||
|
||||
call go#cmd#Test(a:bang, 0, a1, flag)
|
||||
endfunction
|
||||
|
||||
" Coverage creates a new cover profile with 'go test -coverprofile' and opens
|
||||
" a new HTML coverage page from that profile.
|
||||
function! go#cmd#Coverage(bang, ...)
|
||||
let l:tmpname=tempname()
|
||||
|
||||
let command = "go test -coverprofile=".l:tmpname
|
||||
|
||||
call go#cmd#autowrite()
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
@ -140,18 +214,17 @@ function! go#cmd#Coverage(...)
|
||||
call go#tool#ExecuteInDir(openHTML)
|
||||
endif
|
||||
cwindow
|
||||
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if g:go_jump_to_error
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
|
||||
call delete(l:tmpname)
|
||||
endfunction
|
||||
|
||||
function! go#cmd#Vet()
|
||||
" Vet calls "go vet' on the current directory. Any warnings are populated in
|
||||
" the quickfix window
|
||||
function! go#cmd#Vet(bang)
|
||||
call go#cmd#autowrite()
|
||||
echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None
|
||||
let out = go#tool#ExecuteInDir('go vet')
|
||||
if v:shell_error
|
||||
@ -159,17 +232,52 @@ function! go#cmd#Vet()
|
||||
else
|
||||
call setqflist([])
|
||||
endif
|
||||
cwindow
|
||||
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if g:go_jump_to_error
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
"
|
||||
" Generate runs 'go generate' in similar fashion to go#cmd#Build()
|
||||
function! go#cmd#Generate(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
if v:shell_error
|
||||
let &makeprg = "go generate " . join(a:000, ' ')
|
||||
else
|
||||
let &makeprg = "go generate " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
endif
|
||||
redraw!
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None
|
||||
endif
|
||||
|
||||
let &makeprg = default_makeprg
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
"
|
||||
|
@ -31,6 +31,9 @@ fu! s:system(str, ...)
|
||||
endf
|
||||
|
||||
fu! s:gocodeShellescape(arg)
|
||||
if go#vimproc#has_vimproc()
|
||||
return vimproc#shellescape(a:arg)
|
||||
endif
|
||||
try
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
@ -48,12 +51,20 @@ fu! s:gocodeCommand(cmd, preargs, args)
|
||||
let a:preargs[i] = s:gocodeShellescape(a:preargs[i])
|
||||
endfor
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_gocode_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_gocode_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let result = s:system(printf('%s %s %s %s', bin_path, join(a:preargs), a:cmd, join(a:args)))
|
||||
" we might hit cache problems, as gocode doesn't handle well different
|
||||
" GOPATHS: https://github.com/nsf/gocode/issues/239
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let result = s:system(printf('%s %s %s %s', s:gocodeShellescape(bin_path), join(a:preargs), s:gocodeShellescape(a:cmd), join(a:args)))
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
|
||||
if v:shell_error != 0
|
||||
return "[\"0\", []]"
|
||||
else
|
||||
|
@ -13,35 +13,43 @@ function! go#def#Jump(...)
|
||||
let arg = a:1
|
||||
endif
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_godef_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_godef_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let command = bin_path . " -f=" . shellescape(expand("%:p")) . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), LineEnding()))
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
|
||||
" jump to it
|
||||
call s:godefJump(out, "")
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
|
||||
function! go#def#JumpMode(mode)
|
||||
let arg = s:getOffset()
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_godef_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_godef_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let command = bin_path . " -f=" . expand("%:p") . " -i " . shellescape(arg)
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let command = bin_path . " -f=" . shellescape(expand("%:p")) . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), LineEnding()))
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
|
||||
call s:godefJump(out, a:mode)
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
|
||||
@ -51,7 +59,7 @@ function! s:getOffset()
|
||||
let offs = line2byte(pos[0]) + pos[1] - 2
|
||||
else
|
||||
let c = pos[1]
|
||||
let buf = line('.') == 1 ? "" : (join(getline(1, pos[0] - 1), LineEnding()) . LineEnding())
|
||||
let buf = line('.') == 1 ? "" : (join(getline(1, pos[0] - 1), go#util#LineEnding()) . go#util#LineEnding())
|
||||
let buf .= c == 1 ? "" : getline(pos[0])[:c-2]
|
||||
let offs = len(iconv(buf, &encoding, "utf-8"))
|
||||
endif
|
||||
@ -66,7 +74,7 @@ function! s:godefJump(out, mode)
|
||||
let &errorformat = "%f:%l:%c"
|
||||
|
||||
if a:out =~ 'godef: '
|
||||
let out=substitute(a:out, LineEnding() . '$', '', '')
|
||||
let out=substitute(a:out, go#util#LineEnding() . '$', '', '')
|
||||
echom out
|
||||
else
|
||||
let parts = split(a:out, ':')
|
||||
|
@ -71,6 +71,14 @@ function! s:godocWord(args)
|
||||
return [pkg, exported_name]
|
||||
endfunction
|
||||
|
||||
function! s:godocNotFound(content)
|
||||
if len(a:content) == 0
|
||||
return 1
|
||||
endif
|
||||
|
||||
return a:content =~# '^.*: no such file or directory\n$'
|
||||
endfunction
|
||||
|
||||
function! go#doc#OpenBrowser(...)
|
||||
let pkgs = s:godocWord(a:000)
|
||||
if empty(pkgs)
|
||||
@ -97,7 +105,7 @@ function! go#doc#Open(newmode, mode, ...)
|
||||
let command = g:go_doc_command . ' ' . g:go_doc_options . ' ' . pkg
|
||||
|
||||
silent! let content = system(command)
|
||||
if v:shell_error || !len(content)
|
||||
if v:shell_error || s:godocNotFound(content)
|
||||
echo 'No documentation found for "' . pkg . '".'
|
||||
return -1
|
||||
endif
|
||||
|
@ -13,7 +13,7 @@ function! go#errcheck#Run(...) abort
|
||||
let package = a:1
|
||||
end
|
||||
|
||||
let bin_path = go#tool#BinPath(g:go_errcheck_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_errcheck_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
@ -27,7 +27,7 @@ function! go#errcheck#Run(...) abort
|
||||
let tokens = matchlist(line, mx)
|
||||
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": expand(DefaultGoPath() . "/src/" . tokens[1]),
|
||||
call add(errors, {"filename": expand(go#path#Default() . "/src/" . tokens[1]),
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4]})
|
||||
@ -44,6 +44,7 @@ function! go#errcheck#Run(...) abort
|
||||
call setqflist(errors, 'r')
|
||||
endif
|
||||
else
|
||||
redraw | echo
|
||||
call setqflist([])
|
||||
endif
|
||||
|
||||
|
@ -79,14 +79,18 @@ function! go#fmt#Format(withGoimport)
|
||||
|
||||
" 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,
|
||||
" if not the user get's a warning via go#tool#BinPath()
|
||||
" 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#tool#BinPath(fmt_command)
|
||||
let bin_path = go#path#CheckBinPath(fmt_command)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
" change GOPATH too, so goimports can pick up the correct library
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let fmt_command = bin_path
|
||||
endif
|
||||
|
||||
@ -95,8 +99,16 @@ function! go#fmt#Format(withGoimport)
|
||||
|
||||
" execute our command...
|
||||
let out = system(command . " " . l:tmpname)
|
||||
let splitted = split(out, '\n')
|
||||
|
||||
"if there is no error on the temp file, gofmt again our original file
|
||||
if fmt_command != "gofmt"
|
||||
let $GOPATH = old_gopath
|
||||
endif
|
||||
|
||||
|
||||
"if there is no error on the temp file replace the output with the current
|
||||
"file (if this fails, we can always check the outputs first line with:
|
||||
"splitted =~ 'package \w\+')
|
||||
if v:shell_error == 0
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
@ -106,8 +118,16 @@ function! go#fmt#Format(withGoimport)
|
||||
let default_srr = &srr
|
||||
set srr=>%s
|
||||
|
||||
" execufe gofmt on the current buffer and replace it
|
||||
silent execute "%!" . command
|
||||
" delete any leftover before we replace the whole file. Suppose the
|
||||
" file had 20 lines, but new output has 10 lines, only 1-10 are
|
||||
" replaced with setline, remaining lines 11-20 won't get touched. So
|
||||
" remove them.
|
||||
if line('$') > len(splitted)
|
||||
execute len(splitted) .',$delete'
|
||||
endif
|
||||
|
||||
" setline iterates over the list and replaces each line
|
||||
call setline(1, splitted)
|
||||
|
||||
" only clear quickfix if it was previously set, this prevents closing
|
||||
" other quickfixes
|
||||
@ -122,7 +142,7 @@ function! go#fmt#Format(withGoimport)
|
||||
elseif g:go_fmt_fail_silently == 0
|
||||
"otherwise get the errors and put them to quickfix window
|
||||
let errors = []
|
||||
for line in split(out, '\n')
|
||||
for line in splitted
|
||||
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": @%,
|
||||
|
@ -50,6 +50,12 @@ function! go#import#SwitchImport(enabled, localname, path)
|
||||
if path[len(path)-1] == '"'
|
||||
let path = strpart(path, 0, len(path) - 1)
|
||||
endif
|
||||
|
||||
" if given a trailing slash, eg. `github.com/user/pkg/`, remove it
|
||||
if path[len(path)-1] == '/'
|
||||
let path = strpart(path, 0, len(path) - 1)
|
||||
endif
|
||||
|
||||
if path == ''
|
||||
call s:Error('Import path not provided')
|
||||
return
|
||||
|
@ -17,7 +17,7 @@ if !exists("g:go_golint_bin")
|
||||
endif
|
||||
|
||||
function! go#lint#Run() abort
|
||||
let bin_path = go#tool#BinPath(g:go_golint_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_golint_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
@ -1,4 +1,3 @@
|
||||
" -*- text -*-
|
||||
" oracle.vim -- Vim integration for the Go oracle.
|
||||
"
|
||||
" Part of this plugin was taken directly from the oracle repo, however it's
|
||||
@ -46,7 +45,7 @@ endfun
|
||||
" via regex.
|
||||
func! s:qflistSecond(output)
|
||||
" backup users errorformat, will be restored once we are finished
|
||||
let old_errorformat = &errorformat
|
||||
let old_errorformat = &errorformat
|
||||
|
||||
" match two possible styles of errorformats:
|
||||
"
|
||||
@ -56,13 +55,13 @@ func! s:qflistSecond(output)
|
||||
" 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
|
||||
" number
|
||||
let &errorformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
let &errorformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
|
||||
" create the quickfix list and open it
|
||||
cgetexpr split(a:output, "\n")
|
||||
cwindow
|
||||
|
||||
let &errorformat = old_errorformat
|
||||
let &errorformat = old_errorformat
|
||||
endfun
|
||||
|
||||
func! s:getpos(l, c)
|
||||
@ -85,7 +84,7 @@ func! s:RunOracle(mode, selected) range abort
|
||||
let unescaped_scopes = split(get(g:, 'go_oracle_scope'))
|
||||
let scopes = []
|
||||
for unescaped_scope in unescaped_scopes
|
||||
call add(scopes, shellescape(unescaped_scope))
|
||||
call add(scopes, shellescape(unescaped_scope))
|
||||
endfor
|
||||
elseif exists('g:go_oracle_include_tests') && pkg != -1
|
||||
" give import path so it includes all _test.go files too
|
||||
@ -97,7 +96,7 @@ func! s:RunOracle(mode, selected) range abort
|
||||
endif
|
||||
|
||||
"return with a warning if the bin doesn't exist
|
||||
let bin_path = go#tool#BinPath(g:go_oracle_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_oracle_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
@ -120,23 +119,48 @@ func! s:RunOracle(mode, selected) range abort
|
||||
" info check Oracle's User Manual section about scopes:
|
||||
" https://docs.google.com/document/d/1SLk36YRjjMgKqe490mSRzOPYEDe0Y_WQNRv-EiFYUyw/view#heading=h.nwso96pj07q8
|
||||
for scope in scopes
|
||||
let cmd .= ' ' . scope
|
||||
let cmd .= ' ' . scope
|
||||
endfor
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "analysing ..." | echohl None
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let out = system(cmd)
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
|
||||
if v:shell_error
|
||||
" unfortunaly oracle outputs a very long stack trace that is not
|
||||
" parsable to show the real error. But the main issue is usually the
|
||||
" package which doesn't build.
|
||||
redraw | echon "vim-go: " | echohl Statement | echon out | echohl None
|
||||
return ""
|
||||
else
|
||||
endif
|
||||
|
||||
return out
|
||||
endfun
|
||||
endfunc
|
||||
|
||||
function! go#oracle#Scope(...)
|
||||
if len(a:000)
|
||||
if len(a:000) == 1 && a:1 == '""'
|
||||
let g:go_oracle_scope = ""
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is cleared"| echohl None
|
||||
else
|
||||
let g:go_oracle_scope = join(a:000, ' ')
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope changed to: '". g:go_oracle_scope ."'" | echohl None
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists(g:go_oracle_scope)
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is not set"| echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "current oracle scope: '". g:go_oracle_scope ."'" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Show 'implements' relation for selected package
|
||||
function! go#oracle#Implements(selected)
|
||||
@ -162,12 +186,6 @@ function! go#oracle#Callers(selected)
|
||||
call s:qflistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show the callgraph of the current program.
|
||||
function! go#oracle#Callgraph(selected)
|
||||
let out = s:RunOracle('callgraph', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show path from callgraph root to selected function
|
||||
function! go#oracle#Callstack(selected)
|
||||
let out = s:RunOracle('callstack', a:selected)
|
||||
@ -189,28 +207,8 @@ endfunction
|
||||
" Show all refs to entity denoted by selected identifier
|
||||
function! go#oracle#Referrers(selected)
|
||||
let out = s:RunOracle('referrers', a:selected)
|
||||
|
||||
" append line contents from Go source file for some messages:
|
||||
" '...: referenced here'
|
||||
" '...: reference to NAME'
|
||||
let lines = split(out, "\n")
|
||||
let extlines = []
|
||||
for line in lines
|
||||
if line =~# '\v: referenced here$|: reference to [^ :]*$'
|
||||
let parts = split(line, ':')
|
||||
" Note: we count -3 from end, to support additional comma in
|
||||
" Windows-style C:\... paths
|
||||
let filename = join(parts[0:-3], ':')
|
||||
let linenum = parts[-2]
|
||||
let extline = line . ': ' . readfile(filename, '', linenum)[linenum-1]
|
||||
call add(extlines, extline)
|
||||
else
|
||||
call add(extlines, line)
|
||||
endif
|
||||
endfor
|
||||
let out = join(extlines, "\n")
|
||||
|
||||
call s:qflistSecond(out)
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
"
|
||||
|
@ -44,11 +44,7 @@ function! go#package#Paths()
|
||||
let dirs += [goroot]
|
||||
endif
|
||||
|
||||
let pathsep = ':'
|
||||
if s:goos == 'windows'
|
||||
let pathsep = ';'
|
||||
endif
|
||||
let workspaces = split($GOPATH, pathsep)
|
||||
let workspaces = split($GOPATH, go#util#PathListSep())
|
||||
if workspaces != []
|
||||
let dirs += workspaces
|
||||
endif
|
||||
@ -116,7 +112,11 @@ endfunction
|
||||
|
||||
function! go#package#Complete(ArgLead, CmdLine, CursorPos)
|
||||
let words = split(a:CmdLine, '\s\+', 1)
|
||||
if len(words) > 2 && words[0] != "GoImportAs"
|
||||
|
||||
" do not complete package members for these commands
|
||||
let neglect_commands = ["GoImportAs", "GoOracleScope"]
|
||||
|
||||
if len(words) > 2 && index(neglect_commands, words[0]) == -1
|
||||
" Complete package members
|
||||
return go#package#CompleteMembers(words[1], words[2])
|
||||
endif
|
||||
@ -142,6 +142,11 @@ function! go#package#Complete(ArgLead, CmdLine, CursorPos)
|
||||
endif
|
||||
let i = substitute(substitute(i[len(r)+1:], '[\\]', '/', 'g'),
|
||||
\ '\.a$', '', 'g')
|
||||
|
||||
" without this the result can have duplicates in form of
|
||||
" 'encoding/json' and '/encoding/json/'
|
||||
let i = go#util#StripPathSep(i)
|
||||
|
||||
let ret[i] = i
|
||||
endfor
|
||||
endfor
|
||||
|
175
sources_non_forked/vim-go/autoload/go/path.vim
Normal file
175
sources_non_forked/vim-go/autoload/go/path.vim
Normal file
@ -0,0 +1,175 @@
|
||||
" initial_go_path is used to store the initial GOPATH that was set when Vim
|
||||
" was started. It's used with :GoPathClear to restore the GOPATH when the user
|
||||
" changed it explicitly via :GoPath. Initially it's empty. It's being set when
|
||||
" :GoPath is used
|
||||
let s:initial_go_path = ""
|
||||
|
||||
" GoPath sets or returns the current GOPATH. If no arguments are passed it
|
||||
" echoes the current GOPATH, if an argument is passed it replaces the current
|
||||
" GOPATH with it. If two double quotes are passed (the empty string in go),
|
||||
" it'll clear the GOPATH and will restore to the initial GOPATH.
|
||||
function! go#path#GoPath(...)
|
||||
" we have an argument, replace GOPATH
|
||||
if len(a:000)
|
||||
" clears the current manually set GOPATH and restores it to the
|
||||
" initial GOPATH, which was set when Vim was started.
|
||||
if len(a:000) == 1 && a:1 == '""'
|
||||
if !empty(s:initial_go_path)
|
||||
let $GOPATH = s:initial_go_path
|
||||
let s:initial_go_path = ""
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Function | echon "GOPATH restored to ". $GOPATH | echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Function | echon "GOPATH changed to ". a:1 | echohl None
|
||||
let s:initial_go_path = $GOPATH
|
||||
let $GOPATH = a:1
|
||||
return
|
||||
endif
|
||||
|
||||
echo go#path#Detect()
|
||||
endfunction
|
||||
|
||||
" Default returns the default GOPATH. If there is a single GOPATH it returns
|
||||
" it. For multiple GOPATHS separated with a the OS specific separator, only
|
||||
" the first one is returned
|
||||
function! go#path#Default()
|
||||
let go_paths = split($GOPATH, go#util#PathListSep())
|
||||
|
||||
if len(go_paths) == 1
|
||||
return $GOPATH
|
||||
endif
|
||||
|
||||
return go_paths[0]
|
||||
endfunction
|
||||
|
||||
" HasPath checks whether the given path exists in GOPATH environment variable
|
||||
" or not
|
||||
function! go#path#HasPath(path)
|
||||
let go_paths = split($GOPATH, go#util#PathListSep())
|
||||
let last_char = strlen(a:path) - 1
|
||||
|
||||
" check cases of '/foo/bar/' and '/foo/bar'
|
||||
if a:path[last_char] == go#util#PathSep()
|
||||
let withSep = a:path
|
||||
let noSep = strpart(a:path, 0, last_char)
|
||||
else
|
||||
let withSep = a:path . go#util#PathSep()
|
||||
let noSep = a:path
|
||||
endif
|
||||
|
||||
let hasA = index(go_paths, withSep) != -1
|
||||
let hasB = index(go_paths, noSep) != -1
|
||||
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.
|
||||
function! go#path#Detect()
|
||||
let gopath = $GOPATH
|
||||
|
||||
" don't lookup for godeps if autodetect is disabled.
|
||||
if !get(g:, "go_autodetect_gopath", 1)
|
||||
return gopath
|
||||
endif
|
||||
|
||||
let current_dir = fnameescape(expand('%:p:h'))
|
||||
|
||||
" TODO(arslan): this should be changed so folders or files should be
|
||||
" fetched from a customizable list. The user should define any new package
|
||||
" management tool by it's own.
|
||||
|
||||
" src folder outside $GOPATH
|
||||
let src_root = finddir("src", current_dir .";")
|
||||
if !empty(src_root)
|
||||
let src_path = fnamemodify(src_root, ':p:h:h') . go#util#PathSep()
|
||||
|
||||
" 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)
|
||||
let gopath = gb_vendor_root . go#util#PathListSep() . gopath
|
||||
endif
|
||||
|
||||
if !go#path#HasPath(src_path)
|
||||
let gopath = src_path . go#util#PathListSep() . gopath
|
||||
endif
|
||||
endif
|
||||
|
||||
" Godeps
|
||||
let godeps_root = finddir("Godeps", current_dir .";")
|
||||
if !empty(godeps_root)
|
||||
let godeps_path = join([fnamemodify(godeps_root, ':p:h:h'), "Godeps", "_workspace" ], go#util#PathSep())
|
||||
|
||||
if !go#path#HasPath(godeps_path)
|
||||
let gopath = godeps_path . go#util#PathListSep() . gopath
|
||||
endif
|
||||
endif
|
||||
|
||||
return gopath
|
||||
endfunction
|
||||
|
||||
|
||||
" BinPath returns the binary path of installed go tools.
|
||||
function! go#path#BinPath()
|
||||
let bin_path = ""
|
||||
|
||||
" check if our global custom path is set, if not check if $GOBIN is set so
|
||||
" we can use it, otherwise use $GOPATH + '/bin'
|
||||
if exists("g:go_bin_path")
|
||||
let bin_path = g:go_bin_path
|
||||
elseif $GOBIN != ""
|
||||
let bin_path = $GOBIN
|
||||
elseif $GOPATH != ""
|
||||
let bin_path = expand(go#path#Default() . "/bin/")
|
||||
else
|
||||
" could not find anything
|
||||
endif
|
||||
|
||||
return bin_path
|
||||
endfunction
|
||||
|
||||
" CheckBinPath checks whether the given binary exists or not and returns the
|
||||
" path of the binary. It returns an empty string doesn't exists.
|
||||
function! go#path#CheckBinPath(binpath)
|
||||
" remove whitespaces if user applied something like 'goimports '
|
||||
let binpath = substitute(a:binpath, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
" if it's in PATH just return it
|
||||
if executable(binpath)
|
||||
return binpath
|
||||
endif
|
||||
|
||||
|
||||
" just get the basename
|
||||
let basename = fnamemodify(binpath, ":t")
|
||||
|
||||
" check if we have an appropriate bin_path
|
||||
let go_bin_path = go#path#BinPath()
|
||||
if empty(go_bin_path)
|
||||
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
|
||||
return ""
|
||||
endif
|
||||
|
||||
" append our GOBIN and GOPATH paths and be sure they can be found there...
|
||||
" let us search in our GOBIN and GOPATH paths
|
||||
let old_path = $PATH
|
||||
let $PATH = $PATH . go#util#PathListSep() .go_bin_path
|
||||
|
||||
if !executable(basename)
|
||||
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
|
||||
" restore back!
|
||||
let $PATH = old_path
|
||||
return ""
|
||||
endif
|
||||
|
||||
let $PATH = old_path
|
||||
|
||||
return go_bin_path . go#util#PathSep() . basename
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
@ -5,8 +5,9 @@ endif
|
||||
function! go#rename#Rename(...)
|
||||
let to = ""
|
||||
if a:0 == 0
|
||||
let ask = printf("vim-go: rename '%s' to: ", expand("<cword>"))
|
||||
let to = input(ask)
|
||||
let from = expand("<cword>")
|
||||
let ask = printf("vim-go: rename '%s' to: ", from)
|
||||
let to = input(ask, from)
|
||||
redraw
|
||||
else
|
||||
let to = a:1
|
||||
@ -14,12 +15,12 @@ function! go#rename#Rename(...)
|
||||
|
||||
|
||||
"return with a warning if the bin doesn't exist
|
||||
let bin_path = go#tool#BinPath(g:go_gorename_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let fname = resolve(expand('%:p:t'))
|
||||
let fname = expand('%:p')
|
||||
let pos = s:getpos(line('.'), col('.'))
|
||||
let cmd = printf('%s -offset %s -to %s', shellescape(bin_path), shellescape(printf('%s:#%d', fname, pos)), shellescape(to))
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
function! go#tool#Files()
|
||||
if IsWin()
|
||||
if go#util#IsWin()
|
||||
let command = 'go list -f "{{range $f := .GoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}"'
|
||||
else
|
||||
let command = "go list -f '{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}'"
|
||||
@ -9,7 +9,7 @@ function! go#tool#Files()
|
||||
endfunction
|
||||
|
||||
function! go#tool#Deps()
|
||||
if IsWin()
|
||||
if go#util#IsWin()
|
||||
let command = 'go list -f "{{range $f := .Deps}}{{$f}}{{printf \"\n\"}}{{end}}"'
|
||||
else
|
||||
let command = "go list -f $'{{range $f := .Deps}}{{$f}}\n{{end}}'"
|
||||
@ -20,7 +20,7 @@ endfunction
|
||||
|
||||
function! go#tool#Imports()
|
||||
let imports = {}
|
||||
if IsWin()
|
||||
if go#util#IsWin()
|
||||
let command = 'go list -f "{{range $f := .Imports}}{{$f}}{{printf \"\n\"}}{{end}}"'
|
||||
else
|
||||
let command = "go list -f $'{{range $f := .Imports}}{{$f}}\n{{end}}'"
|
||||
@ -41,7 +41,17 @@ function! go#tool#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"))
|
||||
|
||||
let errors = []
|
||||
|
||||
for line in split(a:out, '\n')
|
||||
let fatalerrors = matchlist(line, '^\(fatal error:.*\)$')
|
||||
let tokens = matchlist(line, '^\s*\(.\{-}\):\(\d\+\):\s*\(.*\)')
|
||||
@ -49,7 +59,7 @@ function! go#tool#ShowErrors(out)
|
||||
if !empty(fatalerrors)
|
||||
call add(errors, {"text": fatalerrors[1]})
|
||||
elseif !empty(tokens)
|
||||
call add(errors, {"filename" : expand("%:p:h:") . "/" . tokens[1],
|
||||
call add(errors, {"filename" : fnamemodify(tokens[1], ':p'),
|
||||
\"lnum": tokens[2],
|
||||
\"text": tokens[3]})
|
||||
elseif !empty(errors)
|
||||
@ -61,6 +71,9 @@ function! go#tool#ShowErrors(out)
|
||||
endif
|
||||
endfor
|
||||
|
||||
" return back to old dir once we are finished with populating the errors
|
||||
execute cd . fnameescape(current_dir)
|
||||
|
||||
if !empty(errors)
|
||||
call setqflist(errors, 'r')
|
||||
return
|
||||
@ -73,14 +86,19 @@ function! go#tool#ShowErrors(out)
|
||||
endfunction
|
||||
|
||||
function! go#tool#ExecuteInDir(cmd) abort
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd.'`=expand("%:p:h")`'
|
||||
execute cd . fnameescape(expand("%:p:h"))
|
||||
let out = system(a:cmd)
|
||||
finally
|
||||
execute cd.'`=dir`'
|
||||
execute cd . fnameescape(dir)
|
||||
endtry
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
return out
|
||||
endfunction
|
||||
|
||||
@ -97,56 +115,13 @@ function! go#tool#Exists(importpath)
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" BinPath checks whether the given binary exists or not and returns the path
|
||||
" of the binary. It returns an empty string doesn't exists.
|
||||
function! go#tool#BinPath(binpath)
|
||||
" remove whitespaces if user applied something like 'goimports '
|
||||
let binpath = substitute(a:binpath, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
" if it's in PATH just return it
|
||||
if executable(binpath)
|
||||
return binpath
|
||||
endif
|
||||
|
||||
|
||||
" just get the basename
|
||||
let basename = fnamemodify(binpath, ":t")
|
||||
|
||||
" check if we have an appropriate bin_path
|
||||
let go_bin_path = GetBinPath()
|
||||
if empty(go_bin_path)
|
||||
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
|
||||
return ""
|
||||
endif
|
||||
|
||||
" append our GOBIN and GOPATH paths and be sure they can be found there...
|
||||
" let us search in our GOBIN and GOPATH paths
|
||||
let old_path = $PATH
|
||||
let $PATH = $PATH . PathSep() .go_bin_path
|
||||
|
||||
if !executable(basename)
|
||||
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
|
||||
" restore back!
|
||||
let $PATH = old_path
|
||||
return ""
|
||||
endif
|
||||
|
||||
let $PATH = old_path
|
||||
|
||||
let sep = '/'
|
||||
if IsWin()
|
||||
let sep = '\'
|
||||
endif
|
||||
|
||||
return go_bin_path . sep . basename
|
||||
endfunction
|
||||
|
||||
" following two functions are from: https://github.com/mattn/gist-vim
|
||||
" thanks @mattn
|
||||
function! s:get_browser_command()
|
||||
let go_play_browser_command = get(g:, 'go_play_browser_command', '')
|
||||
if go_play_browser_command == ''
|
||||
if IsWin()
|
||||
if go#util#IsWin()
|
||||
let go_play_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%'
|
||||
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
|
||||
let go_play_browser_command = 'open %URL%'
|
||||
@ -183,5 +158,4 @@ function! go#tool#OpenBrowser(url)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
51
sources_non_forked/vim-go/autoload/go/util.vim
Normal file
51
sources_non_forked/vim-go/autoload/go/util.vim
Normal file
@ -0,0 +1,51 @@
|
||||
" PathSep returns the appropriate OS specific path separator.
|
||||
function! go#util#PathSep()
|
||||
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 ":"
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
return a:path
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
@ -1,7 +1,7 @@
|
||||
"Check if has vimproc
|
||||
function! go#vimproc#has_vimproc()
|
||||
if !exists('g:go#use_vimproc')
|
||||
if IsWin()
|
||||
if go#util#IsWin()
|
||||
try
|
||||
call vimproc#version()
|
||||
let exists_vimproc = 1
|
||||
|
@ -24,6 +24,7 @@ endif
|
||||
CompilerSet errorformat=
|
||||
\%-G#\ %.%#,
|
||||
\%-G%.%#panic:\ %m,
|
||||
\%Ecan\'t\ load\ package:\ %m,
|
||||
\%A%f:%l:%c:\ %m,
|
||||
\%A%f:%l:\ %m,
|
||||
\%C%*\\s%m,
|
||||
|
@ -71,12 +71,12 @@ add the appropriate lines and execute the plugin's install command.
|
||||
<
|
||||
|
||||
* https://github.com/junegunn/vim-plug >
|
||||
|
||||
|
||||
Plug 'fatih/vim-go'
|
||||
|
||||
<
|
||||
* https://github.com/Shougo/neobundle.vim >
|
||||
|
||||
|
||||
NeoBundle 'fatih/vim-go'
|
||||
<
|
||||
|
||||
@ -86,7 +86,7 @@ add the appropriate lines and execute the plugin's install command.
|
||||
|
||||
<
|
||||
* Manual >
|
||||
|
||||
|
||||
Copy all of the files into your `~/.vim` directory
|
||||
<
|
||||
|
||||
@ -110,6 +110,14 @@ https://github.com/Shougo/neosnippet.vim.
|
||||
===============================================================================
|
||||
COMMANDS *go-commands*
|
||||
|
||||
*:GoPath*
|
||||
:GoPath [path]
|
||||
|
||||
GoPath sets and ovverides GOPATH with the given {path}. If no {path} is
|
||||
given it shows the current GOPATH. If `""` is given as path, it clears
|
||||
current `GOPATH` which was set with |GoPath| and restores `GOPATH` back to
|
||||
the inital value which was sourced when Vim was started.
|
||||
|
||||
*:GoImport*
|
||||
:GoImport [path]
|
||||
|
||||
@ -169,7 +177,7 @@ COMMANDS *go-commands*
|
||||
'xterm-clipboard' otherwise it's get yanked into the `""` register.
|
||||
|
||||
*:GoVet*
|
||||
:GoVet
|
||||
:GoVet[!]
|
||||
|
||||
Run `go vet` for the directory under your current file. Vet examines Go
|
||||
source code and reports suspicious constructs, such as Printf calls whose
|
||||
@ -177,6 +185,8 @@ COMMANDS *go-commands*
|
||||
guarantee all reports are genuine problems, but it can find errors not caught
|
||||
by the compilers.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoDef*
|
||||
:GoDef [identifier]
|
||||
|
||||
@ -204,6 +214,17 @@ COMMANDS *go-commands*
|
||||
You may optionally pass any valid go build flags/options. For a full list
|
||||
please see `go help build`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoGenerate*
|
||||
:GoGenerate[!] [options]
|
||||
|
||||
Creates or updates your auto-generated source files by running `go
|
||||
generate`.
|
||||
|
||||
You may optionally pass any valid go generate flags/options. For a full list
|
||||
please see `go help generate`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoInfo*
|
||||
@ -214,19 +235,35 @@ COMMANDS *go-commands*
|
||||
|
||||
|
||||
*:GoInstall*
|
||||
:GoInstall
|
||||
:GoInstall[!]
|
||||
|
||||
Install your package with `go install`.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoTest*
|
||||
:GoTest [expand]
|
||||
: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 ./...`).
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoTestFunc*
|
||||
:GoTestFunc[!] [expand]
|
||||
|
||||
Runs :GoTest, but only on the single test function immediate to your
|
||||
cursor using 'go test's '-run' flag.
|
||||
|
||||
Lookup is done starting at the cursor (including that line) moving up till
|
||||
a matching `func Test` pattern is found or top of file is reached. Search
|
||||
will not wrap around when at the top of the file.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoTestCompile*
|
||||
:GoTestCompile [expand]
|
||||
: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
|
||||
@ -234,12 +271,16 @@ COMMANDS *go-commands*
|
||||
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.
|
||||
|
||||
*:GoCoverage*
|
||||
:GoCoverage
|
||||
:GoCoverage[!]
|
||||
|
||||
Create a coverage profile and open a browser to display the annotated
|
||||
source code of the current package.
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
*:GoErrCheck*
|
||||
:GoErrCheck
|
||||
|
||||
@ -274,13 +315,22 @@ 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 quickfix list.
|
||||
*:GoRename*
|
||||
: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.
|
||||
|
||||
|
||||
*:GoOracleScope*
|
||||
:GoOracleScope [path1] [path2] ...
|
||||
|
||||
Changes the custom |g:go_oracle_scope| setting and overrides it with the
|
||||
given import paths. The custom scope is cleared (unset) if `""` is given
|
||||
as the only path. If no arguments is given it prints the current custom
|
||||
scope.
|
||||
|
||||
*:GoCallees*
|
||||
:GoCallees
|
||||
|
||||
@ -304,27 +354,20 @@ COMMANDS *go-commands*
|
||||
identifier), etc. Almost any piece of syntax may be described, and the
|
||||
oracle will try to print all the useful information it can.
|
||||
|
||||
*:GoCallgraph*
|
||||
:GoCallgraph
|
||||
|
||||
Shows the 'callgraph' for the entire program. For more info about the
|
||||
indentation checkout the Oracle User Manual:
|
||||
golang.org/s/oracle-user-manual
|
||||
|
||||
*:GoCallstack*
|
||||
:GoCallstack
|
||||
|
||||
Shows 'callstack' relation for the selected function. An arbitrary path
|
||||
from the root of the callgrap to the selected function is showed in a
|
||||
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
|
||||
reached in a given program.
|
||||
reached in a given program.
|
||||
|
||||
*:GoFreevars*
|
||||
:GoFreevars
|
||||
|
||||
Enumerates the free variables of the selection. “Free variables” is a
|
||||
technical term meaning the set of variables that are referenced but not
|
||||
defined within the selection, or loosely speaking, its inputs.
|
||||
defined within the selection, or loosely speaking, its inputs.
|
||||
|
||||
This information is useful if you’re considering whether to refactor the
|
||||
selection into a function of its own, as the free variables would be the
|
||||
@ -336,11 +379,11 @@ COMMANDS *go-commands*
|
||||
:GoChannelPeers
|
||||
|
||||
Shows the set of possible sends/receives on the channel operand of the
|
||||
selected send or receive operation; the selection must be a <- token.
|
||||
selected send or receive operation; the selection must be a <- token.
|
||||
|
||||
For example, visually select a channel operand in the form of:
|
||||
For example, visually select a channel operand in the form of:
|
||||
|
||||
"done <- true"
|
||||
"done <- true"
|
||||
|
||||
and call |GoChannelPeers| on it. It will show where it was allocated, and
|
||||
the sending and receiving endings.
|
||||
@ -375,6 +418,10 @@ Calls `go run` for the current file
|
||||
|
||||
Calls `go build` for the current package
|
||||
|
||||
*(go-generate)*
|
||||
|
||||
Calls `go generate` for the current package
|
||||
|
||||
|
||||
*(go-info)*
|
||||
|
||||
@ -390,6 +437,10 @@ Calls `go install` for the current package
|
||||
|
||||
Calls `go test` for the current package
|
||||
|
||||
*(go-test-func)*
|
||||
|
||||
Calls `go test -run '...'` for the test function immediate to cursor
|
||||
|
||||
*(go-test-compile)*
|
||||
|
||||
Calls `go test -c` for the current package
|
||||
@ -477,10 +528,6 @@ Show possible callers of selected function
|
||||
Describe selected syntax: definition, methods, etc
|
||||
|
||||
|
||||
*(go-callgraph)*
|
||||
|
||||
Show the callgraph of the current program.
|
||||
|
||||
*(go-callstack)*
|
||||
|
||||
Show path from callgraph root to selected function
|
||||
@ -541,6 +588,18 @@ By default it's disabled >
|
||||
|
||||
let g:go_auto_type_info = 0
|
||||
<
|
||||
|
||||
*'g:go_jump_to_error'*
|
||||
|
||||
Use this option to enable/disable passing the bang attribute to the mappings
|
||||
|(go-build)|, |(go-run)|, etc.. When enabled it will jump to the first error
|
||||
automatically (means it will NOT pass the bang attribute to the appropriate
|
||||
command, i.e: (go-run) -> :GoRun ). Note, that calling this doesn't have any
|
||||
affect on calling the commands manually. This setting is only useful for
|
||||
changing the behaviour of our custom static mappings. By default it's enabled.
|
||||
>
|
||||
let g:go_jump_to_error = 1
|
||||
<
|
||||
*'g:go_fmt_autosave'*
|
||||
|
||||
Use this option to auto |:GoFmt| on save. By default it's enabled >
|
||||
@ -574,10 +633,10 @@ fails. By default it's disabled. >
|
||||
|
||||
Use this option to enable fmt's experimental mode. This experimental mode is
|
||||
superior to the current mode as it fully saves the undo history, so undo/redo
|
||||
doesn't break. However it's causing problems on some Vim versions. By default
|
||||
it's disabled. >
|
||||
doesn't break. However it's slows (creates/deletes a file for every save) and
|
||||
it's causing problems on some Vim versions. By default it's disabled. >
|
||||
|
||||
let g:go_fmt_experimental = 1
|
||||
let g:go_fmt_experimental = 0
|
||||
<
|
||||
*'g:go_doc_keywordprg_enabled'*
|
||||
|
||||
@ -595,6 +654,14 @@ enabled. Disabling it allows you to map something else to the mapping `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. >
|
||||
|
||||
let g:go_dispatch_enabled = 0
|
||||
<
|
||||
*'g:go_doc_command'*
|
||||
|
||||
@ -630,7 +697,8 @@ is used. Use "neosnippet" for neosnippet.vim: >
|
||||
|
||||
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. For more
|
||||
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
|
||||
>
|
||||
@ -704,12 +772,25 @@ Highlights build constraints. By default it's disabled. >
|
||||
|
||||
let g:go_highlight_build_constraints = 0
|
||||
<
|
||||
|
||||
*'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
|
||||
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
|
||||
supports will be added. By default it's enabled. >
|
||||
|
||||
let g:go_autodetect_gopath = 1
|
||||
<
|
||||
*'g:go_textobj_enabled'*
|
||||
|
||||
Adds custom text objects. By default it's enabled. >
|
||||
|
||||
let g:go_textobj_enabled = 1
|
||||
|
||||
|
||||
===============================================================================
|
||||
TROUBLESHOOTING *go-troubleshooting*
|
||||
|
||||
|
@ -6,18 +6,22 @@ let s:current_fileencodings = ''
|
||||
|
||||
" define fileencodings to open as utf-8 encoding even if it's ascii.
|
||||
function! s:gofiletype_pre()
|
||||
let s:current_fileformats = &g:fileformats
|
||||
let s:current_fileencodings = &g:fileencodings
|
||||
set fileencodings=utf-8 fileformats=unix
|
||||
setlocal filetype=go
|
||||
let s:current_fileformats = &g:fileformats
|
||||
let s:current_fileencodings = &g:fileencodings
|
||||
set fileencodings=utf-8 fileformats=unix
|
||||
setlocal filetype=go
|
||||
endfunction
|
||||
|
||||
" restore fileencodings as others
|
||||
function! s:gofiletype_post()
|
||||
let &g:fileformats = s:current_fileformats
|
||||
let &g:fileencodings = s:current_fileencodings
|
||||
let &g:fileformats = s:current_fileformats
|
||||
let &g:fileencodings = s:current_fileencodings
|
||||
endfunction
|
||||
|
||||
au BufNewFile *.go setlocal filetype=go fileencoding=utf-8 fileformat=unix
|
||||
au BufRead *.go call s:gofiletype_pre()
|
||||
au BufReadPost *.go call s:gofiletype_post()
|
||||
|
||||
au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
@ -3,15 +3,28 @@ if exists("g:go_loaded_commands")
|
||||
endif
|
||||
let g:go_loaded_commands = 1
|
||||
|
||||
" go_jump_to_error defines whether we should pass the bang attribute to the
|
||||
" command or not. This is only used for mappings, because the user can't pass
|
||||
" the bang attribute to the plug mappings below. So instead of hardcoding it
|
||||
" as 0 (no '!' attribute) or 1 (with '!' attribute) we pass the user setting,
|
||||
" which by default is enabled. For commands the user has the ability to pass
|
||||
" the '!', such as :GoBuild or :GoBuild!
|
||||
if !exists("g:go_jump_to_error")
|
||||
let g:go_jump_to_error = 1
|
||||
endif
|
||||
|
||||
|
||||
" Some handy plug mappings
|
||||
nnoremap <silent> <Plug>(go-run) :<C-u>call go#cmd#Run(expand('%'))<CR>
|
||||
nnoremap <silent> <Plug>(go-build) :<C-u>call go#cmd#Build('')<CR>
|
||||
nnoremap <silent> <Plug>(go-install) :<C-u>call go#cmd#Install()<CR>
|
||||
nnoremap <silent> <Plug>(go-test) :<C-u>call go#cmd#Test(0, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-test-compile) :<C-u>call go#cmd#Test(1, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-coverage) :<C-u>call go#cmd#Coverage('')<CR>
|
||||
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#cmd#Vet()<CR>
|
||||
nnoremap <silent> <Plug>(go-run) :<C-u>call go#cmd#Run(!g:go_jump_to_error,expand('%'))<CR>
|
||||
nnoremap <silent> <Plug>(go-build) :<C-u>call go#cmd#Build(!g:go_jump_to_error,'')<CR>
|
||||
nnoremap <silent> <Plug>(go-generate) :<C-u>call go#cmd#Generate(!g:go_jump_to_error,'')<CR>
|
||||
nnoremap <silent> <Plug>(go-install) :<C-u>call go#cmd#Install(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-test) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 0, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-test-func) :<C-u>call go#cmd#TestFunc(!g:go_jump_to_error, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-test-compile) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 1, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-coverage) :<C-u>call go#cmd#Coverage(!g:go_jump_to_error, '')<CR>
|
||||
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#cmd#Vet(!g:go_jump_to_error)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-files) :<C-u>call go#tool#Files()<CR>
|
||||
nnoremap <silent> <Plug>(go-deps) :<C-u>call go#tool#Deps()<CR>
|
||||
nnoremap <silent> <Plug>(go-info) :<C-u>call go#complete#Info()<CR>
|
||||
@ -21,7 +34,6 @@ nnoremap <silent> <Plug>(go-implements) :<C-u>call go#oracle#Implements(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callees) :<C-u>call go#oracle#Callees(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callers) :<C-u>call go#oracle#Callers(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-describe) :<C-u>call go#oracle#Describe(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callgraph) :<C-u>call go#oracle#Callgraph(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-callstack) :<C-u>call go#oracle#Callstack(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-freevars) :<C-u>call go#oracle#Freevars(-1)<CR>
|
||||
nnoremap <silent> <Plug>(go-channelpeers) :<C-u>call go#oracle#ChannelPeers(-1)<CR>
|
||||
@ -49,25 +61,28 @@ command! -range=% GoImplements call go#oracle#Implements(<count>)
|
||||
command! -range=% GoCallees call go#oracle#Callees(<count>)
|
||||
command! -range=% GoDescribe call go#oracle#Describe(<count>)
|
||||
command! -range=% GoCallers call go#oracle#Callers(<count>)
|
||||
command! -range=% GoCallgraph call go#oracle#Callgraph(<count>)
|
||||
command! -range=% GoCallstack call go#oracle#Callstack(<count>)
|
||||
command! -range=% GoFreevars call go#oracle#Freevars(<count>)
|
||||
command! -range=% GoChannelPeers call go#oracle#ChannelPeers(<count>)
|
||||
command! -range=% GoReferrers call go#oracle#Referrers(<count>)
|
||||
|
||||
command! -nargs=* -complete=customlist,go#package#Complete GoOracleScope call go#oracle#Scope(<f-args>)
|
||||
|
||||
" tool
|
||||
command! -nargs=0 GoFiles echo go#tool#Files()
|
||||
command! -nargs=0 GoDeps echo go#tool#Deps()
|
||||
command! -nargs=* GoInfo call go#complete#Info()
|
||||
|
||||
" cmd
|
||||
command! -nargs=* -bang GoRun call go#cmd#Run(<bang>0,<f-args>)
|
||||
command! -nargs=* -bang GoBuild call go#cmd#Build(<bang>0,<f-args>)
|
||||
command! -nargs=* GoInstall call go#cmd#Install(<f-args>)
|
||||
command! -nargs=* GoTest call go#cmd#Test(0, <f-args>)
|
||||
command! -nargs=* GoTestCompile call go#cmd#Test(1, <f-args>)
|
||||
command! -nargs=* GoCoverage call go#cmd#Coverage(<f-args>)
|
||||
command! -nargs=0 GoVet call go#cmd#Vet()
|
||||
command! -nargs=* -bang GoGenerate call go#cmd#Generate(<bang>0,<f-args>)
|
||||
command! -nargs=* -bang GoRun call go#cmd#Run(<bang>0,<f-args>)
|
||||
command! -nargs=* -bang GoInstall call go#cmd#Install(<bang>0, <f-args>)
|
||||
command! -nargs=* -bang GoTest call go#cmd#Test(<bang>0, 0, <f-args>)
|
||||
command! -nargs=* -bang GoTestFunc call go#cmd#TestFunc(<bang>0, <f-args>)
|
||||
command! -nargs=* -bang GoTestCompile call go#cmd#Test(<bang>0, 1, <f-args>)
|
||||
command! -nargs=* -bang GoCoverage call go#cmd#Coverage(<bang>0, <f-args>)
|
||||
command! -nargs=0 -bang GoVet call go#cmd#Vet(<bang>0)
|
||||
|
||||
" -- play
|
||||
command! -nargs=0 -range=% GoPlay call go#play#Share(<count>, <line1>, <line2>)
|
||||
|
@ -26,7 +26,17 @@ function! s:GoNeosnippet()
|
||||
endif
|
||||
|
||||
let g:neosnippet#enable_snipmate_compatibility = 1
|
||||
exec 'NeoSnippetSource' globpath(&rtp, 'gosnippets/snippets/go.snip')
|
||||
|
||||
let gosnippets_dir = globpath(&rtp, 'gosnippets/snippets')
|
||||
if type(g:neosnippet#snippets_directory) == type([])
|
||||
let g:neosnippet#snippets_directory += [gosnippets_dir]
|
||||
elseif type(g:neosnippet#snippets_directory) == type("")
|
||||
if strlen(g:neosnippet#snippets_directory) > 0
|
||||
let g:neosnippet#snippets_directory = g:neosnippet#snippets_directory . "," . gosnippets_dir
|
||||
else
|
||||
let g:neosnippet#snippets_directory = gosnippets_dir
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
if g:go_snippet_engine == "ultisnips"
|
||||
|
@ -1,5 +1,5 @@
|
||||
" Check if tagbar is installed under plugins or is directly under rtp
|
||||
" this covers pathgen + Vundle/Bundle
|
||||
" this covers pathogen + Vundle/Bundle
|
||||
"
|
||||
" Also make sure the ctags command exists
|
||||
"
|
||||
@ -15,7 +15,7 @@ endif
|
||||
|
||||
|
||||
function! s:SetTagbar()
|
||||
let bin_path = go#tool#BinPath(g:go_gotags_bin)
|
||||
let bin_path = go#path#CheckBinPath(g:go_gotags_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
@ -25,7 +25,7 @@ function! s:SetTagbar()
|
||||
\ 'ctagstype' : 'go',
|
||||
\ 'kinds' : [
|
||||
\ 'p:package',
|
||||
\ 'i:imports:1',
|
||||
\ 'i:imports',
|
||||
\ 'c:constants',
|
||||
\ 'v:variables',
|
||||
\ 't:types',
|
||||
|
5
sources_non_forked/vim-go/indent/gohtmltmpl.vim
Normal file
5
sources_non_forked/vim-go/indent/gohtmltmpl.vim
Normal file
@ -0,0 +1,5 @@
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! indent/html.vim
|
@ -4,6 +4,7 @@ if exists("g:go_loaded_install")
|
||||
endif
|
||||
let g:go_loaded_install = 1
|
||||
|
||||
|
||||
" these packages are used by vim-go and can be automatically installed if
|
||||
" needed by the user with GoInstallBinaries
|
||||
let s:packages = [
|
||||
@ -17,74 +18,11 @@ let s:packages = [
|
||||
\ "github.com/jstemmer/gotags",
|
||||
\ ]
|
||||
|
||||
" Commands
|
||||
command! GoErrCheck call go#errcheck#Run()
|
||||
|
||||
" These commands are available on any filetypes
|
||||
command! GoInstallBinaries call s:GoInstallBinaries(-1)
|
||||
command! GoUpdateBinaries call s:GoInstallBinaries(1)
|
||||
command! -nargs=? -complete=dir GoPath call go#path#GoPath(<f-args>)
|
||||
|
||||
" LineEnding returns the correct line ending, based on the current fileformat
|
||||
function! LineEnding()
|
||||
if &fileformat == 'dos'
|
||||
return "\r\n"
|
||||
elseif &fileformat == 'mac'
|
||||
return "\r"
|
||||
endif
|
||||
|
||||
return "\n"
|
||||
endfunction
|
||||
|
||||
" IsWin returns 1 if current OS is Windows or 0 otherwise
|
||||
function! IsWin()
|
||||
let win = ['win16', 'win32', 'win32unix', 'win64', 'win95']
|
||||
for w in win
|
||||
if (has(w))
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" PathSep returns the appropriate path separator based on OS.
|
||||
function! PathSep()
|
||||
if IsWin()
|
||||
return ";"
|
||||
endif
|
||||
|
||||
return ":"
|
||||
endfunction
|
||||
|
||||
" DefaultGoPath returns the default GOPATH.
|
||||
" If there is only one GOPATH it returns that, otherwise it returns the first one.
|
||||
function! DefaultGoPath()
|
||||
let go_paths = split($GOPATH, PathSep())
|
||||
|
||||
if len(go_paths) == 1
|
||||
return $GOPATH
|
||||
endif
|
||||
|
||||
return go_paths[0]
|
||||
endfunction
|
||||
|
||||
" GetBinPath returns the binary path of installed go tools
|
||||
function! GetBinPath()
|
||||
let bin_path = ""
|
||||
|
||||
" check if our global custom path is set, if not check if $GOBIN is set so
|
||||
" we can use it, otherwise use $GOPATH + '/bin'
|
||||
if exists("g:go_bin_path")
|
||||
let bin_path = g:go_bin_path
|
||||
elseif $GOBIN != ""
|
||||
let bin_path = $GOBIN
|
||||
elseif $GOPATH != ""
|
||||
let bin_path = expand(DefaultGoPath() . "/bin/")
|
||||
else
|
||||
" could not find anything
|
||||
endif
|
||||
|
||||
return bin_path
|
||||
endfunction
|
||||
|
||||
" GoInstallBinaries downloads and install all necessary binaries stated in the
|
||||
" packages variable. It uses by default $GOBIN or $GOPATH/bin as the binary
|
||||
@ -103,7 +41,7 @@ function! s:GoInstallBinaries(updateBinaries)
|
||||
return
|
||||
endif
|
||||
|
||||
let go_bin_path = GetBinPath()
|
||||
let go_bin_path = go#path#BinPath()
|
||||
|
||||
" change $GOBIN so go get can automatically install to it
|
||||
let $GOBIN = go_bin_path
|
||||
@ -112,7 +50,7 @@ function! s:GoInstallBinaries(updateBinaries)
|
||||
let old_path = $PATH
|
||||
|
||||
" vim's executable path is looking in PATH so add our go_bin path to it
|
||||
let $PATH = $PATH . PathSep() .go_bin_path
|
||||
let $PATH = $PATH . go#util#PathListSep() .go_bin_path
|
||||
|
||||
" when shellslash is set on MS-* systems, shellescape puts single quotes
|
||||
" around the output string. cmd on Windows does not handle single quotes
|
||||
@ -124,6 +62,15 @@ function! s:GoInstallBinaries(updateBinaries)
|
||||
set noshellslash
|
||||
endif
|
||||
|
||||
let cmd = "go get -u -v "
|
||||
|
||||
let s:go_version = matchstr(system("go version"), '\d.\d.\d')
|
||||
|
||||
" https://github.com/golang/go/issues/10791
|
||||
if s:go_version > "1.4.0" && s:go_version < "1.5.0"
|
||||
let cmd .= "-f "
|
||||
endif
|
||||
|
||||
for pkg in s:packages
|
||||
let basename = fnamemodify(pkg, ":t")
|
||||
let binname = "go_" . basename . "_bin"
|
||||
@ -140,7 +87,8 @@ function! s:GoInstallBinaries(updateBinaries)
|
||||
echo "vim-go: ". basename ." not found. Installing ". pkg . " to folder " . go_bin_path
|
||||
endif
|
||||
|
||||
let out = system("go get -u -v ".shellescape(pkg))
|
||||
|
||||
let out = system(cmd . shellescape(pkg))
|
||||
if v:shell_error
|
||||
echo "Error installing ". pkg . ": " . out
|
||||
endif
|
||||
|
@ -52,7 +52,7 @@ if !exists("g:go_highlight_trailing_whitespace_error")
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_operators")
|
||||
let g:go_highlight_operators = 1
|
||||
let g:go_highlight_operators = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_functions")
|
||||
@ -147,7 +147,7 @@ hi def link goEscapeError Error
|
||||
syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
|
||||
syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
|
||||
syn region goRawString start=+`+ end=+`+
|
||||
syn match goFormatSpecifier /%[#0\-\ \+\*]*[vTtbcdoqxXUeEfgGsp]/ contained containedin=goString
|
||||
syn match goFormatSpecifier /%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)*[vTtbcdoqxXUeEfgGsp]/ contained containedin=goString
|
||||
|
||||
hi def link goString String
|
||||
hi def link goRawString String
|
||||
@ -236,20 +236,18 @@ hi def link goTodo Todo
|
||||
|
||||
" Operators;
|
||||
if g:go_highlight_operators != 0
|
||||
syn match goOperator /:=/
|
||||
syn match goOperator />=/
|
||||
syn match goOperator /<=/
|
||||
syn match goOperator /==/
|
||||
syn match goOperator /!=/
|
||||
syn match goOperator /+=/
|
||||
syn match goOperator /-=/
|
||||
syn match goOperator /\s>\s/
|
||||
syn match goOperator /\s<\s/
|
||||
syn match goOperator /\s+\s/
|
||||
syn match goOperator /\s-\s/
|
||||
syn match goOperator /\s\*\s/
|
||||
syn match goOperator /\s\/\s/
|
||||
syn match goOperator /\s%\s/
|
||||
" 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
|
||||
|
||||
|
15
sources_non_forked/vim-go/syntax/gohtmltmpl.vim
Normal file
15
sources_non_forked/vim-go/syntax/gohtmltmpl.vim
Normal file
@ -0,0 +1,15 @@
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
if !exists("main_syntax")
|
||||
let main_syntax = 'html'
|
||||
endif
|
||||
|
||||
runtime! syntax/gotexttmpl.vim
|
||||
runtime! syntax/html.vim
|
||||
unlet b:current_syntax
|
||||
|
||||
let b:current_syntax = "gohtmltmpl"
|
||||
|
||||
" vim:ts=4:sw=4:et
|
85
sources_non_forked/vim-go/syntax/gotexttmpl.vim
Normal file
85
sources_non_forked/vim-go/syntax/gotexttmpl.vim
Normal file
@ -0,0 +1,85 @@
|
||||
" Copyright 2011 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.
|
||||
"
|
||||
" gotexttmpl.vim: Vim syntax file for Go templates.
|
||||
|
||||
" Quit when a (custom) syntax file was already loaded
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn case match
|
||||
|
||||
" Go escapes
|
||||
syn match goEscapeOctal display contained "\\[0-7]\{3}"
|
||||
syn match goEscapeC display contained +\\[abfnrtv\\'"]+
|
||||
syn match goEscapeX display contained "\\x\x\{2}"
|
||||
syn match goEscapeU display contained "\\u\x\{4}"
|
||||
syn match goEscapeBigU display contained "\\U\x\{8}"
|
||||
syn match goEscapeError display contained +\\[^0-7xuUabfnrtv\\'"]+
|
||||
|
||||
hi def link goEscapeOctal goSpecialString
|
||||
hi def link goEscapeC goSpecialString
|
||||
hi def link goEscapeX goSpecialString
|
||||
hi def link goEscapeU goSpecialString
|
||||
hi def link goEscapeBigU goSpecialString
|
||||
hi def link goSpecialString Special
|
||||
hi def link goEscapeError Error
|
||||
|
||||
" Strings and their contents
|
||||
syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
|
||||
syn region goString contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
|
||||
syn region goRawString contained start=+`+ end=+`+
|
||||
|
||||
hi def link goString String
|
||||
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
|
||||
|
||||
hi def link goCharacter Character
|
||||
|
||||
" Integers
|
||||
syn match goDecimalInt contained "\<\d\+\([Ee]\d\+\)\?\>"
|
||||
syn match goHexadecimalInt contained "\<0x\x\+\>"
|
||||
syn match goOctalInt contained "\<0\o\+\>"
|
||||
syn match goOctalError contained "\<0\o*[89]\d*\>"
|
||||
syn cluster goInt contains=goDecimalInt,goHexadecimalInt,goOctalInt
|
||||
" Floating point
|
||||
syn match goFloat contained "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>"
|
||||
syn match goFloat contained "\<\.\d\+\([Ee][-+]\d\+\)\?\>"
|
||||
syn match goFloat contained "\<\d\+[Ee][-+]\d\+\>"
|
||||
" Imaginary literals
|
||||
syn match goImaginary contained "\<\d\+i\>"
|
||||
syn match goImaginary contained "\<\d\+\.\d*\([Ee][-+]\d\+\)\?i\>"
|
||||
syn match goImaginary contained "\<\.\d\+\([Ee][-+]\d\+\)\?i\>"
|
||||
syn match goImaginary contained "\<\d\+[Ee][-+]\d\+i\>"
|
||||
|
||||
hi def link goInt Number
|
||||
hi def link goFloat Number
|
||||
hi def link goImaginary Number
|
||||
|
||||
" Token groups
|
||||
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 /\.[^ ]*\>/
|
||||
|
||||
hi def link gotplControl Keyword
|
||||
hi def link gotplFunctions Function
|
||||
hi def link goTplVariable Special
|
||||
|
||||
syn region gotplAction start="{{" end="}}" contains=@gotplLiteral,gotplControl,gotplFunctions,gotplVariable,goTplIdentifier display
|
||||
syn region gotplAction start="\[\[" end="\]\]" contains=@gotplLiteral,gotplControl,gotplFunctions,gotplVariable display
|
||||
syn region goTplComment start="{{/\*" end="\*/}}" display
|
||||
syn region goTplComment start="\[\[/\*" end="\*/\]\]" display
|
||||
|
||||
hi def link gotplAction PreProc
|
||||
hi def link goTplComment Comment
|
||||
|
||||
let b:current_syntax = "gotexttmpl"
|
||||
|
||||
" vim:ts=4:sw=4:et
|
Reference in New Issue
Block a user