Repository: nushell/nushell
File: crates/nu-parser/src/parse_shape_specs.rs (Rust)

Code before:
                            working_set.error(ParseError::LabeledError(
                                "expected a single type parameter".into(),
                                "only one parameter allowed".into(),
                                params.span,
                            ));
                            SyntaxShape::Any
                        } else {
                            parsed_params.pop().unwrap_or(SyntaxShape::Any)
                        }
                    }
                    None => SyntaxShape::Any,
                })),
                b"record" => SyntaxShape::Record(match type_params {
                    Some(params) => parse_named_type_params(working_set, params, use_loc),
                    None => vec![],
                }),
                b"table" => SyntaxShape::Table(match type_params {
                    Some(params) => parse_named_type_params(working_set, params, use_loc),
                    None => vec![],
                }),
                _ => {
                    working_set.error(ParseError::UnknownType(span));
                    SyntaxShape::Any
                }
            }
        }
        b"string" => SyntaxShape::String,
        _ => {
            if bytes.contains(&b'@') {
                let mut split = bytes.splitn(2, |b| b == &b'@');

                let shape_name = split
                    .next()
                    .expect("If `bytes` contains `@` splitn returns 2 slices");
                let shape_span = Span::new(span.start, span.start + shape_name.len());
                let shape = parse_shape_name(working_set, shape_name, shape_span, use_loc);
                if use_loc != ShapeDescriptorUse::Argument {
                    let illegal_span = Span::new(span.start + shape_name.len(), span.end);
                    working_set.error(ParseError::LabeledError(
                        "Unexpected custom completer in type spec".into(),
                        "Type specifications do not support custom completers".into(),
                        illegal_span,
                    ));
                    return shape;
                }

                let cmd_span = Span::new(span.start + shape_name.len() + 1, span.end);
                let cmd_name = split
                    .next()
                    .expect("If `bytes` contains `@` splitn returns 2 slices");


Review comment (suggestion):
I think this should be a standalone function, there happens a lot and if ever need more generics, they would just be added here too.

Code after:
                let shape_span = Span::new(span.start, span.start + shape_name.len());
                let shape = parse_shape_name(working_set, shape_name, shape_span, use_loc);
                if use_loc != ShapeDescriptorUse::Argument {
                    let illegal_span = Span::new(span.start + shape_name.len(), span.end);
                    working_set.error(ParseError::LabeledError(
                        "Unexpected custom completer in type spec".into(),
                        "Type specifications do not support custom completers".into(),
                        illegal_span,
                    ));
                    return shape;
                }

                let cmd_span = Span::new(span.start + shape_name.len() + 1, span.end);
                let cmd_name = split
                    .next()
                    .expect("If `bytes` contains `@` splitn returns 2 slices");

                let cmd_name = trim_quotes(cmd_name);
                if cmd_name.is_empty() {
                    working_set.error(ParseError::Expected(
                        "the command name of a completion function",
                        cmd_span,
                    ));
                    return shape;
                }

                if let Some(decl_id) = working_set.find_decl(cmd_name) {
                    return SyntaxShape::CompleterWrapper(Box::new(shape), decl_id);
                } else {
                    working_set.error(ParseError::UnknownCommand(cmd_span));
                    return shape;
                }
            } else {
                //TODO: Handle error case for unknown shapes
                working_set.error(ParseError::UnknownType(span));
                return SyntaxShape::Any;
            }
        }
    };

    result
}

fn parse_generic_shape(
    working_set: &mut StateWorkingSet<'_>,
    bytes: &[u8],
    span: Span,
    use_loc: ShapeDescriptorUse,
) -> SyntaxShape {
    let (type_name, type_params) = split_generic_params(working_set, bytes, span);
    match type_name {