Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/export: extract docs from root
Browse files Browse the repository at this point in the history
Change-Id: I0ddab86790c0447dbd8fab7e21dd37dd4e09c7b9
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9442
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Apr 20, 2021
1 parent d5ff672 commit 64ede63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 15 additions & 8 deletions internal/core/export/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,22 @@ func extractDocs(v *adt.Vertex, a []adt.Conjunct) (docs []*ast.CommentGroup) {
docs = append(docs, extractDocs(v, v.Conjuncts)...)
continue
}
f, ok := x.Source().(*ast.Field)
if !ok || hasShorthandValue(f) {
continue
}

fields = append(fields, f)
for _, cg := range f.Comments() {
if !containsDoc(docs, cg) && cg.Doc {
docs = append(docs, cg)
switch f := x.Source().(type) {
case *ast.Field:
if hasShorthandValue(f) {
continue
}
fields = append(fields, f)
for _, cg := range f.Comments() {
if !containsDoc(docs, cg) && cg.Doc {
docs = append(docs, cg)
}
}

case *ast.File:
if c := internal.FileComment(f); c != nil {
docs = append(docs, c)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/core/export/testdata/docs.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ baz: bar & {
-- out.txt --
-- out/doc --
[]
- foobar defines at least foo.

[Foo]
- A Foo fooses stuff.

Expand Down

0 comments on commit 64ede63

Please sign in to comment.