Skip to content

Commit

Permalink
feat(go_indexer): support flag field vars
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Mar 18, 2024
1 parent c067658 commit df747be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kythe/go/indexer/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ func (e *emitter) flagNameNode(caller *funcInfo, flagName string) *spb.VName {
func findIdentifier(expr ast.Expr) *ast.Ident {
for expr != nil {
switch e := expr.(type) {
case *ast.SelectorExpr:
return e.Sel
case *ast.UnaryExpr:
if e.Op != token.AND {
return nil
Expand Down
9 changes: 9 additions & 0 deletions kythe/go/indexer/testdata/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var (
featureFlag = flag.Int("feature", 42, "DEPRECATED: don't use this")
)

type Options struct{ Option int }

func init() {
//- @localFlag defines/binding LocalFlag
//- LocalFlag.node/kind variable
Expand All @@ -60,6 +62,13 @@ func init() {
//- FuncFlagDoc.text "Func flag"
flag.BoolFunc("func_flag", "Func flag", func(s string) error { return nil })

opts := Options{}

//- @"\"field_flag\"" defines/binding FieldFlag
//- @Option ref OptField
//- OptField denotes FieldFlag
flag.IntVar(&opts.Option, "field_flag", 0, "Field flag")

fmt.Println(*flagVar, *localFlag) // use flag vars
}

Expand Down

0 comments on commit df747be

Please sign in to comment.