Skip to content

Commit

Permalink
restore: @name parsing behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
njacob1001 committed Dec 17, 2024
1 parent 04b5bc8 commit 41a57e9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ func (t *TypeSpecDef) Name() string {
func (t *TypeSpecDef) TypeName() string {
if ignoreNameOverride(t.TypeSpec.Name.Name) {
return t.TypeSpec.Name.Name[1:]
} else if t.TypeSpec.Comment != nil {
// get alias from comment '// @name '
const regexCaseInsensitive = "(?i)"
reTypeName, err := regexp.Compile(regexCaseInsensitive + `^@name\s+(\S+)`)
if err != nil {
panic(err)
}
for _, comment := range t.TypeSpec.Comment.List {
trimmedComment := strings.TrimSpace(strings.TrimLeft(comment.Text, "/"))
texts := reTypeName.FindStringSubmatch(trimmedComment)
if len(texts) > 1 {
return texts[1]
}
}
}

var names []string
Expand Down

0 comments on commit 41a57e9

Please sign in to comment.