Skip to content

Commit

Permalink
Allow extra option locations in source info when building an image (#…
Browse files Browse the repository at this point in the history
…2803)

This opts into a feature in protocompile to produce more source code
locations (for span and comment info) than protoc produces. This
allows us to potentially report lint warnings with more precise position
information, and it should also allows us to carry more comment
information about custom option values into generated docs.
  • Loading branch information
jhump authored Mar 6, 2024
1 parent 421ed0a commit 49066c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion private/bufpkg/bufcheck/buflint/buflint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ func TestRunProtovalidateRules(t *testing.T) {
bufanalysistesting.NewFileAnnotation(t, "number.proto", 35, 5, 35, 43, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 39, 5, 39, 43, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 42, 5, 42, 42, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 45, 48, 48, 4, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 46, 5, 46, 11, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 47, 5, 47, 12, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 56, 5, 56, 39, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 65, 5, 65, 41, "PROTOVALIDATE"),
bufanalysistesting.NewFileAnnotation(t, "number.proto", 74, 5, 74, 40, "PROTOVALIDATE"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ message Int32Test {
// the next line should be annotated
(buf.validate.field).sfixed64.gt = 10
];
// the entire option should be annotated. (45, 48) to (48, 4)
// annotating items inside an option value
fixed32 invalid_bound_aggregate_syntax = 11 [(buf.validate.field).fixed32 = {
lt: 10
gte: 10
lt: 10 // this line should be annotated
gte: 10 // and this one, too
}];
// valid
google.protobuf.Int32Value int32_value_match = 12 [
Expand Down
5 changes: 4 additions & 1 deletion private/bufpkg/bufimage/bufimagebuild/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ func getBuildResult(
) *buildResult {
var errorsWithPos []reporter.ErrorWithPos
var warningErrorsWithPos []reporter.ErrorWithPos
sourceInfoMode := protocompile.SourceInfoStandard
// With "extra option locations", buf can include more comments
// for an option value than protoc can. In particular, this allows
// it to preserve comments inside of message literals.
sourceInfoMode := protocompile.SourceInfoExtraOptionLocations
if excludeSourceCodeInfo {
sourceInfoMode = protocompile.SourceInfoNone
}
Expand Down

0 comments on commit 49066c4

Please sign in to comment.