1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 09:35:01 +08:00

Updated plugins

This commit is contained in:
amix
2016-08-02 14:48:32 +02:00
parent 64a81818ee
commit 61a22e9f3e
39 changed files with 1372 additions and 782 deletions

View File

@ -1,17 +1,45 @@
## 1.8 (unplanned)
## Unplanned
IMPROVEMENTS:
* **guru** uses now the `-modified` flag, which allows us use guru on modified
buffers as well. This affects all commands where `guru` is used. Such as
`:GoDef`, `:GoReferrers`, etc.. [gh-944]
* Cleanup and improve documentation [gh-987]
BUG FIXES:
* Fix system calls on Windows [gh-988]
## 1.8 (July 31, 2016)
FEATURES:
* If you open a new buffer with a Go filename it get automatically populated based on the directory. If there are no Go files a simple main package is created, otherwise the file will include the package declaration line based on the package in the current directory. Checkout the demo to see it in action: https://twitter.com/fatih/status/748333086643994624. This is enabled by default. Can be disabled with `let g:go_template_autocreate = 0`. You can use your own template with `let g:go_template_file = "foo.go"` and putting the file under the `templates/` folder. [gh-918]
* The snippet expansion `json` is now much more smarter. It pre populates the placeholder according to the first word and it also applies `snake_case` or `camelCase` conversion. Checkout the demo to see it in action: https://github.com/fatih/vim-go/pull/927 [gh-927]
* **`:GoSameIds`** support. When called highlights all same identifiers in the current file. Can be also enabled to highlight identifiers automatically. Checkout the demo to see it in action: https://twitter.com/fatih/status/753673709278339072. [gh-936]
* New **`:GoAddTags`** command that adds field tags for the fields of a struct automatically based on the field names. Checkout the demo to see it in action: https://twitter.com/fatih/status/759822857773907968 [gh-971]
* The snippet expansion `json` is now much more smarter. It pre populates the placeholder according to the first word and it also applies `snake_case` or `camelCase` conversion. Together with `:GoAddTags` it gives `vim-go` users flexible ways of populating a field tag. Checkout the demo to see it in action: https://twitter.com/fatih/status/754477622042689536 [gh-927]
* New **`:GoSameIds`** command. When called highlights all same identifiers in the current file. Can be also enabled to highlight identifiers automatically (with `:GoSameIdsAutoToggle` or `g:go_auto_sameids`). Checkout the demo to see it in action: https://twitter.com/fatih/status/753673709278339072. [gh-936]
* New **`:GoWhicherrs`** command. It shows all possible values of the selected error variable. [gh-948]
* Add new `errp` snippet to expand an `if err != nil { panic() }` clause [gh-926]
* If you open a new buffer with a Go filename it get automatically populated based on the directory. If there are no Go files a simple main package is created, otherwise the file will include the package declaration line based on the package in the current directory. Checkout the demo to see it in action: https://twitter.com/fatih/status/748333086643994624. This is enabled by default. Can be disabled with `let g:go_template_autocreate = 0`. You can use your own template with `let g:go_template_file = "foo.go"` and putting the file under the `templates/` folder. [gh-918]
* Added new toggle commands to enable/disable feature that run for your
automatic. For example if you have `let g:go_auto_type_info = 1` enabled, you
can now easily enable/disable it on the fly. Support added with the following
commands: `:GoAutoTypeInfoToggle`, `:GoFmtAutoSaveToggle`,
`:GoAsmFmtAutoSaveToggle`, `:GoMetalinterAutoSaveToggle`,
`:GoTemplateAutoCreateToggle` [gh-945]
IMPROVEMENTS:
* `:GoDoc` accepts arguments now which are passed directly to `godoc`. So usages like `:GoDoc flag` works again (it was changed in previous versions [gh-894]
* `:GoDef` works now for modified files as well [gh-910]
* Internal: pass filename to the `--srcdir` flag to enable upcoming `goimports` features [gh-957]
* Internal: fix indentations on all files to **2-spaces/no tabs**. This is now the default vim-go style across all VimL files [gh-915]
* Internal: autocmd settings can be now dynamically enabled/disabled [gh-939]
* Internal: automatically detect `GOPATH` for :GoInstall [gh-980]
* Internal: shell executions uses now by default `sh` and then resets it back to the user preference. [gh-967]
* Syntax: improved syntax highglighting performance for methods, fields, structs and interface type declarations [gh-917]
* Syntax: moved `:GoCoverage` highlight definition into go's syntax file for more customizability [gh-962]
BUG FIXES:
@ -21,6 +49,7 @@ BUG FIXES:
* Fix `:GoFmt` not picking up `-srcdir` if the command was set to use `goimports` [gh-904]
* Fix `:GoTestCompile` to not leave behind artifacts if the cwd and the test files's directory do not match [gh-909]
* Fix `:GoDocBrowser` to not fail if godoc doesn't exist [gh-920]
* Fix `:GoFmt` to not change the permissions of saved file. Now original file permissions are restored [gh-922]
BACKWARDS INCOMPATIBILITIES:

View File

@ -50,10 +50,16 @@ disabled/enabled easily.
in their own new terminal. (beta)
* Alternate between implementation and test code with `:GoAlternate`
Checkout the official [tutorial](https://github.com/fatih/vim-go-tutorial)
that goes literally over all features and shows many tips and tricks. It shows
how to install vim-go and explains many unknown use cases. Recommended for
beginners as well as advanced users: https://github.com/fatih/vim-go-tutorial
## Install
Master branch is supposed to be a development branch. So stuff here can break and change.
Please try use always the [latest release](https://github.com/fatih/vim-go/releases/latest)
Master branch is supposed to be a development branch. So stuff here can break
and change. Please try use always the [latest
release](https://github.com/fatih/vim-go/releases/latest)
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
@ -69,6 +75,8 @@ command.
* `NeoBundle 'fatih/vim-go'`
* [Vundle](https://github.com/gmarik/vundle)
* `Plugin 'fatih/vim-go'`
* [Vim packages](http://vimhelp.appspot.com/repeat.txt.html#packages) (since Vim 7.4.1528)
* `git clone https://github.com/fatih/vim-go.git ~/.vim/pack/plugins/start/vim-go`
Please be sure all necessary binaries are installed (such as `gocode`, `godef`,
`goimports`, etc.). You can easily install them with the included
@ -84,7 +92,8 @@ installed binaries.
completion (completion by type) install:
[neocomplete](https://github.com/Shougo/neocomplete.vim) for Vim or
[deoplete](https://github.com/Shougo/deoplete.nvim) and
[deoplete-go](https://github.com/zchee/deoplete-go) for NeoVim
[deoplete-go](https://github.com/zchee/deoplete-go) for NeoVim or
[SimpleAutoCmplPop](https://github.com/roxma/SimpleAutoComplPop)
* To display source code tag information on a sidebar install
[tagbar](https://github.com/majutsushi/tagbar).
* For snippet features install:
@ -270,7 +279,6 @@ To resolve this:
let g:go_list_type = "quickfix"
```
## More info
Check out the [Wiki](https://github.com/fatih/vim-go/wiki) page for more
@ -282,8 +290,12 @@ other [various pieces](https://github.com/fatih/vim-go/wiki) of information.
## Donation
People have asked for this for a long time, now you can be a fully supporter by
[being a patron](https://www.patreon.com/fatih)! This is fully optional and is
just a way to support vim-go's ongoing development directly. Thanks!
[being a patron](https://www.patreon.com/fatih)!
By being a patron, you are enabling vim-go to grow and mature, helping me to
invest in bug fixes, new documentation, and improving both current and future
features. It's completely optional and is just a direct way to support Vim-go's
ongoing development. Thanks!
[https://www.patreon.com/fatih](https://www.patreon.com/fatih)

View File

@ -41,7 +41,11 @@ function! go#asmfmt#Format()
" Replace the current file with the temp file; then reload the buffer.
let old_fileformat = &fileformat
" save old file permissions
let original_fperm = getfperm(expand('%'))
call rename(l:tmpname, expand('%'))
" restore old file permissions
call setfperm(expand('%'), original_fperm)
silent edit!
let &fileformat = old_fileformat
let &syntax = &syntax
@ -51,4 +55,15 @@ function! go#asmfmt#Format()
call winrestview(l:curw)
endfunction
function! go#asmfmt#ToggleAsmFmtAutoSave()
if get(g:, "go_asmfmt_autosave", 1)
let g:go_asmfmt_autosave = 0
call go#util#EchoProgress("auto asmfmt disabled")
return
end
let g:go_asmfmt_autosave = 1
call go#util#EchoProgress("auto asmfmt enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -143,6 +143,8 @@ endfunction
" 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 old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let default_makeprg = &makeprg
" :make expands '%' and '#' wildcards, so they must also be escaped
@ -179,6 +181,7 @@ function! go#cmd#Install(bang, ...)
redraws! | echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
endif
let $GOPATH = old_gopath
let &makeprg = default_makeprg
endfunction

View File

@ -153,4 +153,16 @@ function! go#complete#Complete(findstart, base)
endif
endf
function! go#complete#ToggleAutoTypeInfo()
if get(g:, "go_auto_type_info", 0)
let g:go_auto_type_info = 0
call go#util#EchoProgress("auto type info disabled")
return
end
let g:go_auto_type_info = 1
call go#util#EchoProgress("auto type info enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -134,9 +134,9 @@ endfunction
" Generates matches to be added to matchaddpos for the given coverage profile
" block
function! go#coverage#genmatch(cov)
let color = 'covered'
let color = 'goCoverageCovered'
if a:cov.cnt == 0
let color = 'uncover'
let color = 'goCoverageUncover'
endif
let matches = []
@ -195,12 +195,12 @@ function! go#coverage#overlay(file)
" contains matches for matchaddpos()
let matches = []
" first mark all lines as normaltext. We use a custom group to not
" first mark all lines as goCoverageNormalText. We use a custom group to not
" interfere with other buffers highlightings. Because the priority is
" lower than the cover and uncover matches, it'll be overriden.
let cnt = 1
while cnt <= line('$')
call add(matches, {'group': 'normaltext', 'pos': [cnt], 'priority': 1})
call add(matches, {'group': 'goCoverageNormalText', 'pos': [cnt], 'priority': 1})
let cnt += 1
endwhile
@ -234,9 +234,6 @@ function! go#coverage#overlay(file)
endfor
syntax manual
highlight normaltext term=bold ctermfg=darkgrey guifg=#75715E
highlight covered term=bold ctermfg=green guifg=#A6E22E
highlight uncover term=bold ctermfg=red guifg=#F92672
" clear the matches if we leave the buffer
autocmd BufWinLeave <buffer> call go#coverage#Clear()

View File

@ -6,12 +6,6 @@ function! go#def#Jump(mode)
let $GOPATH = go#path#Detect()
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
if &modified
" Write current unsaved buffer to a temp file and use the modified content
let l:tmpname = tempname()
call writefile(getline(1, '$'), l:tmpname)
let fname = l:tmpname
endif
" so guru right now is slow for some people. previously we were using
" godef which also has it's own quirks. But this issue come up so many
@ -19,6 +13,13 @@ function! go#def#Jump(mode)
" covers all edge cases, but now anyone can switch to godef if they wish
let bin_name = get(g:, 'go_def_mode', 'guru')
if bin_name == 'godef'
if &modified
" Write current unsaved buffer to a temp file and use the modified content
let l:tmpname = tempname()
call writefile(getline(1, '$'), l:tmpname)
let fname = l:tmpname
endif
let bin_path = go#path#CheckBinPath("godef")
if empty(bin_path)
let $GOPATH = old_gopath
@ -31,31 +32,45 @@ function! go#def#Jump(mode)
" jump_to_declaration() function can parse it. This makes it
" compatible with guru definition as well too
let out = join(split(out, '\n'), ':')
if exists("l:tmpname")
call delete(l:tmpname)
endif
elseif bin_name == 'guru'
let flags = ""
let in = ""
if &modified
let sep = go#util#LineEnding()
let content = join(getline(1, '$'), sep)
let in = fname . "\n" . strlen(content) . "\n" . content
let flags .= " -modified"
endif
let bin_path = go#path#CheckBinPath("guru")
if empty(bin_path)
let $GOPATH = old_gopath
return
endif
let flags = ""
if exists('g:go_guru_tags')
let tags = get(g:, 'go_guru_tags')
let flags = printf(" -tags %s", tags)
let flags .= printf(" -tags %s", tags)
endif
let fname = shellescape(fname.':#'.go#util#OffsetCursor())
let command = printf("%s %s definition %s", bin_path, flags, fname)
let out = go#util#System(command)
if &modified
let out = go#util#System(command, in)
else
let out = go#util#System(command)
endif
else
call go#util#EchoError('go_def_mode value: '. bin_name .' is not valid. Valid values are: [godef, guru]')
return
endif
if exists("l:tmpname")
call delete(l:tmpname)
endif
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
@ -98,24 +113,29 @@ function! s:jump_to_declaration(out, mode)
" modes of switchbuf which we need based on the split mode
let old_switchbuf = &switchbuf
" jump to existing buffer if, 1. we have enabled it, 2. the buffer is loaded
" and 3. there is buffer window number we switch to
if get(g:, 'go_def_reuse_buffer', 0) && bufloaded(filename) != 0 && bufwinnr(filename) != -1
" jumpt to existing buffer if it exists
execute bufwinnr(filename) . 'wincmd w'
elseif a:mode == "tab"
let &switchbuf = "usetab"
if bufloaded(filename) == 0
tab split
let l:fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
if filename != l:fname
" jump to existing buffer if, 1. we have enabled it, 2. the buffer is loaded
" and 3. there is buffer window number we switch to
if get(g:, 'go_def_reuse_buffer', 0) && bufloaded(filename) != 0 && bufwinnr(filename) != -1
" jumpt to existing buffer if it exists
execute bufwinnr(filename) . 'wincmd w'
elseif a:mode == "tab"
let &switchbuf = "usetab"
if bufloaded(filename) == 0
tab split
endif
elseif a:mode == "split"
split
elseif a:mode == "vsplit"
vsplit
elseif &modified
split
endif
elseif a:mode == "split"
split
elseif a:mode == "vsplit"
vsplit
endif
" open the file and jump to line and column
exec 'edit '.filename
" open the file and jump to line and column
exec 'edit '.filename
endif
call cursor(line, col)
" also align the line to middle of the view

View File

@ -43,7 +43,7 @@ if !exists("g:go_fmt_experimental")
let g:go_fmt_experimental = 0
endif
" we have those problems :
" 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
"
@ -124,7 +124,7 @@ function! go#fmt#Format(withGoimport)
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
let ssl_save = &shellslash
set noshellslash
let command = command . '-srcdir ' . shellescape(expand("%:p:h"))
let command = command . '-srcdir ' . shellescape(expand("%:p"))
let &shellslash = ssl_save
endif
endif
@ -149,7 +149,15 @@ function! go#fmt#Format(withGoimport)
" Replace current file with temp file, then reload buffer
let old_fileformat = &fileformat
if exists("*getfperm")
" save old file permissions
let original_fperm = getfperm(expand('%'))
endif
call rename(l:tmpname, expand('%'))
" restore old file permissions
if exists("*setfperm") && original_fperm != ''
call setfperm(expand('%'), original_fperm)
endif
silent edit!
let &fileformat = old_fileformat
let &syntax = &syntax
@ -207,4 +215,14 @@ function! go#fmt#Format(withGoimport)
endif
endfunction
function! go#fmt#ToggleFmtAutoSave()
if get(g:, "go_fmt_autosave", 1)
let g:go_fmt_autosave = 0
call go#util#EchoProgress("auto fmt disabled")
return
end
let g:go_fmt_autosave = 1
call go#util#EchoProgress("auto fmt enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -1,5 +1,6 @@
" guru.vim -- Vim integration for the Go guru.
func! s:RunGuru(mode, format, selected, needs_scope) range abort
"return with a warning if the binary doesn't exist
let bin_path = go#path#CheckBinPath("guru")
@ -7,18 +8,6 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
return {'err': "bin path not found"}
endif
let filename = fnamemodify(expand("%"), ':p:gs?\\?/?')
if !filereadable(filename)
" this might happen for new buffers which are not written yet
return {'err': "file does not exist"}
endif
if &modified
" Write current unsaved buffer to a temp file and use the modified content
let l:tmpname = tempname()
call writefile(getline(1, '$'), l:tmpname)
let filename = l:tmpname
endif
let dirname = expand('%:p:h')
let pkg = go#package#ImportPath(dirname)
@ -30,6 +19,15 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
" start constructing the 'command' variable
let command = bin_path
let filename = fnamemodify(expand("%"), ':p:gs?\\?/?')
let in = ""
if &modified
let sep = go#util#LineEnding()
let content = join(getline(1, '$'), sep )
let in = filename . "\n" . strlen(content) . "\n" . content
let command .= " -modified"
endif
" enable outputting in json format
if a:format == "json"
let command .= " -json"
@ -72,8 +70,8 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
let scopes = go#util#Shelllist(scopes)
" guru expect a comma-separated list of patterns, construct it
let scope = join(scopes, ",")
let command .= printf(" -scope %s", scope)
let l:scope = join(scopes, ",")
let command .= printf(" -scope %s", l:scope)
endif
let pos = printf("#%s", go#util#OffsetCursor())
@ -91,16 +89,18 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
if a:mode !=# 'what'
if a:needs_scope
call go#util#EchoProgress("analysing with scope ". l:scope . " ...")
elseif a:mode !=# 'what'
" the query might take time, let us give some feedback
call go#util#EchoProgress("analysing ...")
endif
" run, forrest run!!!
let out = go#util#System(command)
if exists("l:tmpname")
call delete(l:tmpname)
if &modified
let out = go#util#System(command, in)
else
let out = go#util#System(command)
endif
let $GOPATH = old_gopath
@ -176,6 +176,23 @@ function! go#guru#Tags(...)
endif
endfunction
" Report the possible constants, global variables, and concrete types that may
" appear in a value of type error
function! go#guru#Whicherrs(selected)
let out = s:RunGuru('whicherrs', 'plain', a:selected, 1)
if has_key(out, 'err')
call go#util#EchoError(out.err)
return
endif
if empty(out.out)
call go#util#EchoSuccess("no error variables found. Try to change the scope with :GoGuruScope")
return
endif
call s:loclistSecond(out.out)
endfunction
" Show 'implements' relation for selected package
function! go#guru#Implements(selected)
let out = s:RunGuru('implements', 'plain', a:selected, 1)
@ -271,16 +288,11 @@ function! go#guru#Referrers(selected)
endfunction
function! go#guru#What(selected)
" nvim doesn't have JSON support, though they work on it:
" https://github.com/neovim/neovim/pull/4131
if has('nvim')
return {'err': "GoWhat is not supported in Neovim"}
endif
" json_encode() and friends are introduced with this patch
" https://groups.google.com/d/msg/vim_dev/vLupTNhQhZ8/cDGIk0JEDgAJ
if !has('patch-7.4.1304')
return {'err': "GoWhat is supported with Vim version 7.4-1304 or later"}
" json_encode() and friends are introduced with this patch (7.4.1304)
" vim: https://groups.google.com/d/msg/vim_dev/vLupTNhQhZ8/cDGIk0JEDgAJ
" nvim: https://github.com/neovim/neovim/pull/4131
if !exists("*json_decode")
return {'err': "GoWhat is not supported due old version of Vim/Neovim"}
endif
let out = s:RunGuru('what', 'json', a:selected, 0)
@ -297,10 +309,29 @@ function! go#guru#What(selected)
return result
endfunction
function! go#guru#AutoToogleSameIds()
if get(g:, "go_auto_sameids", 0)
call go#util#EchoProgress("sameids auto highlighting disabled")
call go#guru#ClearSameIds()
let g:go_auto_sameids = 0
return
endif
call go#util#EchoSuccess("sameids auto highlighting enabled")
let g:go_auto_sameids = 1
endfunction
function! go#guru#SameIds(selected)
call go#guru#ClearSameIds()
" we use matchaddpos() which was introduce with 7.4.330, be sure we have
" it: http://ftp.vim.org/vim/patches/7.4/7.4.330
if !exists("*matchaddpos")
call go#util#EchoError("GoSameIds is supported with Vim version 7.4-330 or later")
return
endif
let result = go#guru#What(a:selected)
call go#guru#ClearSameIds() " run after calling guru to reduce flicker.
if has_key(result, 'err') && !get(g:, 'go_auto_sameids', 0)
" only echo if it's called via `:GoSameIds, but not if it's in automode
call go#util#EchoError(result.err)
@ -327,8 +358,6 @@ function! go#guru#SameIds(selected)
return
endif
hi goSameId term=bold cterm=bold ctermbg=white ctermfg=black
let same_ids = result['sameids']
" highlight the lines
for item in same_ids
@ -346,4 +375,12 @@ function! go#guru#ClearSameIds()
endfor
endfunction
function! go#guru#ToggleSameIds(selected)
if len(getmatches()) != 0
call go#guru#ClearSameIds()
else
call go#guru#SameIds(a:selected)
endif
endfunction
" vim: sw=2 ts=2 et

View File

@ -71,12 +71,12 @@ endif
function! s:root_dirs()
let dirs = []
let root = go#util#GOROOT()
let root = go#util#goroot()
if root !=# '' && isdirectory(root)
call add(dirs, root)
endif
let paths = map(split(go#util#GOPATH(), go#util#PathListSep()), "substitute(v:val, '\\\\', '/', 'g')")
let paths = map(split(go#util#gopath(), go#util#PathListSep()), "substitute(v:val, '\\\\', '/', 'g')")
if go#util#ShellError()
return []
endif
@ -91,7 +91,7 @@ endfunction
function! s:go_packages(dirs)
let pkgs = []
for d in a:dirs
let pkg_root = expand(d . '/pkg/' . go#util#OSARCH())
let pkg_root = expand(d . '/pkg/' . go#util#osarch())
call extend(pkgs, split(globpath(pkg_root, '**/*.a', 1), "\n"))
endfor
return map(pkgs, "fnamemodify(v:val, ':t:r')")

View File

@ -196,4 +196,15 @@ function! go#lint#Errcheck(...) abort
endfunction
function! go#lint#ToggleMetaLinterAutoSave()
if get(g:, "go_metalinter_autosave", 0)
let g:go_metalinter_autosave = 0
call go#util#EchoProgress("auto metalinter disabled")
return
end
let g:go_metalinter_autosave = 1
call go#util#EchoProgress("auto metalinter enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -33,7 +33,7 @@ function! go#package#Paths()
if !exists("s:goroot")
if executable('go')
let s:goroot = substitute(go#util#System('go env GOROOT'), '\n', '', 'g')
let s:goroot = go#util#goroot()
if go#util#ShellError() != 0
echomsg '''go env GOROOT'' failed'
endif

View File

@ -10,13 +10,13 @@ function! go#template#create()
let l:package_name = go#tool#PackageName()
" if we can't figure out any package name(no Go files or non Go package
" files) from the directory create the template
" files) from the directory create the template
if l:package_name == -1
let l:template_file = get(g:, 'go_template_file', "hello_world.go")
let l:template_path = go#util#Join(l:root_dir, "templates", l:template_file)
exe '0r ' . l:template_path
exe '0r ' . fnameescape(l:template_path)
$delete _
else
else
let l:content = printf("package %s", l:package_name)
call append(0, l:content)
$delete _
@ -28,4 +28,15 @@ function! go#template#create()
execute cd . fnameescape(dir)
endfunction
function! go#template#ToggleAutoCreate()
if get(g:, "go_template_autocreate", 1)
let g:go_template_autocreate = 0
call go#util#EchoProgress("auto template create disabled")
return
end
let g:go_template_autocreate = 1
call go#util#EchoProgress("auto template create enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -44,7 +44,7 @@ function! go#tool#Imports()
endfunction
function! go#tool#PackageName()
let command = "go list -f '{{.Name}}'"
let command = "go list -f \"{{.Name}}\""
let out = go#tool#ExecuteInDir(command)
if go#util#ShellError() != 0
return -1

View File

@ -43,27 +43,26 @@ function! go#util#IsWin()
return 0
endfunction
function! go#util#GOARCH()
function! go#util#goarch()
return substitute(go#util#System('go env GOARCH'), '\n', '', 'g')
endfunction
function! go#util#GOOS()
function! go#util#goos()
return substitute(go#util#System('go env GOOS'), '\n', '', 'g')
endfunction
function! go#util#GOROOT()
function! go#util#goroot()
return substitute(go#util#System('go env GOROOT'), '\n', '', 'g')
endfunction
function! go#util#GOPATH()
function! go#util#gopath()
return substitute(go#util#System('go env GOPATH'), '\n', '', 'g')
endfunction
function! go#util#OSARCH()
return go#util#GOOS() . '_' . go#util#GOARCH()
function! go#util#osarch()
return go#util#goos() . '_' . go#util#goarch()
endfunction
"Check if has vimproc
function! s:has_vimproc()
if !exists('g:go#use_vimproc')
@ -92,8 +91,20 @@ else
let s:vim_shell_error = ''
endif
" System runs a shell command. It will reset the shell to /bin/sh for Unix-like
" systems if it is executable.
function! go#util#System(str, ...)
return call(s:vim_system, [a:str] + a:000)
let l:shell = &shell
if !go#util#IsWin() && executable('/bin/sh')
let &shell = '/bin/sh'
endif
try
let l:output = call(s:vim_system, [a:str] + a:000)
return l:output
finally
let &shell = l:shell
endtry
endfunction
function! go#util#ShellError()
@ -228,24 +239,68 @@ function! go#util#camelcase(word)
endif
endfunction
function! go#util#AddTags(line1, line2, ...)
" default is json
let l:keys = ["json"]
if a:0
let l:keys = a:000
endif
let l:line1 = a:line1
let l:line2 = a:line2
" If we're inside a struct and just call this function let us add the tags
" to all fields
" TODO(arslan): I don't like using patterns. Check if we can move it to
" `motion` and do it via AST based position
let ln1 = searchpair('struct {', '', '}', 'bcnW')
if ln1 == 0
echon "vim-go: " | echohl ErrorMsg | echon "cursor is outside the struct" | echohl None
return
endif
" searchpair only returns a single position
let ln2 = search('}', "cnW")
" if no range is given we apply for the whole struct
if l:line1 == l:line2
let l:line1 = ln1 + 1
let l:line2 = ln2 - 1
endif
for line in range(l:line1, l:line2)
" get the field name (word) that are not part of a commented line
let l:matched = matchstr(getline(line), '\(\/\/.*\)\@<!\w\+')
if empty(l:matched)
continue
endif
let word = go#util#snippetcase(l:matched)
let tags = map(copy(l:keys), 'printf("%s:%s", v:val,"\"'. word .'\"")')
let updated_line = printf("%s `%s`", getline(line), join(tags, " "))
" finally, update the line inplace
call setline(line, updated_line)
endfor
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
redraw | 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
redraw | 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
redraw | 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
redraw | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None
endfunction
" vim: sw=2 ts=2 et

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ command! -nargs=? GoRename call go#rename#Rename(<bang>0,<f-args>)
" -- guru
command! -nargs=* -complete=customlist,go#package#Complete GoGuruScope call go#guru#Scope(<f-args>)
command! -range=% GoImplements call go#guru#Implements(<count>)
command! -range=% GoWhicherrs call go#guru#Whicherrs(<count>)
command! -range=% GoCallees call go#guru#Callees(<count>)
command! -range=% GoDescribe call go#guru#Describe(<count>)
command! -range=% GoCallers call go#guru#Callers(<count>)
@ -12,13 +13,20 @@ command! -range=% GoFreevars call go#guru#Freevars(<count>)
command! -range=% GoChannelPeers call go#guru#ChannelPeers(<count>)
command! -range=% GoReferrers call go#guru#Referrers(<count>)
command! -nargs=? GoGuruTags call go#guru#Tags(<f-args>)
command! -nargs=* -range GoAddTags call go#util#AddTags(<line1>, <line2>, <f-args>)
command! -range=% GoSameIds call go#guru#SameIds(<count>)
command! -range=0 GoSameIdsClear call go#guru#ClearSameIds()
command! -range=% GoSameIdsToggle call go#guru#ToggleSameIds(<count>)
command! -range=0 GoSameIdsAutoToggle call go#guru#AutoToogleSameIds()
" -- tool
command! -nargs=0 GoFiles echo go#tool#Files()
command! -nargs=0 GoDeps echo go#tool#Deps()
command! -nargs=* GoInfo call go#complete#Info(0)
command! -nargs=0 GoAutoTypeInfoToggle call go#complete#ToggleAutoTypeInfo()
" -- cmd
command! -nargs=* -bang GoBuild call go#cmd#Build(<bang>0,<f-args>)
@ -50,8 +58,12 @@ command! -nargs=* -range -complete=customlist,go#package#Complete GoDocBrowser c
" -- fmt
command! -nargs=0 GoFmt call go#fmt#Format(-1)
command! -nargs=0 GoFmtAutoSaveToggle call go#fmt#ToggleFmtAutoSave()
command! -nargs=0 GoImports call go#fmt#Format(1)
" -- asmfmt
command! -nargs=0 GoAsmFmtAutoSaveToggle call go#asmfmt#ToggleAsmFmtAutoSave()
" -- import
command! -nargs=? -complete=customlist,go#package#Complete GoDrop call go#import#SwitchImport(0, '', <f-args>, '')
command! -nargs=1 -bang -complete=customlist,go#package#Complete GoImport call go#import#SwitchImport(1, '', <f-args>, '<bang>')
@ -59,6 +71,7 @@ command! -nargs=* -bang -complete=customlist,go#package#Complete GoImportAs call
" -- linters
command! -nargs=* GoMetaLinter call go#lint#Gometa(0, <f-args>)
command! -nargs=0 GoMetalinterAutoSaveToggle call go#lint#ToggleMetaLinterAutoSave()
command! -nargs=* GoLint call go#lint#Golint(<f-args>)
command! -nargs=* -bang GoVet call go#lint#Vet(<bang>0, <f-args>)
command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck(<f-args>)
@ -75,4 +88,7 @@ endif
" -- impl
command! -nargs=* -buffer -complete=customlist,go#impl#Complete GoImpl call go#impl#Impl(<f-args>)
" -- template
command! -nargs=0 GoTemplateAutoCreateToggle call go#template#ToggleAutoCreate()
" vim: sw=2 ts=2 et

View File

@ -44,6 +44,8 @@ xnoremap <silent> <Plug>(go-freevars) :<C-u>call go#guru#Freevars(0)<CR>
nnoremap <silent> <Plug>(go-channelpeers) :<C-u>call go#guru#ChannelPeers(-1)<CR>
nnoremap <silent> <Plug>(go-referrers) :<C-u>call go#guru#Referrers(-1)<CR>
nnoremap <silent> <Plug>(go-sameids) :<C-u>call go#guru#SameIds(-1)<CR>
nnoremap <silent> <Plug>(go-whicherrs) :<C-u>call go#guru#Whicherrs(-1)<CR>
nnoremap <silent> <Plug>(go-sameids-toggle) :<C-u>call go#guru#ToggleSameIds(-1)<CR>
nnoremap <silent> <Plug>(go-rename) :<C-u>call go#rename#Rename(!g:go_jump_to_error)<CR>

View File

@ -189,6 +189,11 @@ snippet json "\`json:key\`"
\`json:"${1:`!v go#util#snippetcase(matchstr(getline("."), '\w\+'))`}"\`
endsnippet
# yaml field tag
snippet yaml "\`yaml:key\`"
\`yaml:"${1:`!v go#util#snippetcase(matchstr(getline("."), '\w\+'))`}"\`
endsnippet
# fallthrough
snippet ft "fallthrough"
fallthrough

View File

@ -162,6 +162,11 @@ snippet json
abbr \`json:key\`
\`json:"${1:keyName}"\`
# yaml snippet
snippet yaml
abbr \`yaml:key\`
\`yaml:"${1:keyName}"\`
# fallthrough
snippet ft
abbr fallthrough

View File

@ -27,7 +27,6 @@ command! GoInstallBinaries call s:GoInstallBinaries(-1)
command! GoUpdateBinaries call s:GoInstallBinaries(1)
command! -nargs=? -complete=dir GoPath call go#path#GoPath(<f-args>)
" GoInstallBinaries downloads and install all necessary binaries stated in the
" packages variable. It uses by default $GOBIN or $GOPATH/bin as the binary
" target install directory. GoInstallBinaries doesn't install binaries if they
@ -143,44 +142,64 @@ function! s:echo_go_info()
redraws! | echo "vim-go: " | echohl Function | echon item.info | echohl None
endfunction
function! s:auto_type_info()
" GoInfo automatic update
if get(g:, "go_auto_type_info", 0)
call go#complete#Info(1)
endif
endfunction
function! s:auto_sameids()
" GoSameId automatic update
if get(g:, "go_auto_sameids", 0)
call go#guru#SameIds(-1)
endif
endfunction
function! s:fmt_autosave()
" Go code formatting on save
if get(g:, "go_fmt_autosave", 1)
call go#fmt#Format(-1)
endif
endfunction
function! s:asmfmt_autosave()
" Go asm formatting on save
if get(g:, "go_asmfmt_autosave", 1)
call go#asmfmt#Format()
endif
endfunction
function! s:metalinter_autosave()
" run gometalinter on save
if get(g:, "go_metalinter_autosave", 0)
call go#lint#Gometa(1)
endif
endfunction
function! s:template_autocreate()
" create new template from scratch
if get(g:, "go_template_autocreate", 1)
call go#template#create()
endif
endfunction
augroup vim-go
autocmd!
" GoInfo automatic update
if get(g:, "go_auto_type_info", 0)
autocmd CursorHold *.go nested call go#complete#Info(1)
endif
" GoSameId automatic update
if get(g:, "go_auto_sameids", 0)
autocmd CursorMoved *.go nested call go#guru#SameIds(-1)
endif
autocmd CursorHold *.go call s:auto_type_info()
autocmd CursorHold *.go call s:auto_sameids()
" 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()
autocmd CompleteDone *.go 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
" create new template from scratch
if get(g:, "go_template_autocreate", 1)
autocmd BufNewFile *.go call go#template#create()
endif
autocmd BufWritePre *.go call s:fmt_autosave()
autocmd BufWritePre *.s call s:asmfmt_autosave()
autocmd BufWritePost *.go call s:metalinter_autosave()
autocmd BufNewFile *.go call s:template_autocreate()
augroup END
" vim: sw=2 ts=2 et

View File

@ -271,6 +271,7 @@ hi def link goSpaceError Error
syn keyword goTodo contained NOTE
hi def link goTodo Todo
syn match goVarArgs /\.\.\./
" Operators;
if g:go_highlight_operators != 0
@ -285,9 +286,9 @@ if g:go_highlight_operators != 0
" match remaining two-char operators: := && || <- ++ --
syn match goOperator /:=\|||\|<-\|++\|--/
" match ...
syn match goOperator /\.\.\./
hi def link goPointerOperator Operator
hi def link goPointerOperator goOperator
hi def link goVarArgs goOperator
endif
hi def link goOperator Operator
@ -306,14 +307,13 @@ hi def link goFunction Function
" Methods;
if g:go_highlight_methods != 0
syn match goMethod /\.\w\+(/hs=s+1,he=e-1
syn match goMethod /\.\w\+\ze(/hs=s+1
endif
hi def link goMethod Type
" Fields;
if g:go_highlight_fields != 0
syn match goVarArgs /\.\.\.\w\+\>/
syn match goField /\.\a\+\([\ \n\r\:\)\[]\)\@=/hs=s+1
syn match goField /\.\w\+\([\ \n\r\:\)\[,]\)\@=/hs=s+1
endif
hi def link goField Identifier
@ -366,7 +366,13 @@ if g:go_highlight_build_constraints != 0
hi def link goPackageComment Comment
endif
hi def link goSameId IncSearch
" :GoSameIds
hi def goSameId term=bold cterm=bold ctermbg=white ctermfg=black
" :GoCoverage commands
hi def link goCoverageNormalText Comment
hi def goCoverageCovered ctermfg=green guifg=#A6E22E
hi def goCoverageUncover ctermfg=red guifg=#F92672
" Search backwards for a global declaration to start processing the syntax.
"syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/