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

feat: exp code ref #215

Merged
merged 2 commits into from
Jul 8, 2024
Merged
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
3 changes: 2 additions & 1 deletion generator/golang/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type Features struct {
EnumAsINT32 bool `enum_as_int_32:"Generate enum type as int32"`
CodeRefSlim bool `code_ref_slim:"Generate code ref by given idl-ref.yaml with less refs to avoid conflict"`
CodeRef bool `code_ref:"Generate code ref by given idl-ref.yaml"`
KeepCodeRefName bool `keep_code_ref_name:"Generate code ref but still keep file name."`
ExpCodeRef bool `exp_code_ref:"Generate code ref by given idl-ref.yaml with less refs to avoid conflict, but remind some struct as local.( this is a exp feature )"`
KeepCodeRefName bool `keep_code_ref_name:"Generate code ref but still keep file name."`
TrimIDL bool `trim_idl:"Simplify IDL to the most concise form before generating code."`
EnableNestedStruct bool `enable_nested_struct:"Generate nested field when 'thrift.nested=\"true\"' annotation is set to field, valid only in 'slim and raw_struct template'"`
JSONStringer bool `json_stringer:"Generate the JSON marshal method in String() method."`
Expand Down
2 changes: 1 addition & 1 deletion generator/golang/scope_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *Scope) GetFirstDescriptor() string {

func BuildRefScope(cu *CodeUtils, ast *parser.Thrift) (*Scope, *Scope, error) {
thriftRef := config.GetRef(ast.Filename)
enableCodeRef := cu.Features().CodeRef || cu.Features().CodeRefSlim
enableCodeRef := cu.Features().CodeRef || cu.Features().CodeRefSlim || cu.Features().ExpCodeRef
scope, err := BuildScope(cu, ast)
if err != nil {
return nil, nil, err
Expand Down
15 changes: 11 additions & 4 deletions generator/golang/templates/ref/ref_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ package ref_tpl
var File = `// Code generated by thriftgo ({{Version}}). DO NOT EDIT.
{{InsertionPoint "bof"}}
package {{.FilePackage}}
{{- $RefPackage := .RefPackage}}
{{- $RefPackage := printf "ref_%s" .RefPackage }}
import (
{{InsertionPoint "imports"}}
{{define "Imports"}}
{{- if Features.ExpCodeRef }}
{{- range $path, $alias := .}}
{{$alias }}"{{$path}}"
{{- end}}
{{- end}}
{{end}}
{{.RefPackage}} "{{.RefPath}}"
{{$RefPackage}} "{{.RefPath}}"
)

` + constRef + `
Expand Down Expand Up @@ -115,7 +120,9 @@ var structRef = `
{{if SupportIsSet .Field}}
{{$DefaultVarName := printf "%s_%s_%s" $TypeName $FieldName "DEFAULT"}}
{{- if Features.CodeRefSlim }}

{{- else if Features.ExpCodeRef }}
var {{$DefaultVarName}} {{$DefaultVarTypeName}}
{{- if .Default}} = {{.DefaultValue}}{{- end}}
{{- else }}
var {{$DefaultVarName}} = {{$RefPackage}}.{{$DefaultVarName}}
{{- end }}
Expand All @@ -130,7 +137,7 @@ var enumRef = `
type {{$TypeName}}= {{$RefPackage}}.{{$TypeName}}
var {{$EnumType}}FromString = {{$RefPackage}}.{{$EnumType}}FromString
var {{$EnumType}}Ptr = {{$RefPackage}}.{{$EnumType}}Ptr
{{- if Features.CodeRefSlim }}
{{- if or Features.CodeRefSlim Features.ExpCodeRef }}
const (
{{- range .Values}}
{{- if and Features.ReserveComments .ReservedComments}}
Expand Down
Loading