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

Commit f9164c6

Browse files
committed
cue/ast: sort CommentGroups by position when adding
This is generally a good idea, as the formatter won't format properly. Until now this was the responsibility of the user, but for the textproto decoder this is a bit tricky. Change-Id: I64c8aaa1f40e75098f98df3a0f5e1cd04355276e Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9188 Reviewed-by: CUE cueckoo <cueckoo@gmail.com> Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
1 parent e3e11e3 commit f9164c6

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

cue/ast/ast.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ func (c *comments) AddComment(cg *CommentGroup) {
163163
c.groups = &a
164164
return
165165
}
166+
166167
*c.groups = append(*c.groups, cg)
168+
a := *c.groups
169+
for i := len(a) - 2; i >= 0 && a[i].Position > cg.Position; i-- {
170+
a[i], a[i+1] = a[i+1], a[i]
171+
}
167172
}
168173

169174
func (c *comments) SetComments(cgs []*CommentGroup) {

encoding/protobuf/testdata/istio.io/api/cue.mod/gen/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor_proto_gen.cue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ package descriptor
150150
// Describes a field within a message.
151151
#FieldDescriptorProto: {
152152
#Type:
153+
// 0 is reserved for errors.
154+
// Order is weird for historical reasons.
153155
"TYPE_DOUBLE" |
154156
"TYPE_FLOAT" |
155157

@@ -180,9 +182,6 @@ package descriptor
180182
"TYPE_SFIXED32" |
181183
"TYPE_SFIXED64" |
182184
"TYPE_SINT32" | // Uses ZigZag encoding.
183-
184-
// 0 is reserved for errors.
185-
// Order is weird for historical reasons.
186185
"TYPE_SINT64" // Uses ZigZag encoding.
187186

188187
#Type_value: {

0 commit comments

Comments
 (0)