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:
Amir Salihefendic
2018-07-04 12:53:25 +02:00
parent 993ed55304
commit 2f164fee9b
70 changed files with 2044 additions and 761 deletions

View File

@ -2,6 +2,27 @@
FEATURES:
* Add **:GoIfErr** command together with the `<Plug>(go-iferr)` plug key to
create a custom mapping. This command generates an `if err != nil { return ... }`
automatically which infer the type of return values and the numbers.
For example:
```
func doSomething() (string, error) {
f, err := os.Open("file")
}
```
Becomes:
```
func doSomething() (string, error) {
f, err := os.Open("file")
if err != nil {
return "", err
}
}
```
* Two new text objects has been added:
* `ic` (inner comment) selects the content of the comment, excluding the start/end markers (i.e: `//`, `/*`)
* `ac` (a comment) selects the content of the whole commment block, including markers

View File

@ -114,10 +114,16 @@ endfunction
" Run runs the current file (and their dependencies if any) in a new terminal.
function! go#cmd#RunTerm(bang, mode, files) abort
let cmd = "go run "
let tags = go#config#BuildTags()
if len(tags) > 0
let cmd .= "-tags " . go#util#Shellescape(tags) . " "
endif
if empty(a:files)
let cmd = "go run ". go#util#Shelljoin(go#tool#Files())
let cmd .= go#util#Shelljoin(go#tool#Files())
else
let cmd = "go run ". go#util#Shelljoin(map(copy(a:files), "expand(v:val)"), 1)
let cmd .= go#util#Shelljoin(map(copy(a:files), "expand(v:val)"), 1)
endif
call go#term#newmode(a:bang, cmd, a:mode)
endfunction
@ -138,8 +144,14 @@ function! go#cmd#Run(bang, ...) abort
" anything. Once this is implemented we're going to make :GoRun async
endif
let cmd = "go run "
let tags = go#config#BuildTags()
if len(tags) > 0
let cmd .= "-tags " . go#util#Shellescape(tags) . " "
endif
if go#util#IsWin()
exec '!go run ' . go#util#Shelljoin(go#tool#Files())
exec '!' . cmd . go#util#Shelljoin(go#tool#Files())
if v:shell_error
redraws! | echon "vim-go: [run] " | echohl ErrorMsg | echon "FAILED"| echohl None
else
@ -152,9 +164,9 @@ function! go#cmd#Run(bang, ...) abort
" :make expands '%' and '#' wildcards, so they must also be escaped
let default_makeprg = &makeprg
if a:0 == 0
let &makeprg = 'go run ' . go#util#Shelljoin(go#tool#Files(), 1)
let &makeprg = cmd . go#util#Shelljoin(go#tool#Files(), 1)
else
let &makeprg = "go run " . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
let &makeprg = cmd . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
endif
let l:listtype = go#list#Type("GoRun")

View File

@ -0,0 +1,16 @@
function! go#iferr#Generate()
let [l:out, l:err] = go#util#Exec(['iferr',
\ '-pos=' . go#util#OffsetCursor()], go#util#GetLines())
if len(l:out) == 1
return
endif
if getline('.') =~ '^\s*$'
silent delete _
silent normal! k
endif
let l:pos = getcurpos()
call append(l:pos[1], split(l:out, "\n"))
silent normal! j=2j
call setpos('.', l:pos)
silent normal! 4j
endfunction

View File

@ -36,7 +36,7 @@ function! go#tool#Files(...) abort
endif
endfor
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-f', l:combined])
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', l:combined])
return split(l:out, '\n')
endfunction
@ -46,7 +46,7 @@ function! go#tool#Deps() abort
else
let format = "{{range $f := .Deps}}{{$f}}\n{{end}}"
endif
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-f', l:format])
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', l:format])
return split(l:out, '\n')
endfunction
@ -57,14 +57,14 @@ function! go#tool#Imports() abort
else
let format = "{{range $f := .Imports}}{{$f}}{{printf \"\\n\"}}{{end}}"
endif
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-f', l:format])
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', l:format])
if l:err != 0
echo out
return imports
endif
for package_path in split(out, '\n')
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-f', '{{.Name}}', l:package_path])
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', '{{.Name}}', l:package_path])
if l:err != 0
echo out
return imports
@ -88,7 +88,7 @@ function! go#tool#Info(auto) abort
endfunction
function! go#tool#PackageName() abort
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-f', '{{.Name}}'])
let [l:out, l:err] = go#tool#ExecuteInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', '{{.Name}}'])
if l:err != 0
return -1
endif

View File

@ -853,6 +853,27 @@ CTRL-t
}
<
*:GoIfErr*
:GoIfErr
Generate if err != nil { return ... } automatically which infer the type
of return values and the numbers.
For example:
>
func doSomething() (string, error) {
f, err := os.Open("file")
}
<
Becomes:
>
func doSomething() (string, error) {
f, err := os.Open("file")
if err != nil {
return "", err
}
}
<
==============================================================================
MAPPINGS *go-mappings*
@ -1065,6 +1086,10 @@ Alternates between the implementation and test code in a new vertical split
Calls `:GoImport` for the current package
*(go-iferr)*
Generate if err != nil { return ... } automatically which infer the type of
return values and the numbers.
==============================================================================
TEXT OBJECTS *go-text-objects*
@ -2090,7 +2115,7 @@ Many vim-go commands use the `guru` commandline tool to get information. Some
a reasonable amount of performance `guru` limits this analysis to a selected
list of packages. This is known as the "guru scope".
The default is to use the package the curent buffer belongs to, but this may
The default is to use the package the current buffer belongs to, but this may
not always be correct. For example for the file `guthub.com/user/pkg/a/a.go`
the scope will be set to `github.com/user/pkg/a`, but you probably want
`github.com/user/pkg`

View File

@ -109,4 +109,7 @@ endif
" -- issue
command! -nargs=0 GoReportGitHubIssue call go#issue#New()
" -- iferr
command! -nargs=0 GoIfErr call go#iferr#Generate()
" vim: sw=2 ts=2 et

View File

@ -73,4 +73,6 @@ nnoremap <silent> <Plug>(go-alternate-edit) :<C-u>call go#alternate#Switch(0, "e
nnoremap <silent> <Plug>(go-alternate-vertical) :<C-u>call go#alternate#Switch(0, "vsplit")<CR>
nnoremap <silent> <Plug>(go-alternate-split) :<C-u>call go#alternate#Switch(0, "split")<CR>
nnoremap <silent> <Plug>(go-iferr) :<C-u>call go#iferr#Generate()<CR>
" vim: sw=2 ts=2 et

View File

@ -47,6 +47,7 @@ let s:packages = {
\ 'impl': ['github.com/josharian/impl'],
\ 'keyify': ['github.com/dominikh/go-tools/cmd/keyify'],
\ 'motion': ['github.com/fatih/motion'],
\ 'iferr': ['github.com/koron/iferr'],
\ }
" These commands are available on any filetypes