Skip to content

Commit 3e49d1e

Browse files
committed
motion: more improvements
1 parent f4c5096 commit 3e49d1e

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

astcontext/funcs.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,16 @@ func (p *Parser) Funcs() Funcs {
206206
switch x := n.(type) {
207207
case *ast.FuncDecl:
208208
fn := &Func{
209-
Lbrace: ToPosition(p.fset.Position(x.Body.Lbrace)),
210-
Rbrace: ToPosition(p.fset.Position(x.Body.Rbrace)),
211209
FuncPos: ToPosition(p.fset.Position(x.Type.Func)),
212210
node: x,
213211
}
214212

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+
215219
if x.Doc != nil {
216220
fn.Doc = ToPosition(p.fset.Position(x.Doc.Pos()))
217221
}

astcontext/query.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type Decl struct {
2020
type Result struct {
2121
Mode string `json:"mode" vim:"mode"`
2222

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"`
2525
}
2626

2727
// Query specifies a single query to the parser

vim/vim.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,25 @@ func marshal(buf *bytes.Buffer, v reflect.Value) error {
8484
continue
8585
}
8686

87-
fv := v.Field(i)
88-
if !fv.IsValid() || isEmptyValue(fv) {
89-
continue
90-
}
91-
9287
tag := sf.Tag.Get("vim")
9388
if tag == "-" {
9489
continue
9590
}
96-
name, _ := parseTag(tag)
91+
92+
name, options := parseTag(tag)
9793
if !isValidTag(name) {
9894
name = ""
9995
}
96+
10097
if name == "" {
10198
name = sf.Name
10299
}
103100

101+
fv := v.Field(i)
102+
if !fv.IsValid() || options == "omitempty" && isEmptyValue(fv) {
103+
continue
104+
}
105+
104106
buf.WriteString(sep)
105107
sep = ", "
106108

0 commit comments

Comments
 (0)