File tree 3 files changed +16
-10
lines changed
3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -206,12 +206,16 @@ func (p *Parser) Funcs() Funcs {
206
206
switch x := n .(type ) {
207
207
case * ast.FuncDecl :
208
208
fn := & Func {
209
- Lbrace : ToPosition (p .fset .Position (x .Body .Lbrace )),
210
- Rbrace : ToPosition (p .fset .Position (x .Body .Rbrace )),
211
209
FuncPos : ToPosition (p .fset .Position (x .Type .Func )),
212
210
node : x ,
213
211
}
214
212
213
+ // can be nil for forward declarations
214
+ if x .Body != nil {
215
+ fn .Lbrace = ToPosition (p .fset .Position (x .Body .Lbrace ))
216
+ fn .Rbrace = ToPosition (p .fset .Position (x .Body .Rbrace ))
217
+ }
218
+
215
219
if x .Doc != nil {
216
220
fn .Doc = ToPosition (p .fset .Position (x .Doc .Pos ()))
217
221
}
Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ type Decl struct {
20
20
type Result struct {
21
21
Mode string `json:"mode" vim:"mode"`
22
22
23
- Decls []Decl `json:"decls" vim:"decls"`
24
- Func * Func `json:"func" vim:"fn"`
23
+ Decls []Decl `json:"decls,omitempty " vim:"decls,omitempty "`
24
+ Func * Func `json:"func,omitempty " vim:"fn,omitempty "`
25
25
}
26
26
27
27
// Query specifies a single query to the parser
Original file line number Diff line number Diff line change @@ -84,23 +84,25 @@ func marshal(buf *bytes.Buffer, v reflect.Value) error {
84
84
continue
85
85
}
86
86
87
- fv := v .Field (i )
88
- if ! fv .IsValid () || isEmptyValue (fv ) {
89
- continue
90
- }
91
-
92
87
tag := sf .Tag .Get ("vim" )
93
88
if tag == "-" {
94
89
continue
95
90
}
96
- name , _ := parseTag (tag )
91
+
92
+ name , options := parseTag (tag )
97
93
if ! isValidTag (name ) {
98
94
name = ""
99
95
}
96
+
100
97
if name == "" {
101
98
name = sf .Name
102
99
}
103
100
101
+ fv := v .Field (i )
102
+ if ! fv .IsValid () || options == "omitempty" && isEmptyValue (fv ) {
103
+ continue
104
+ }
105
+
104
106
buf .WriteString (sep )
105
107
sep = ", "
106
108
You can’t perform that action at this time.
0 commit comments