-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix issue that strings with parameters are not parsed automatically #41
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where localization strings with parameters would lose their parameters when comments are empty or invalid XML. The fix ensures that original parameters are preserved instead of being replaced with empty parameters.
Key changes:
- Remove unused
_emptyLocalizableStringParams
static field - Return original parameters when comment is null/empty or XML parsing fails
- Add explanatory comments for the parameter preservation logic
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
📝 WalkthroughWalkthroughUpdates Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Compiler
participant LSG as LocalizeSourceGenerator
participant Parser as ParseCommentAndUpdateParameters
Compiler->>LSG: Execute()
LSG->>Parser: Parse(comment, parameters)
alt Valid comment
Parser-->>LSG: (parsedText, updatedParams)
else Null/invalid comment or exception
note over Parser: New behavior: return input parameters as immutable
Parser-->>LSG: (null, parameters.ToImmutableArray())
end
LSG-->>Compiler: Generated sources (based on returned tuple)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs (3)
357-359
: Preserve parsed params when comment is absent/invalid — correct fix; tighten guard + tiny alloc tweakReturning
parameters.ToImmutableArray()
here fixes the bug and preserves parsed placeholders. Consider clarifying the comment and making the guard more precise (avoidValue == null
, prefer whitespace check) and skip an allocation whenparameters
is empty.Proposed diff:
- if (comment == null || comment.Value == null || parameters.Count == 0) + if (parameters.Count == 0 || comment is null || string.IsNullOrWhiteSpace(comment.Value)) { - // If the comment is not a valid XML, the summary is null and the parameters are not updated - return (null, parameters.ToImmutableArray()); + // No comment (or empty) or no format params: pass through parsed parameters unchanged + return (null, parameters.Count == 0 + ? ImmutableArray<LocalizableStringParam>.Empty + : parameters.ToImmutableArray()); }Please confirm you have a test covering:
- Comment missing
- Comment empty/whitespace
- Comment present but invalid XML
369-383
: Avoid NullReference when attributes are missing; don’t rely on exceptions for control flowAccessing
.Value
on a missing attribute can throw and fall into the catch path. Parse attributes defensively to keep the happy path exception‑free.- var index = int.TryParse(p.Attribute(Constants.IndexAttribute).Value, out var intValue) ? intValue : -1; - var name = p.Attribute(Constants.NameAttribute).Value; - var type = p.Attribute(Constants.TypeAttribute).Value; + var idxAttr = p.Attribute(Constants.IndexAttribute)?.Value; + var name = p.Attribute(Constants.NameAttribute)?.Value; + var type = p.Attribute(Constants.TypeAttribute)?.Value; + var index = !string.IsNullOrEmpty(idxAttr) && int.TryParse(idxAttr, out var intValue) + ? intValue + : -1;
388-390
: Exception path now preserves parsed params — good; optionally surface diagnosticsBehavior matches the intent (keep parsed params if comment parsing fails). If feasible later, consider reporting a diagnostic (at low severity) for malformed comment XML to aid authors.
If you want, I can add a follow-up PR to plumb a non-throwing diagnostic here (e.g., via a helper) so generator users see why summaries/param metadata weren’t applied.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Flow.Launcher.Localization.SourceGenerators/Localize/LocalizeSourceGenerator.cs
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
CHANGES
When comment of one localization string is empty, its parameters will be empty. So we should return the original parameters
parameters.ToImmutableArray()
instead of_emptyLocalizableStringParams
.TEST
We have one localization strings with parameters:
Originally, the result is:

Now, the result is:
