Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix pinyin match for Chinese restart command#4544

Open
SparkUiX wants to merge 2 commits into
Flow-Launcher:dev from
SparkUiX:codex/flow-pinyin-polyphonic-restart
Open

Fix pinyin match for Chinese restart command #4544
SparkUiX wants to merge 2 commits into
Flow-Launcher:dev from
SparkUiX:codex/flow-pinyin-polyphonic-restart

Conversation

@SparkUiX

@SparkUiX SparkUiX commented Jun 23, 2026
edited by cubic-dev-ai Bot
Loading

Copy link
Copy Markdown

Summary

  • add a limited pinyin override for the Chinese phrase 重启
  • allow 重启 and 重启 Flow Launcher to match queries like chongqi
  • add unit tests for the polyphonic phrase and the fuzzy match behavior

Scope

This does not try to solve every Chinese polyphonic character case. It fixes the common built-in command phrase from #3955 while keeping the behavior for 重庆 as Chong Qing.

Tests

  • dotnet test Flow.Launcher.Test\Flow.Launcher.Test.csproj --filter "FullyQualifiedName~PinyinAlphabetTest"
  • dotnet test Flow.Launcher.Test\Flow.Launcher.Test.csproj --no-restore --filter "FullyQualifiedName~PinyinAlphabetTest|FullyQualifiedName~FuzzyMatcherTest"

Fixes #3955


Summary by cubic

Fixes pinyin matching for the Chinese restart command by overriding the polyphonic phrase "重启" to map to "Chong Qi". Queries like "chongqi" now match "重启" and "重启 Flow Launcher" without affecting words like "重庆".

Summary of changes

  • Changed: PinyinAlphabet.BuildCacheFromContent now applies polyphonic overrides and pre-allocates the translation builder; default constructor delegates to PinyinAlphabet(Settings) with a null check.
  • Added: Static PolyphonicPhraseOverrides for "重启" → ["Chong","Qi"]; ApplyPolyphonicPhraseOverrides with bounds checks; NUnit tests for translation and fuzzy match of "chongqi".
  • Removed: None.
  • Memory: Negligible impact (small static map; unchanged cache).
  • Security: No new inputs or permissions; no identified risks.
  • Tests: New tests cover "重启", "重启 Flow Launcher", "重庆" translations and ensure "chongqi" fuzzy match succeeds.

Release Note
Typing "chongqi" now correctly finds the Chinese "重启" (restart) command.

Written for commit f9ac9b7. Summary will update on new commits.

Review in cubic

Copilot AI review requested due to automatic review settings June 23, 2026 16:56
@github-actions github-actions Bot added this to the 2.2.0 milestone Jun 23, 2026

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

This PR fixes pinyin matching for the built-in Chinese restart command phrase 重启 by introducing a small phrase-level override so that queries like chongqi correctly match 重启 (and 重启 Flow Launcher) while preserving existing behavior for unrelated polyphonic words like 重庆.

Changes:

  • Added a polyphonic phrase override map in PinyinAlphabet and applied it during pinyin cache construction.
  • Refactored PinyinAlphabet to support Settings injection (improves testability).
  • Added unit tests covering the 重启 override and fuzzy matching for chongqi.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Flow.Launcher.Infrastructure/PinyinAlphabet.cs Adds a targeted override for 重启 pinyin output and enables Settings injection for deterministic behavior in tests.
Flow.Launcher.Test/PinyinAlphabetTest.cs Adds unit tests validating translation and fuzzy-match behavior for 重启/chongqi, plus a regression check for 重庆.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 2 files

Re-trigger cubic

coderabbitai Bot commented Jun 23, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

i️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 52c11277-4bda-42bb-9594-f874e6cc2a53

📥 Commits

Reviewing files that changed from the base of the PR and between 410db08 and f9ac9b7.

📒 Files selected for processing (1)
  • Flow.Launcher.Infrastructure/PinyinAlphabet.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher.Infrastructure/PinyinAlphabet.cs

📝 Walkthrough

Walkthrough

PinyinAlphabet gains a static PolyphonicPhraseOverrides dictionary and an ApplyPolyphonicPhraseOverrides helper invoked in BuildCacheFromContent to correct per-phrase pinyin tokens for polyphonic characters. The parameterless constructor is refactored to delegate to a new PinyinAlphabet(Settings settings) constructor. A new NUnit test fixture validates both translation output and fuzzy matching for polyphonic phrases.

Changes

Polyphonic Phrase Pinyin Override

Layer / File(s) Summary
Constructor refactor and polyphonic override dictionary
Flow.Launcher.Infrastructure/PinyinAlphabet.cs
Adds PolyphonicPhraseOverrides static dictionary mapping phrases to pinyin tokens (initially overriding "重启"["Chong","Qi"]), introduces PinyinAlphabet(Settings settings) constructor that stores settings and registers property change handlers for ShouldUsePinyin and double-pinyin settings, and refactors the parameterless constructor to delegate to the settings constructor.
Override application helper and cache integration
Flow.Launcher.Infrastructure/PinyinAlphabet.cs
Implements ApplyPolyphonicPhraseOverrides(string content, string[] resultList) that iterates override phrases, finds each in content via IndexOf, validates phrase and token length compatibility, and overwrites corresponding pinyin tokens in the result list; wires the call into BuildCacheFromContent after initial per-character pinyin generation.
Translation and fuzzy match tests
Flow.Launcher.Test/PinyinAlphabetTest.cs
New PinyinAlphabetTest fixture with a parameterized test asserting correct pinyin for polyphonic phrases (e.g., "重启""Chong Qi", "重庆""Chong Qing") and a fuzzy match test confirming "chongqi" matches "重启" through StringMatcher with ShouldUsePinyin = true.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Flow-Launcher/Flow.Launcher#3825: Both PRs modify pinyin cache construction in BuildCacheFromContent, with this PR adding polyphonic phrase override logic adjacent to the retrieved PR's cache-building changes.

Suggested reviewers

  • jjw24
  • Jack251970
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing pinyin matching for the Chinese restart command (重启).
Description check ✅ Passed The description is well-related to the changeset, explaining the polyphonic phrase override for '重启', the scope of the fix, and testing approach.
Linked Issues check ✅ Passed The PR fully addresses issue #3955 by implementing pinyin override for '重启' to match 'chongqi' queries, with scoped implementation and unit tests validating both phrase translation and fuzzy matching.
Out of Scope Changes check ✅ Passed All changes are in scope: the PinyinAlphabet constructor refactoring supports the override feature, polyphonic phrase override implementation directly fixes #3955, and tests validate the fix without unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Flow.Launcher.Infrastructure/PinyinAlphabet.cs (1)

185-188: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Defensively validate override span writes.

The override loop assumes phrase length and pinyin token count always align. A future bad entry can throw IndexOutOfRangeException at Line 187. Add a guard before writing the span to keep translation resilient.

Suggested hardening
 while (index >= 0)
 {
+ if (pinyin.Length != phrase.Length || index + pinyin.Length > resultList.Length)
+ {
+ index = content.IndexOf(phrase, index + phrase.Length, StringComparison.Ordinal);
+ continue;
+ }
+
 for (var i = 0; i < pinyin.Length; i++)
 {
 resultList[index + i] = pinyin[i];
 }
🤖 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 `@Flow.Launcher.Infrastructure/PinyinAlphabet.cs` around lines 185 - 188, The
loop at line 185-188 that writes pinyin characters to resultList lacks bounds
validation and assumes the phrase length always matches the pinyin token count.
Add a guard condition before the for loop that iterates over pinyin to validate
that index plus pinyin.Length does not exceed resultList.Length, preventing
potential IndexOutOfRangeException when future bad entries are encountered. If
the bounds check fails, handle it gracefully by skipping the write or logging a
warning to keep the translation resilient.
🤖 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.
Inline comments:
In `@Flow.Launcher.Infrastructure/PinyinAlphabet.cs`:
- Around line 31-33: The PinyinAlphabet constructor does not validate that the
injected settings parameter is null before assigning it to the _settings field.
Add a null guard at the beginning of the PinyinAlphabet constructor that throws
an ArgumentNullException if the settings parameter is null, ensuring the error
fails fast instead of allowing a NullReferenceException to occur later when
_settings is dereferenced.
---
Nitpick comments:
In `@Flow.Launcher.Infrastructure/PinyinAlphabet.cs`:
- Around line 185-188: The loop at line 185-188 that writes pinyin characters to
resultList lacks bounds validation and assumes the phrase length always matches
the pinyin token count. Add a guard condition before the for loop that iterates
over pinyin to validate that index plus pinyin.Length does not exceed
resultList.Length, preventing potential IndexOutOfRangeException when future bad
entries are encountered. If the bounds check fails, handle it gracefully by
skipping the write or logging a warning to keep the translation resilient.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

i️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19d08c6a-e4e2-492c-adb9-1621554a762a

📥 Commits

Reviewing files that changed from the base of the PR and between 5413d40 and 410db08.

📒 Files selected for processing (2)
  • Flow.Launcher.Infrastructure/PinyinAlphabet.cs
  • Flow.Launcher.Test/PinyinAlphabetTest.cs

Comment thread Flow.Launcher.Infrastructure/PinyinAlphabet.cs

Copy link
Copy Markdown
Contributor

Nice workaround. Our 3rd party pinyin nuget is not good while dealing with polyphonic.

Jack251970 reacted with thumbs up emoji

@Jack251970 Jack251970 added the bug Something isn't working label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
Copilot code review Copilot Copilot left review comments
@cubic-dev-ai cubic-dev-ai[bot] cubic-dev-ai[bot] left review comments

At least 1 approving review is required to merge this pull request.

Labels

bug Something isn't working

Projects

None yet

Milestone

2.2.0

Development

Successfully merging this pull request may close these issues.

BUG: Chinese polyphonic characters pinyin search issue

AltStyle によって変換されたページ (->オリジナル) /