nushell on your web browser
nushell wasm terminal

fix suggestions to check oneof signature for arguments and flags

ptr.pet 5600d1b6 9f22274a

verified
+36 -28
+36 -28
src/completion/suggestions.rs
··· 256 256 "[completion] Flag {flag_name:?} accepts argument of type {:?}", 257 257 flag_arg_shape 258 258 ); 259 + let mut add_file_suggestions = || { 260 + let file_suggestions = generate_file_suggestions( 261 + &prefix, 262 + span, 263 + root, 264 + Some(flag.desc.clone()), 265 + input, 266 + ); 267 + let file_count = file_suggestions.len(); 268 + suggestions.extend(file_suggestions); 269 + console_log!( 270 + "[completion] Found {file_count} file suggestions for flag argument" 271 + ); 272 + }; 259 273 match flag_arg_shape { 260 274 nu_protocol::SyntaxShape::Filepath 261 275 | nu_protocol::SyntaxShape::Any => { 262 - // File/directory completion for flag argument 263 - let file_suggestions = generate_file_suggestions( 264 - &prefix, 265 - span, 266 - root, 267 - Some(flag.desc.clone()), 268 - input, 269 - ); 270 - let file_count = file_suggestions.len(); 271 - suggestions.extend(file_suggestions); 272 - console_log!( 273 - "[completion] Found {file_count} file suggestions for flag argument" 274 - ); 276 + add_file_suggestions(); 277 + } 278 + nu_protocol::SyntaxShape::OneOf(l) 279 + if l.contains(&nu_protocol::SyntaxShape::Filepath) => 280 + { 281 + add_file_suggestions(); 275 282 } 276 283 _ => { 277 284 // Flag argument is not a filepath type ··· 308 315 }; 309 316 310 317 if let Some(arg) = arg { 311 - // Check the SyntaxShape to determine completion type 312 - // Only suggest files/dirs for Filepath type 318 + let mut add_file_suggestions = || { 319 + let file_suggestions = 320 + generate_file_suggestions(&prefix, span, root, Some(arg.desc.clone()), input); 321 + let file_count = file_suggestions.len(); 322 + suggestions.extend(file_suggestions); 323 + console_log!( 324 + "[completion] Found {file_count} file suggestions for argument {arg_index}" 325 + ); 326 + }; 327 + 313 328 match &arg.shape { 314 329 nu_protocol::SyntaxShape::Filepath | nu_protocol::SyntaxShape::Any => { 315 - // File/directory completion 316 - let file_suggestions = generate_file_suggestions( 317 - &prefix, 318 - span, 319 - root, 320 - Some(arg.desc.clone()), 321 - input, 322 - ); 323 - let file_count = file_suggestions.len(); 324 - suggestions.extend(file_suggestions); 325 - console_log!( 326 - "[completion] Found {file_count} file suggestions for argument {arg_index}" 327 - ); 330 + add_file_suggestions(); 331 + } 332 + nu_protocol::SyntaxShape::OneOf(l) 333 + if l.contains(&nu_protocol::SyntaxShape::Filepath) => 334 + { 335 + add_file_suggestions(); 328 336 } 329 337 _ => { 330 338 // For other types, don't suggest files