-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:GoAlternate and related documentation/mappings
In #684 a golang alternate plugin was presented in which it was easy to alternate between the implementation and testing code. This commit adds support for that in vim-go. It also adds related documentation and mappings. I also fixed some documentation issues to make g:go_term_mode more clear.
- Loading branch information
Showing
6 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
" By default use edit (current buffer view) to switch | ||
if !exists("g:go_alternate_mode") | ||
let g:go_alternate_mode = "edit" | ||
endif | ||
|
||
" Test alternates between the implementation of code and the test code. | ||
function! go#alternate#Switch(bang, cmd) | ||
let l:file = go#alternate#Filename(fnameescape(expand("%"))) | ||
if !filereadable(l:file) && !a:bang | ||
redraws! | echon "vim-go: " | echohl ErrorMsg | echon "couldn't find ".file | echohl None | ||
return | ||
elseif empty(a:cmd) | ||
execute ":" . g:go_alternate_mode . " " . file | ||
else | ||
execute ":" . a:cmd . " " . file | ||
endif | ||
endfunction | ||
|
||
" Filename returns the name of the test file or implementation file | ||
" depending on the arguments | ||
function! go#alternate#Filename(path) | ||
if empty(matchstr(a:path, "_test")) | ||
let l:root = split(a:path, ".go$")[0] | ||
let l:file = l:root . "_test.go" | ||
else | ||
let l:root = split(a:path, "_test.go$")[0] | ||
let l:file = l:root . ".go" | ||
endif | ||
return l:file | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters