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

Commit

Permalink
cue/ast: sort CommentGroups by position when adding
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed Mar 29, 2021
1 parent e3e11e3 commit f9164c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cue/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ func (c *comments) AddComment(cg *CommentGroup) {
c.groups = &a
return
}

*c.groups = append(*c.groups, cg)
a := *c.groups
for i := len(a) - 2; i >= 0 && a[i].Position > cg.Position; i-- {
a[i], a[i+1] = a[i+1], a[i]
}
}

func (c *comments) SetComments(cgs []*CommentGroup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ package descriptor
// Describes a field within a message.
#FieldDescriptorProto: {
#Type:
// 0 is reserved for errors.
// Order is weird for historical reasons.
"TYPE_DOUBLE" |
"TYPE_FLOAT" |

Expand Down Expand Up @@ -180,9 +182,6 @@ package descriptor
"TYPE_SFIXED32" |
"TYPE_SFIXED64" |
"TYPE_SINT32" | // Uses ZigZag encoding.

// 0 is reserved for errors.
// Order is weird for historical reasons.
"TYPE_SINT64" // Uses ZigZag encoding.

#Type_value: {
Expand Down

0 comments on commit f9164c6

Please sign in to comment.