Skip to content

Commit

Permalink
internal/core/export: handle ConjunctGroups
Browse files Browse the repository at this point in the history
extractDocs did not handle ConjunctGroups correctly for
the top-level Vertex. Adjust its signature to allow using
VisitLeafConjuncts and adjust accordingly.

Issue #3060

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ia7ca18aae552894d23d738e5105edc19d733de84
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194103
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
mpvl committed May 1, 2024
1 parent 1259cf9 commit 8935df9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
10 changes: 8 additions & 2 deletions cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func TestAPI(t *testing.T) {
return res
},
want: "_|_ // #runSpec.ction: field not allowed",

skip: true,
}, {
// Issue #567
input: `
Expand Down Expand Up @@ -2741,6 +2743,7 @@ func TestValueDoc(t *testing.T) {
val Value
path string
doc string
skip bool
}{{
val: v1,
path: "foos",
Expand Down Expand Up @@ -2776,6 +2779,8 @@ field1 is an int.
comment from baz on field 1
`,
// New evaluaotor orders the comments differently (arguably better).
skip: true,
}, {
val: v1,
path: "baz field2",
Expand All @@ -2795,8 +2800,9 @@ Another Foo.
}}
for _, tc := range testCases {
t.Run("field:"+tc.path, func(t *testing.T) {
TODO_V3(t, cfg)

if tc.skip {
TODO_V3(t, cfg)
}
v := tc.val.Lookup(strings.Split(tc.path, " ")...)
doc := docStr(v.Doc())
if doc != tc.doc {
Expand Down
3 changes: 2 additions & 1 deletion internal/core/export/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ func (x *exporter) mergeValues(label adt.Feature, src *adt.Vertex, a []conjunct,

internal.SetConstraint(d, field.arcType.Token())
if x.cfg.ShowDocs {
docs := extractDocs(src, a)
v := &adt.Vertex{Conjuncts: a}
docs := extractDocs(v)
ast.SetComments(d, docs)
}
if x.cfg.ShowAttributes {
Expand Down
18 changes: 8 additions & 10 deletions internal/core/export/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ import (
// // comment
// foo: bar: 2
func ExtractDoc(v *adt.Vertex) (docs []*ast.CommentGroup) {
return extractDocs(v, v.Conjuncts)
return extractDocs(v)
}

func extractDocs(v *adt.Vertex, a []adt.Conjunct) (docs []*ast.CommentGroup) {
func extractDocs(v *adt.Vertex) (docs []*ast.CommentGroup) {
fields := []*ast.Field{}

// Collect docs directly related to this Vertex.
for _, x := range a {
v.VisitLeafConjuncts(func(x adt.Conjunct) bool {
// TODO: Is this still being used?
if v, ok := x.Elem().(*adt.Vertex); ok {
docs = append(docs, extractDocs(v, v.Conjuncts)...)
continue
docs = append(docs, extractDocs(v)...)
return true
}

switch f := x.Field().Source().(type) {
case *ast.Field:
if hasShorthandValue(f) {
continue
return true
}
fields = append(fields, f)
for _, cg := range f.Comments() {
Expand All @@ -60,11 +60,9 @@ func extractDocs(v *adt.Vertex, a []adt.Conjunct) (docs []*ast.CommentGroup) {
docs = append(docs, c)
}
}
}

if v == nil {
return docs
}
return true
})

// Collect docs from parent scopes in collapsed fields.
for p := v.Parent; p != nil; p = p.Parent {
Expand Down

0 comments on commit 8935df9

Please sign in to comment.