Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support minisnip #1589

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ IMPROVEMENTS:
[[GH-1582]](https://github.com/fatih/vim-go/pull/1582).
* `:GoDescribe` doesn't require a scope anymore
[[GH-1596]](https://github.com/fatih/vim-go/pull/1596).
* Add some standard snippets for
[vim-minisnip](https://github.com/joereynolds/vim-minisnip)
[[GH-1589]](https://github.com/fatih/vim-go/pull/1589).
* `g:go_snippet_engine` now defaults to `automatic` to use the first installed
snippet engine it can find.
[[GH-1589]](https://github.com/fatih/vim-go/pull/1589).

## 1.15 - (October 3, 2017)

Expand Down
18 changes: 13 additions & 5 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ tools developed by the Go community to provide a seamless Vim experience.
* Advanced source analysis tools utilizing `guru`, such as |:GoImplements|,
|:GoCallees|, and |:GoReferrers|.
* Precise type-safe renaming of identifiers with |:GoRename|.
* Integrated and improved snippets, supporting `ultisnips` or `neosnippet`.
* Integrated and improved snippets, supporting `ultisnips`, `neosnippet`,
and `vim-minisnip`.
* Share your current code to play.golang.org with |:GoPlay|.
* On-the-fly information about the word under the cursor. Plug it into your
custom Vim function.
Expand Down Expand Up @@ -136,7 +137,8 @@ The following plugins are supported for use with vim-go:

* Snippets:
https://github.com/Shougo/neosnippet.vim or
https://github.com/SirVer/ultisnips
https://github.com/SirVer/ultisnips or
https://github.com/joereynolds/vim-minisnip

* For a better documentation viewer check out:
https://github.com/garyburd/go-explorer
Expand Down Expand Up @@ -1278,10 +1280,16 @@ Use this option to change default path for vim-go tools when using
<
*'g:go_snippet_engine'*

Use this option to define the default snippet engine. By default "ultisnips"
is used. Use "neosnippet" for neosnippet.vim: >
Define the snippet engine to use. The default is to auto-detect one. Valid
values are:

let g:go_snippet_engine = "ultisnips"
automatic Automatically detect a snippet engine.
ultisnips https://github.com/SirVer/ultisnips
neosnippet https://github.com/Shougo/neosnippet.vim
minisnip https://github.com/joereynolds/vim-minisnip
Note: the original at KeyboardFire/vim-minisnip won't work.
>
let g:go_snippet_engine = "automatic"
<
*'g:go_get_update'*

Expand Down
49 changes: 34 additions & 15 deletions ftplugin/go/snippets.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ if exists("g:go_loaded_gosnippets")
endif
let g:go_loaded_gosnippets = 1

" by default UltiSnips
if !exists("g:go_snippet_engine")
let g:go_snippet_engine = "ultisnips"
endif

function! s:GoUltiSnips()
if globpath(&rtp, 'plugin/UltiSnips.vim') == ""
function! s:GoUltiSnips() abort
if get(g:, 'did_plugin_ultisnips') isnot 1
return
endif

Expand All @@ -20,29 +15,53 @@ function! s:GoUltiSnips()
endif
endfunction

function! s:GoNeosnippet()
if globpath(&rtp, 'plugin/neosnippet.vim') == ""
function! s:GoNeosnippet() abort
if get(g:, 'loaded_neosnippet') isnot 1
return
endif

let g:neosnippet#enable_snipmate_compatibility = 1

let gosnippets_dir = globpath(&rtp, 'gosnippets/snippets')
let l:gosnippets_dir = globpath(&rtp, 'gosnippets/snippets')
if type(g:neosnippet#snippets_directory) == type([])
let g:neosnippet#snippets_directory += [gosnippets_dir]
let g:neosnippet#snippets_directory += [l: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
let g:neosnippet#snippets_directory = g:neosnippet#snippets_directory . "," . l:gosnippets_dir
else
let g:neosnippet#snippets_directory = gosnippets_dir
let g:neosnippet#snippets_directory = l:gosnippets_dir
endif
endif
endfunction

if g:go_snippet_engine == "ultisnips"
function! s:GoMinisnip() abort
if get(g:, 'loaded_minisnip') isnot 1
return
endif

if exists('g:minisnip_dir')
let g:minisnip_dir .= ':' . globpath(&rtp, 'gosnippets/minisnip')
else
let g:minisnip_dir = globpath(&rtp, 'gosnippets/minisnip')
endif
endfunction


let s:engine = get(g:, 'go_snippet_engine', 'automatic')
if s:engine is? "automatic"
if get(g:, 'did_plugin_ultisnips') is 1
call s:GoUltiSnips()
elseif get(g:, 'loaded_neosnippet') is 1
call s:GoNeosnippet()
elseif get(g:, 'loaded_minisnip') is 1
call s:GoMinisnip()
endif
elseif s:engine is? "ultisnips"
call s:GoUltiSnips()
elseif g:go_snippet_engine == "neosnippet"
elseif s:engine is? "neosnippet"
call s:GoNeosnippet()
elseif s:engine is? "minisnip"
call s:GoMinisnip()
endif

" vim: sw=2 ts=2 et
3 changes: 3 additions & 0 deletions gosnippets/minisnip/_go_eq
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if !reflect.DeepEqual({{+got+}}, {{+want+}}) {
t.Errorf("\ngot: %#v\nwant: %#v\n", {{+~\~2+}}, {{+~\~2+}})
}
3 changes: 3 additions & 0 deletions gosnippets/minisnip/_go_err
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if err != nil {
return {{+err+}}
}
4 changes: 4 additions & 0 deletions gosnippets/minisnip/_go_errt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if err != nil {
t.Fatal(err)
}
{{++}}
3 changes: 3 additions & 0 deletions gosnippets/minisnip/_go_errw
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if err != nil {
return errors.Wrap(err, "{{++}}")
}
3 changes: 3 additions & 0 deletions gosnippets/minisnip/_go_f
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// {{++}}
func {{+~\~1+}}() {
}
1 change: 1 addition & 0 deletions gosnippets/minisnip/_go_ff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fmt.Printf("%#v\n", {{++}})
3 changes: 3 additions & 0 deletions gosnippets/minisnip/_go_fori
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for i := 0; i < {{++}}; i++ {
{{++}}
}
2 changes: 2 additions & 0 deletions gosnippets/minisnip/_go_pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package {{+~expand('%:p:h:t')+}} {{++}}
package {{+~\~2+}}
2 changes: 2 additions & 0 deletions gosnippets/minisnip/_go_sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fmt.Sprintf("{{++}}", {{++}})