@@ -9,18 +9,14 @@ if !exists("g:go_fmt_command")
9
9
let g: go_fmt_command = " gofmt"
10
10
endif
11
11
12
- if ! exists (" g:go_goimports_bin " )
13
- let g: go_goimports_bin = " goimports "
12
+ if ! exists (' g:go_fmt_options ' )
13
+ let g: go_fmt_options = ' '
14
14
endif
15
15
16
16
if ! exists (' g:go_fmt_fail_silently' )
17
17
let g: go_fmt_fail_silently = 0
18
18
endif
19
19
20
- if ! exists (' g:go_fmt_options' )
21
- let g: go_fmt_options = ' '
22
- endif
23
-
24
20
if ! exists (" g:go_fmt_experimental" )
25
21
let g: go_fmt_experimental = 0
26
22
endif
@@ -70,7 +66,7 @@ function! go#fmt#Format(withGoimport) abort
70
66
71
67
let bin_name = g: go_fmt_command
72
68
if a: withGoimport == 1
73
- let bin_name = g: go_goimports_bin
69
+ let bin_name = " goimports "
74
70
endif
75
71
76
72
let out = go#fmt#run (bin_name, l: tmpname , expand (' %' ))
@@ -172,7 +168,15 @@ function! s:fmt_cmd(bin_name, source, target)
172
168
" start constructing the command
173
169
let cmd = [bin_path]
174
170
call add (cmd, " -w" )
175
- call extend (cmd, split (g: go_fmt_options , " " ))
171
+
172
+ " add the options for binary (if any). go_fmt_options was by default of type
173
+ " string, however to allow customization it's now a dictionary of binary
174
+ " name mapping to options.
175
+ let opts = g: go_fmt_options
176
+ if type (g: go_fmt_options ) == type ({})
177
+ let opts = has_key (g: go_fmt_options , a: bin_name ) ? g: go_fmt_options [a: bin_name ] : " "
178
+ endif
179
+ call extend (cmd, split (opts, " " ))
176
180
177
181
if a: bin_name == " goimports"
178
182
" lazy check if goimports support `-srcdir`. We should eventually remove
0 commit comments