diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-19 13:50:58 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-19 13:50:58 +0800 |
| commit | 8aab231188fa50a5180f1ff883ab44131173fdba (patch) | |
| tree | dd4c6e1a52ba33dc031610328147b8a9f333cc1f /src | |
| parent | f508de7bc4321db6f3dd71ea43c1cc384b7d6a7f (diff) | |
Improve command node completion with prefix matching
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/jvn_comp.rs | 23 |
1 files changed, 16 insertions, 7 deletions
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<Vec<String>> { 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()); + } } } } |
