Skip to content

fix(protogen): use strings.LastIndex to trim first field name from predefined struct name#352

Merged
wenchy merged 3 commits intomasterfrom
predefined-struct-name
Feb 5, 2026
Merged

fix(protogen): use strings.LastIndex to trim first field name from predefined struct name#352
wenchy merged 3 commits intomasterfrom
predefined-struct-name

Conversation

@Kybxd
Copy link
Collaborator

@Kybxd Kybxd commented Feb 4, 2026

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.89%. Comparing base (69e0296) to head (2992bcb).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #352      +/-   ##
==========================================
+ Coverage   73.86%   73.89%   +0.02%     
==========================================
  Files          87       87              
  Lines        8587     8595       +8     
==========================================
+ Hits         6343     6351       +8     
  Misses       1690     1690              
  Partials      554      554              

☔ 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.

xerrors.KeyTrimmedNameCell, trimmedNameCell)
}
if index := strings.Index(trimmedNameCell, typeInfo.FirstFieldOptionName); index != -1 {
if index := strings.LastIndex(trimmedNameCell, typeInfo.FirstFieldOptionName); index != -1 {
Copy link
Member

@wenchy wenchy Feb 5, 2026

Choose a reason for hiding this comment

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

Well, if trim in reverse order, it will have a another problem if int32 (ItemID) in struct (Item) in struct (Target)

TargetItemItemID
{.Target}{.Item}int32

So the solution should be:

  • If the struct's first field is not struct type, then trim in reverse order
  • Otherwise, trim in forward order

Please also add test cases to cover the logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FirstFieldOptionName is parsed recursively now. New test cases added.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@Kybxd Kybxd force-pushed the predefined-struct-name branch from adb2d1f to 9411d2e Compare February 5, 2026 12:33
@Kybxd Kybxd force-pushed the predefined-struct-name branch from 9411d2e to 0c1def5 Compare February 5, 2026 12:34
xerrors.KeyTrimmedNameCell, trimmedNameCell)
}
if index := strings.Index(trimmedNameCell, typeInfo.FirstFieldOptionName); index != -1 {
if index := strings.LastIndex(trimmedNameCell, typeInfo.FirstFieldOptionName); index != -1 {
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

@wenchy wenchy merged commit 508d6c4 into master Feb 5, 2026
11 checks passed
@wenchy wenchy deleted the predefined-struct-name branch February 5, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants