Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editions support in protoc-gen-star #130

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/lyft/protoc-gen-star/v2
module github.com/vaidehi-figma/protoc-gen-star

go 1.17

require (
github.com/spf13/afero v1.3.3
github.com/stretchr/testify v1.6.1
golang.org/x/tools v0.1.12
google.golang.org/protobuf v1.23.0
google.golang.org/protobuf v1.34.2
)

require (
Expand Down
22 changes: 6 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
Expand Down Expand Up @@ -52,13 +46,9 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
16 changes: 16 additions & 0 deletions init_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,19 @@ func SupportedFeatures(feat *uint64) InitOption {
g.persister.SetSupportedFeatures(feat)
}
}

// Generators must specify exactly which editions they support. MinimumEdition and MaximumEdition fields for specify the precise support window.
// See: https://protobuf.dev/editions/implementation/
func MinimumEdition(me *int32) InitOption {
return func(g *Generator) {
g.persister.SetMinimumEdition(me)
}
}

// Generators must specify exactly which editions they support. MinimumEdition and MaximumEdition fields for specify the precise support window.
// See: https://protobuf.dev/editions/implementation/
func MaximumEdition(me *int32) InitOption {
return func(g *Generator) {
g.persister.SetMaximumEdition(me)
}
}
2 changes: 1 addition & 1 deletion lang/go/camel.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pgsgo

import (
pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix all of your package renames?

)

// PGGUpperCamelCase converts Name n to the protoc-gen-go defined upper
Expand Down
2 changes: 1 addition & 1 deletion lang/go/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pgsgo

import pgs "github.com/lyft/protoc-gen-star/v2"
import pgs "github.com/vaidehi-figma/protoc-gen-star"

// Context resolves Go-specific language for Packages & Entities generated by
// protoc-gen-go. The rules that drive the naming behavior are complicated, and
Expand Down
2 changes: 1 addition & 1 deletion lang/go/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package pgsgo
import (
"testing"

pgs "github.com/lyft/protoc-gen-star/v2"
"github.com/stretchr/testify/assert"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestContext_Params(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/gofmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"go/format"
"strings"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

type goFmt struct{}
Expand Down
2 changes: 1 addition & 1 deletion lang/go/gofmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pgsgo
import (
"testing"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"

"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion lang/go/goimports.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"golang.org/x/tools/imports"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

type goImports struct{}
Expand Down
2 changes: 1 addition & 1 deletion lang/go/goimports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/assert"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestGoImports_Match(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"testing"

pgs "github.com/lyft/protoc-gen-star/v2"
"github.com/stretchr/testify/require"
pgs "github.com/vaidehi-figma/protoc-gen-star"
"google.golang.org/protobuf/proto"
plugin_go "google.golang.org/protobuf/types/pluginpb"
)
Expand Down
2 changes: 1 addition & 1 deletion lang/go/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"unicode"
"unicode/utf8"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func (c context) Name(node pgs.Node) pgs.Name {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package pgsgo
import (
"testing"

pgs "github.com/lyft/protoc-gen-star/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestPGGUpperCamelCase(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"unicode"
"unicode/utf8"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

var nonAlphaNumPattern = regexp.MustCompile("[^a-zA-Z0-9]")
Expand Down
2 changes: 1 addition & 1 deletion lang/go/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package pgsgo
import (
"testing"

pgs "github.com/lyft/protoc-gen-star/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestPackageName(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion lang/go/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package pgsgo
import (
"testing"

pgs "github.com/lyft/protoc-gen-star/v2"
"github.com/stretchr/testify/assert"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestParameters_Plugins(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/type_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func (c context) Type(f pgs.Field) TypeName {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/type_name_p2_presence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestType(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion lang/go/type_name_p3_presence_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build proto3_presence
// +build proto3_presence

package pgsgo
Expand All @@ -8,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestType(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion lang/go/type_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

func TestTypeName(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type persister interface {
SetDebugger(d Debugger)
SetFS(fs afero.Fs)
SetSupportedFeatures(f *uint64)
SetMaximumEdition(me *int32)
SetMinimumEdition(me *int32)
AddPostProcessor(proc ...PostProcessor)
Persist(a ...Artifact) *plugin_go.CodeGeneratorResponse
}
Expand All @@ -24,18 +26,24 @@ type stdPersister struct {
fs afero.Fs
procs []PostProcessor
supportedFeatures *uint64
maximumEdition *int32
minimumEdition *int32
}

func newPersister() *stdPersister { return &stdPersister{fs: afero.NewOsFs()} }

func (p *stdPersister) SetDebugger(d Debugger) { p.Debugger = d }
func (p *stdPersister) SetFS(fs afero.Fs) { p.fs = fs }
func (p *stdPersister) SetSupportedFeatures(f *uint64) { p.supportedFeatures = f }
func (p *stdPersister) SetMaximumEdition(me *int32) { p.maximumEdition = me }
func (p *stdPersister) SetMinimumEdition(me *int32) { p.minimumEdition = me }
func (p *stdPersister) AddPostProcessor(proc ...PostProcessor) { p.procs = append(p.procs, proc...) }

func (p *stdPersister) Persist(arts ...Artifact) *plugin_go.CodeGeneratorResponse {
resp := new(plugin_go.CodeGeneratorResponse)
resp.SupportedFeatures = p.supportedFeatures
resp.MaximumEdition = p.maximumEdition
resp.MinimumEdition = p.minimumEdition

for _, a := range arts {
switch a := a.(type) {
Expand Down
6 changes: 5 additions & 1 deletion protoc-gen-debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ func main() {
}

// protoc-gen-debug supports proto3 field presence for testing purposes
var supportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
var supportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL) | uint64(pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS)
var minimumEdition = int32(2023)
var maximumEdition = int32(2023)
if data, err = proto.Marshal(&plugin_go.CodeGeneratorResponse{
SupportedFeatures: &supportedFeatures,
MinimumEdition: &minimumEdition,
MaximumEdition: &maximumEdition,
}); err != nil {
log.Fatal("unable to marshal response payload: ", err)
}
Expand Down
16 changes: 8 additions & 8 deletions testdata/protoc-gen-example/jsonify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
import (
"text/template"

pgsgo "github.com/lyft/protoc-gen-star/v2/lang/go"
pgsgo "github.com/vaidehi-figma/protoc-gen-star/lang/go"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

// JSONifyPlugin adds encoding/json Marshaler and Unmarshaler methods on PB
Expand Down Expand Up @@ -74,12 +74,12 @@ import (

{{ range .AllMessages }}

// {{ marshaler . }} describes the default jsonpb.Marshaler used by all
// instances of {{ name . }}. This struct is safe to replace or modify but
// {{ marshaler . }} describes the default jsonpb.Marshaler used by all
// instances of {{ name . }}. This struct is safe to replace or modify but
// should not be done so concurrently.
var {{ marshaler . }} = new(jsonpb.Marshaler)

// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// MarshalJSON satisfies the encoding/json Marshaler interface. This method
// uses the more correct jsonpb package to correctly marshal the message.
func (m *{{ name . }}) MarshalJSON() ([]byte, error) {
if m == nil {
Expand All @@ -97,12 +97,12 @@ func (m *{{ name . }}) MarshalJSON() ([]byte, error) {

var _ json.Marshaler = (*{{ name . }})(nil)

// {{ unmarshaler . }} describes the default jsonpb.Unmarshaler used by all
// instances of {{ name . }}. This struct is safe to replace or modify but
// {{ unmarshaler . }} describes the default jsonpb.Unmarshaler used by all
// instances of {{ name . }}. This struct is safe to replace or modify but
// should not be done so concurrently.
var {{ unmarshaler . }} = new(jsonpb.Unmarshaler)

// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// UnmarshalJSON satisfies the encoding/json Unmarshaler interface. This method
// uses the more correct jsonpb package to correctly unmarshal the message.
func (m *{{ name . }}) UnmarshalJSON(b []byte) error {
return {{ unmarshaler . }}.Unmarshal(bytes.NewReader(b), m)
Expand Down
4 changes: 2 additions & 2 deletions testdata/protoc-gen-example/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
pgs "github.com/lyft/protoc-gen-star/v2"
pgsgo "github.com/lyft/protoc-gen-star/v2/lang/go"
pgs "github.com/vaidehi-figma/protoc-gen-star"
pgsgo "github.com/vaidehi-figma/protoc-gen-star/lang/go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion testdata/protoc-gen-example/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"bytes"

pgs "github.com/lyft/protoc-gen-star/v2"
pgs "github.com/vaidehi-figma/protoc-gen-star"
)

type PrinterModule struct {
Expand Down
2 changes: 1 addition & 1 deletion testutils/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os/exec"
"path/filepath"

pgs "github.com/lyft/protoc-gen-star/v2"
"github.com/spf13/afero"
pgs "github.com/vaidehi-figma/protoc-gen-star"
"google.golang.org/protobuf/proto"
descriptor "google.golang.org/protobuf/types/descriptorpb"
)
Expand Down