+40
src/completion/suggestions.rs
+40
src/completion/suggestions.rs
···
193
193
pub fn generate_command_argument_suggestions(
194
194
input: &str,
195
195
engine_guard: &EngineState,
196
+
working_set: &StateWorkingSet,
196
197
prefix: String,
197
198
span: Span,
198
199
command_name: String,
···
204
205
);
205
206
206
207
let mut suggestions = Vec::new();
208
+
209
+
// If we're at argument index 0, check if the command has subcommands and add them
210
+
if arg_index == 0 {
211
+
let parent_prefix = format!("{} ", command_name);
212
+
let search_prefix = if prefix.is_empty() {
213
+
parent_prefix.clone()
214
+
} else {
215
+
format!("{}{}", parent_prefix, prefix)
216
+
};
217
+
218
+
let subcommands = working_set
219
+
.find_commands_by_predicate(|value| value.starts_with(search_prefix.as_bytes()), true);
220
+
221
+
if !subcommands.is_empty() {
222
+
// Command has subcommands - add them to suggestions
223
+
console_log!(
224
+
"[completion] Command {command_name:?} has subcommands, adding subcommand suggestions for prefix: {prefix:?}"
225
+
);
226
+
let span = to_char_span(input, span);
227
+
for (_, name, desc, _) in subcommands {
228
+
let name_str = String::from_utf8_lossy(&name).to_string();
229
+
if let Some(subcommand_name) = name_str.strip_prefix(&parent_prefix) {
230
+
suggestions.push(Suggestion {
231
+
rendered: {
232
+
let name_colored = ansi_term::Color::Green.bold().paint(subcommand_name);
233
+
let desc_str = desc.as_deref().unwrap_or("<no description>");
234
+
format!("{name_colored} {desc_str}")
235
+
},
236
+
name: subcommand_name.to_string(),
237
+
description: desc.map(|d| d.to_string()),
238
+
span_start: span.start,
239
+
span_end: span.end,
240
+
});
241
+
}
242
+
}
243
+
}
244
+
}
245
+
207
246
if let Some(signature) = get_command_signature(engine_guard, &command_name) {
208
247
// First, check if we're completing an argument for a flag
209
248
// Look backwards from the current position to find the previous flag
···
552
591
} => generate_command_argument_suggestions(
553
592
input,
554
593
engine_guard,
594
+
working_set,
555
595
prefix,
556
596
span,
557
597
command_name,