@@ -25,9 +25,11 @@ import (
2525 "strconv"
2626 "testing"
2727
28- checkv1 "buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go/buf/plugin/check /v1"
28+ descriptorv1 "buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go/buf/plugin/descriptor /v1"
2929 "buf.build/go/bufplugin/check"
30+ "buf.build/go/bufplugin/descriptor"
3031 "buf.build/go/bufplugin/internal/pkg/xslices"
32+ "buf.build/go/bufplugin/option"
3133 "github.com/bufbuild/protocompile"
3234 "github.com/bufbuild/protocompile/linker"
3335 "github.com/bufbuild/protocompile/parser"
@@ -116,25 +118,25 @@ func (r *RequestSpec) ToRequest(ctx context.Context) (check.Request, error) {
116118 return nil , errors .New ("RequestSpec.Files not set" )
117119 }
118120
119- againstFiles , err := r .AgainstFiles .ToFiles (ctx )
121+ againstFileDescriptors , err := r .AgainstFiles .ToFileDescriptors (ctx )
120122 if err != nil {
121123 return nil , err
122124 }
123- options , err := check .NewOptions (r .Options )
125+ options , err := option .NewOptions (r .Options )
124126 if err != nil {
125127 return nil , err
126128 }
127129 requestOptions := []check.RequestOption {
128- check .WithAgainstFiles ( againstFiles ),
130+ check .WithAgainstFileDescriptors ( againstFileDescriptors ),
129131 check .WithOptions (options ),
130132 check .WithRuleIDs (r .RuleIDs ... ),
131133 }
132134
133- files , err := r .Files .ToFiles (ctx )
135+ fileDescriptors , err := r .Files .ToFileDescriptors (ctx )
134136 if err != nil {
135137 return nil , err
136138 }
137- return check .NewRequest (files , requestOptions ... )
139+ return check .NewRequest (fileDescriptors , requestOptions ... )
138140}
139141
140142// ProtoFileSpec specifies files to be compiled for testing.
@@ -160,10 +162,10 @@ type ProtoFileSpec struct {
160162 FilePaths []string
161163}
162164
163- // ToFiles compiles the files into check.Files .
165+ // ToFileDescriptors compiles the files into descriptor.FileDescriptors .
164166//
165167// If p is nil, this returns an empty slice.
166- func (p * ProtoFileSpec ) ToFiles (ctx context.Context ) ([]check. File , error ) {
168+ func (p * ProtoFileSpec ) ToFileDescriptors (ctx context.Context ) ([]descriptor. FileDescriptor , error ) {
167169 if p == nil {
168170 return nil , nil
169171 }
@@ -185,22 +187,22 @@ type ExpectedAnnotation struct {
185187 // against the value in Annotation. That is, it is valid to have an Annotation return
186188 // a message but to not set it on ExpectedAnnotation.
187189 Message string
188- // Location is the location of the failure.
189- Location * ExpectedLocation
190- // AgainstLocation is the against location of the failure.
191- AgainstLocation * ExpectedLocation
190+ // FileLocation is the location of the failure.
191+ FileLocation * ExpectedFileLocation
192+ // AgainstFileLocation is the against location of the failure.
193+ AgainstFileLocation * ExpectedFileLocation
192194}
193195
194196// String implements fmt.Stringer.
195197func (ea ExpectedAnnotation ) String () string {
196198 return "ruleID=\" " + ea .RuleID + "\" " +
197199 " message=\" " + ea .Message + "\" " +
198- " location=\" " + ea .Location .String () + "\" " +
199- " againstLocation=\" " + ea .AgainstLocation .String () + "\" "
200+ " location=\" " + ea .FileLocation .String () + "\" " +
201+ " againstLocation=\" " + ea .AgainstFileLocation .String () + "\" "
200202}
201203
202- // ExpectedLocation contains the values expected from a Location.
203- type ExpectedLocation struct {
204+ // ExpectedFileLocation contains the values expected from a Location.
205+ type ExpectedFileLocation struct {
204206 // FileName is the name of the file.
205207 FileName string
206208 // StartLine is the zero-indexed start line.
@@ -214,7 +216,7 @@ type ExpectedLocation struct {
214216}
215217
216218// String implements fmt.Stringer.
217- func (el * ExpectedLocation ) String () string {
219+ func (el * ExpectedFileLocation ) String () string {
218220 if el == nil {
219221 return "nil"
220222 }
@@ -292,28 +294,28 @@ func expectedAnnotationForAnnotation(annotation check.Annotation) ExpectedAnnota
292294 RuleID : annotation .RuleID (),
293295 Message : annotation .Message (),
294296 }
295- if location := annotation .Location (); location != nil {
296- expectedAnnotation .Location = & ExpectedLocation {
297- FileName : location . File ().FileDescriptor ().Path (),
298- StartLine : location .StartLine (),
299- StartColumn : location .StartColumn (),
300- EndLine : location .EndLine (),
301- EndColumn : location .EndColumn (),
297+ if fileLocation := annotation .FileLocation (); fileLocation != nil {
298+ expectedAnnotation .FileLocation = & ExpectedFileLocation {
299+ FileName : fileLocation . FileDescriptor ().ProtoreflectFileDescriptor ().Path (),
300+ StartLine : fileLocation .StartLine (),
301+ StartColumn : fileLocation .StartColumn (),
302+ EndLine : fileLocation .EndLine (),
303+ EndColumn : fileLocation .EndColumn (),
302304 }
303305 }
304- if againstLocation := annotation .AgainstLocation (); againstLocation != nil {
305- expectedAnnotation .AgainstLocation = & ExpectedLocation {
306- FileName : againstLocation . File ().FileDescriptor ().Path (),
307- StartLine : againstLocation .StartLine (),
308- StartColumn : againstLocation .StartColumn (),
309- EndLine : againstLocation .EndLine (),
310- EndColumn : againstLocation .EndColumn (),
306+ if againstFileLocation := annotation .AgainstFileLocation (); againstFileLocation != nil {
307+ expectedAnnotation .AgainstFileLocation = & ExpectedFileLocation {
308+ FileName : againstFileLocation . FileDescriptor ().ProtoreflectFileDescriptor ().Path (),
309+ StartLine : againstFileLocation .StartLine (),
310+ StartColumn : againstFileLocation .StartColumn (),
311+ EndLine : againstFileLocation .EndLine (),
312+ EndColumn : againstFileLocation .EndColumn (),
311313 }
312314 }
313315 return expectedAnnotation
314316}
315317
316- func compile (ctx context.Context , dirPaths []string , filePaths []string ) ([]check. File , error ) {
318+ func compile (ctx context.Context , dirPaths []string , filePaths []string ) ([]descriptor. FileDescriptor , error ) {
317319 dirPaths = fromSlashPaths (dirPaths )
318320 filePaths = fromSlashPaths (filePaths )
319321 toSlashFilePathMap := make (map [string ]struct {}, len (filePaths ))
@@ -351,22 +353,22 @@ func compile(ctx context.Context, dirPaths []string, filePaths []string) ([]chec
351353 }
352354 fileDescriptorSet := fileDescriptorSetForFileDescriptors (files )
353355
354- protoFiles := make ([]* checkv1. File , len (fileDescriptorSet .GetFile ()))
356+ protoFileDescriptors := make ([]* descriptorv1. FileDescriptor , len (fileDescriptorSet .GetFile ()))
355357 for i , fileDescriptorProto := range fileDescriptorSet .GetFile () {
356358 _ , isNotImport := toSlashFilePathMap [fileDescriptorProto .GetName ()]
357359 _ , isSyntaxUnspecified := syntaxUnspecifiedFilePaths [fileDescriptorProto .GetName ()]
358360 unusedDependencyIndexes := unusedDependencyIndexesForFilePathToUnusedDependencyFilePaths (
359361 fileDescriptorProto ,
360362 filePathToUnusedDependencyFilePaths [fileDescriptorProto .GetName ()],
361363 )
362- protoFiles [i ] = & checkv1. File {
364+ protoFileDescriptors [i ] = & descriptorv1. FileDescriptor {
363365 FileDescriptorProto : fileDescriptorProto ,
364366 IsImport : ! isNotImport ,
365367 IsSyntaxUnspecified : isSyntaxUnspecified ,
366368 UnusedDependency : unusedDependencyIndexes ,
367369 }
368370 }
369- return check . FilesForProtoFiles ( protoFiles )
371+ return descriptor . FileDescriptorsForProtoFileDescriptors ( protoFileDescriptors )
370372}
371373
372374func unusedDependencyIndexesForFilePathToUnusedDependencyFilePaths (
0 commit comments