Skip to content

feat: fuzzy command#2043

Open
New2Niu wants to merge 1 commit into
Hmbown:mainfrom
New2Niu:feat/fuzzy-cmd
Open

feat: fuzzy command#2043
New2Niu wants to merge 1 commit into
Hmbown:mainfrom
New2Niu:feat/fuzzy-cmd

Conversation

@New2Niu
Copy link
Copy Markdown

@New2Niu New2Niu commented May 25, 2026

模糊匹配同时对以下场景生效:

内置命令(如 /mdl → /model)
技能名 如
/skill cre
▶/skill plugin-creator
✦/skill skill-creator

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the slash command and skill completion logic by implementing a three-phase matching strategy: prefix, substring, and fuzzy subsequence matching. It also introduces a deduplication mechanism using a HashSet and refactors command entry creation into a helper function. Feedback focused on performance optimizations, specifically recommending the use of the existing HashSet for skill deduplication to avoid O(N^2) complexity and suggesting the elimination of redundant command info lookups by passing references directly to the helper function.

Comment on lines +2213 to +2215
&& !entries.iter().any(|e| {
e.name == format!("/skill {skill_name}")
})
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.

medium

The check for existing skill entries using entries.iter().any results in O(N^2) complexity as it iterates through the results list for every skill in the cache. Since a seen HashSet is already initialized and used for command deduplication (lines 2155, 2172, 2189), it should be leveraged here as well for O(1) lookups. To maintain consistency, ensure that skill entries are also inserted into seen when they are first added to entries.

locale: crate::localization::Locale,
) {
let (description, alias_hint) =
if let Some(info) = commands::get_command_info(command_key) {
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.

medium

This function performs a redundant registry lookup via commands::get_command_info. In Phase 2 and Phase 3 of slash_completion_hints, the CommandInfo is already available as the loop variable cmd. Passing the info reference directly to push_command_entry would avoid these repeated lookups and improve performance.

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.

1 participant