Fix the issue of multiple package imports when generating triple files. - #3052
Conversation
修复proto包中引用自定义common包时,命名冲突问题
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3052 +/- ##
===========================================
- Coverage 46.76% 40.40% -6.37%
===========================================
Files 295 457 +162
Lines 17172 32428 +15256
===========================================
+ Hits 8031 13101 +5070
- Misses 8287 18064 +9777
- Partials 854 1263 +409 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
修复生成 triple 代码时多 proto/多包引用导致的包名冲突与类型引用问题,改为使用 protobuf 的 protogen 信息来生成跨包的类型引用。
- 在生成流程中使用 protogen 的 GoIdent 生成请求/返回类型的合格标识,避免包名冲突
- 调整输出文件的包/导入路径获取逻辑,并聚合多文件错误
- 修改模板的 import 区块(但当前移除了必要的 dubbo 包导入)
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tools/protoc-gen-go-triple/main.go | 改为跳过无服务 proto、从 go_package 解析 import path、用 QualifiedGoIdent 预注册依赖、聚合错误 |
| tools/protoc-gen-go-triple/go.mod | 依赖清理为仅使用 google.golang.org/protobuf |
| tools/protoc-gen-go-triple/gen/generator/tripleTpl.go | 调整 ImportTpl,移除了固定的 dubbo 相关 import |
| tools/protoc-gen-go-triple/gen/generator/genTriple.go | ProcessProtoFile 使用 protogen 的 GoIdent 生成跨包类型引用,去掉原有 go_package 手动解析 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
please update the pr title in english |
移除go_package手动解析 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
|
There was a problem hiding this comment.
we use https://github.com/dubbogo/tools?tab=readme-ov-file#imports-formatter to format import blocks, for u, you should download the tool and cd to tools/protoc-gen-go-triple and use imports-formatter .
| if err != nil { | ||
| return err | ||
|
|
||
| // 跳过无服务的proto文件 |
| // Use the import path as parsed by protogen to avoid edge cases. | ||
| g := plugin.NewGeneratedFile(filename, file.GoImportPath) | ||
| return generator.GenTripleFile(g, tripleGo) | ||
| // 导入dubbo基础库 |
| Services: make([]Service, 0), | ||
| } | ||
| for _, service := range file.GetService() { | ||
| for k_s, service := range file.GetService() { |
There was a problem hiding this comment.
k_s 别取这种名字,你把这段代码粘贴到 chatgpt,可以咨询下,让它给你改个更合适的名字
|
@CAICAIIs check this |
CAICAIIs
left a comment
There was a problem hiding this comment.
LGTM. I think this PR is more elegant than my implementation and can be merged.
|



Modify to use the protobuf library for managing referenced libraries
After modification, it can resolve package reference issues caused by multiple .proto files and avoid naming conflicts between libraries like Dubbo's common library and custom common libraries.