Fix GTK4 Linux menu updates#5539
Conversation
WalkthroughThis PR fixes GTK4 Linux menus becoming a no-op after the first ChangesGTK4 Linux Menu Rebuild Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" 🔧 Infer (1.2.0)v3/pkg/application/linux_cgo.cIn file included from v3/pkg/application/linux_cgo.c:3: ... [truncated 759 characters] ... inux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/lib/clang/18/include" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
v3/pkg/application/linux_menu_regression_test.go (1)
17-17: 💤 Low valueThe co-occurrence check correctly detects the regression pattern.
The logic checks for both
"if impl.processed"and"return"anywhere in the function body. While this could theoretically cause false positives if unrelated return statements are added later, it accurately targets the specific bug pattern (early-return guard) that this PR fixes.If the test becomes brittle in the future, consider refining the check to look for the specific pattern
"if impl.processed"followed closely by"return"(e.g., within the same conditional block), or migrate to AST-based testing usinggo/parserandgo/astto structurally verify control flow rather than substring matching. However, the current approach is acceptable for a focused regression test.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v3/pkg/application/linux_menu_regression_test.go` at line 17, The current test checks for co-occurrence using if strings.Contains(body, "if impl.processed") && strings.Contains(body, "return"), which can yield false positives; update the test to more precisely detect an early-return guard by matching the pattern of "if impl.processed" followed closely by "return" (e.g., use a regex that allows only whitespace/comments/newlines between the if condition and the return, or scan the subsequent N lines after finding "if impl.processed" to assert a nearby "return"), or replace the substring approach with an AST-based check using go/parser/go/ast to verify a conditional statement whose body contains a return; operate on the same variable body (or parsed AST root) and keep the assertion semantics but tighten the matching to avoid unrelated return statements triggering the regression test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@v3/pkg/application/linux_menu_regression_test.go`:
- Line 17: The current test checks for co-occurrence using if
strings.Contains(body, "if impl.processed") && strings.Contains(body, "return"),
which can yield false positives; update the test to more precisely detect an
early-return guard by matching the pattern of "if impl.processed" followed
closely by "return" (e.g., use a regex that allows only
whitespace/comments/newlines between the if condition and the return, or scan
the subsequent N lines after finding "if impl.processed" to assert a nearby
"return"), or replace the substring approach with an AST-based check using
go/parser/go/ast to verify a conditional statement whose body contains a return;
operate on the same variable body (or parsed AST root) and keep the assertion
semantics but tighten the matching to avoid unrelated return statements
triggering the regression test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f0627931-d2aa-429c-bfbc-941c387a47c2
📒 Files selected for processing (6)
v3/UNRELEASED_CHANGELOG.mdv3/pkg/application/linux_cgo.cv3/pkg/application/linux_cgo.gov3/pkg/application/linux_cgo.hv3/pkg/application/linux_menu_regression_test.gov3/pkg/application/menu_linux.go
|
Thanks for this. I'm not sure of the value of the test as it just tests that the source code exists? |
Fixes #5464
Summary
Menu.Update()calls instead of returning early after the first process passmenuClearhelper and reset menu item indexes before rebuildingTests
go test ./pkg/application -run TestLinuxGTK4MenuUpdateRebuildsProcessedMenusgo test ./pkg/applicationNote:
coderabbit --plainwas not run because the command is not installed locally.Summary by CodeRabbit
Menu.Update()on a menu that had been rendered would be ignored entirely. Menus are now properly cleared and rebuilt during updates, ensuring that menu modifications take effect correctly even when updating menus that have been previously displayed.