Skip to content

Fix the issue of multiple package imports when generating triple files. - #3052

Merged
Alanxtl merged 6 commits into
apache:developfrom
hs80:develop
Nov 1, 2025
Merged

Alanxtl merged 6 commits into
apache:developfrom
hs80:develop

Conversation

@hs80

@hs80 hs80 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

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.

修复proto包中引用自定义common包时,命名冲突问题
@codecov-commenter

codecov-commenter commented Oct 16, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.40%. Comparing base (60d1c2a) to head (208100a).
⚠️ Report is 647 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread tools/protoc-gen-go-triple/gen/generator/tripleTpl.go Outdated
Comment thread tools/protoc-gen-go-triple/main.go
Comment thread tools/protoc-gen-go-triple/main.go Outdated
@AlexStocks

Copy link
Copy Markdown
Contributor

please update the pr title in english

@hs80 hs80 changed the title 修复生成triple时,多包引入问题 Fix the issue of multiple package imports when generating triples. Oct 17, 2025
移除go_package手动解析

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@hs80 hs80 changed the title Fix the issue of multiple package imports when generating triples. Fix the issue of multiple package imports when generating triple files. Oct 17, 2025
@Alanxtl

Alanxtl commented Oct 19, 2025

Copy link
Copy Markdown
Member
  1. comment use English instead of Chinese
  2. import 块的格式不要修改

@hs80

hs80 commented Oct 22, 2025

Copy link
Copy Markdown
Contributor Author
  1. comment use English instead of Chinese
  2. import 块的格式不要修改
  1. 已修改
  2. 具体是指模板还是哪里?格式是指什么格式?

@Alanxtl Alanxtl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 .

Comment thread tools/protoc-gen-go-triple/main.go Outdated
if err != nil {
return err

// 跳过无服务的proto文件

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use English

Comment thread tools/protoc-gen-go-triple/main.go Outdated
// Use the import path as parsed by protogen to avoid edge cases.
g := plugin.NewGeneratedFile(filename, file.GoImportPath)
return generator.GenTripleFile(g, tripleGo)
// 导入dubbo基础库

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use English

Services: make([]Service, 0),
}
for _, service := range file.GetService() {
for k_s, service := range file.GetService() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

k_s 别取这种名字,你把这段代码粘贴到 chatgpt,可以咨询下,让它给你改个更合适的名字

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已修改

@Alanxtl

Alanxtl commented Oct 26, 2025

Copy link
Copy Markdown
Member

@CAICAIIs check this
先把 https://github.com/dubbogo/protoc-gen-go-triple 中的代码迁移到主仓库
然后 check 一下这个 pr,如果有相同的功能就合并一下

@CAICAIIs CAICAIIs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. I think this PR is more elegant than my implementation and can be merged.

@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2025

Copy link
Copy Markdown

@Alanxtl
Alanxtl merged commit cdf2780 into apache:develop Nov 1, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants