feat: fuzzy command#2043
Conversation
There was a problem hiding this comment.
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.
| && !entries.iter().any(|e| { | ||
| e.name == format!("/skill {skill_name}") | ||
| }) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
模糊匹配同时对以下场景生效:
内置命令(如 /mdl → /model)
技能名 如
/skill cre
▶/skill plugin-creator
✦/skill skill-creator