File tree 3 files changed +25
-7
lines changed
3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -14,21 +14,24 @@ function! go#template#create() abort
14
14
" files) from the directory create the template or use the cwd
15
15
" as the name
16
16
if l: package_name == -1 && l: go_template_use_pkg != 1
17
- let l: template_file = get (g: , ' go_template_file' , " hello_world.go" )
17
+ let l: filename = fnamemodify (expand (" %" ), ' :t' )
18
+ if l: filename = ~ " _test.go$"
19
+ let l: template_file = get (g: , ' go_template_test_file' , " hello_world_test.go" )
20
+ else
21
+ let l: template_file = get (g: , ' go_template_file' , " hello_world.go" )
22
+ endif
18
23
let l: template_path = go#util#Join (l: root_dir , " templates" , l: template_file )
19
24
exe ' 0r ' . fnameescape (l: template_path )
20
- $delete _
21
25
elseif l: package_name == -1 && l: go_template_use_pkg == 1
22
26
" cwd is now the dir of the package
23
27
let l: path = fnamemodify (getcwd (), ' :t' )
24
28
let l: content = printf (" package %s" , l: path )
25
29
call append (0 , l: content )
26
- $delete _
27
30
else
28
31
let l: content = printf (" package %s" , l: package_name )
29
32
call append (0 , l: content )
30
- $delete _
31
33
endif
34
+ $delete _
32
35
33
36
" Remove the '... [New File]' message line from the command line
34
37
echon
Original file line number Diff line number Diff line change @@ -1485,9 +1485,9 @@ Specifies whether `gocode` should use a different socket type. By default
1485
1485
*'g:go_template_autocreate'*
1486
1486
1487
1487
When a new Go file is created, vim-go automatically fills the buffer content
1488
- with a Go code template. By default the template under
1489
- `templates/hello_world. go ` is used. This can be changed with the
1490
- | 'g:go_template_file ' | setting .
1488
+ with a Go code template. By default, the templates under the `templates`
1489
+ folder are used. This can be changed with the | 'g:go_template_file' | and
1490
+ | 'g:go_template_test_file ' | settings .
1491
1491
1492
1492
If the new file is created in an already prepopulated package (with other Go
1493
1493
files), in this case a Go code template with only the Go package declaration
@@ -1507,6 +1507,14 @@ is created. Checkout |'g:go_template_autocreate'| for more info. By default
1507
1507
the `hello_world.go ` file is used.
1508
1508
>
1509
1509
let g:go_template_file = "hello_world.go"
1510
+ <
1511
+ *'g:go_template_test_file'*
1512
+
1513
+ Specifies the file under the `templates` folder that is used if a new Go test
1514
+ file is created. Checkout | 'g:go_template_autocreate' | for more info. By
1515
+ default the `hello_world_test.go ` file is used.
1516
+ >
1517
+ let g:go_template_test_file = "hello_world_test.go"
1510
1518
<
1511
1519
*'g:go_template_use_pkg'*
1512
1520
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "testing"
4
+
5
+ func TestHelloWorld (t * testing.T ) {
6
+ // t.Fatal("not implemented")
7
+ }
You can’t perform that action at this time.
0 commit comments