From 8aab231188fa50a5180f1ff883ab44131173fdba Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 19 Mar 2026 13:50:58 +0800 Subject: Improve command node completion with prefix matching --- src/bin/jvn_comp.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/bin/jvn_comp.rs') diff --git a/src/bin/jvn_comp.rs b/src/bin/jvn_comp.rs index 199256c..dc723dc 100644 --- a/src/bin/jvn_comp.rs +++ b/src/bin/jvn_comp.rs @@ -202,16 +202,25 @@ fn try_comp_cmd_nodes(ctx: &CompletionContext) -> Option> { break; } - // For next-level suggestions, all parts must match exactly - if input_path[i] != node_parts[i] { - matches = false; - break; + if i == input_path.len() - 1 { + if !node_parts[i].starts_with(input_path[i]) { + matches = false; + break; + } + } else { + if input_path[i] != node_parts[i] { + matches = false; + break; + } } } - if matches && input_path.len() < node_parts.len() { - // Add the next part as suggestion - suggestions.push(node_parts[input_path.len()].to_string()); + if matches && input_path.len() <= node_parts.len() { + if input_path.len() == node_parts.len() && !ctx.current_word.is_empty() { + suggestions.push(node_parts[input_path.len() - 1].to_string()); + } else if input_path.len() < node_parts.len() { + suggestions.push(node_parts[input_path.len()].to_string()); + } } } } -- cgit