encoding/protobuf: parse message options

Converted to CUE attributes.

Fixes #366

Change-Id: Id5434d8f1f1296d12a6e56ca7fd0b5ce3e7fcdcc
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7284
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/protobuf/parse.go b/encoding/protobuf/parse.go
index fb1324c..9de76f6 100644
--- a/encoding/protobuf/parse.go
+++ b/encoding/protobuf/parse.go
@@ -543,6 +543,15 @@
 	case *proto.Extensions, *proto.Reserved:
 		// no need to handle
 
+	case *proto.Option:
+		opt := fmt.Sprintf("@protobuf(option %s=%s)", x.Name, x.Constant.Source)
+		attr := &ast.Attribute{
+			At:   p.toCUEPos(x.Position),
+			Text: opt,
+		}
+		addComments(attr, i, x.Doc(), x.InlineComment)
+		s.Elts = append(s.Elts, attr)
+
 	default:
 		failf(scanner.Position{}, "unsupported field type %T", v)
 	}
diff --git a/encoding/protobuf/testdata/acme/test.proto b/encoding/protobuf/testdata/acme/test.proto
index 64de468..2cda70d 100644
--- a/encoding/protobuf/testdata/acme/test.proto
+++ b/encoding/protobuf/testdata/acme/test.proto
@@ -3,5 +3,9 @@
 package acme.test;
 
 message Test {
+  // doc comment
+  option (yoyo.foo) = true; // line comment
+
+  option (yoyo.bar) = false;
   int32 test = 1;
 }
diff --git a/encoding/protobuf/testdata/istio.io/api/cue.mod/gen/googleapis.com/acme/test/test_proto_gen.cue b/encoding/protobuf/testdata/istio.io/api/cue.mod/gen/googleapis.com/acme/test/test_proto_gen.cue
index 10b74a6..6963a32 100644
--- a/encoding/protobuf/testdata/istio.io/api/cue.mod/gen/googleapis.com/acme/test/test_proto_gen.cue
+++ b/encoding/protobuf/testdata/istio.io/api/cue.mod/gen/googleapis.com/acme/test/test_proto_gen.cue
@@ -1,5 +1,8 @@
 package test
 
 #Test: {
+	// doc comment
+	@protobuf(option (yoyo.foo)=true) // line comment
+	@protobuf(option (yoyo.bar)=false)
 	test?: int32 @protobuf(1)
 }