Repository: nushell/nushell
File: crates/nu-cli/src/completions/custom_completions.rs (Rust)

Code before:
                    "span" => {
                        if let Value::Record { val: span, .. } = value {
                            let start = span
                                .get("start")
                                .and_then(|val| val.as_int().ok())
                                .and_then(|x| usize::try_from(x).ok());
                            let end = span
                                .get("end")
                                .and_then(|val| val.as_int().ok())
                                .and_then(|x| usize::try_from(x).ok());
                            // TODO: error on invalid spans?
                            match (start, end) {
                                (Some(start), Some(end)) => {
                                    suggestion.span = reedline::Span {
                                        start: start.min(end),
                                        end,
                                    };
                                }
                                (Some(start), None) => {
                                    suggestion.span.start = start.min(suggestion.span.end);
                                }
                                (None, Some(end)) => {
                                    suggestion.span.end = end.max(suggestion.span.start);
                                }
                                _ => (),
                            }
                            if let (Some(start), Some(end)) = (start, end) {
                                suggestion.span = reedline::Span {
                                    start: start.min(end),
                                    end,
                                };
                            }
                        }
                    }
                    _ => (),
                }
            });

            return Some(SemanticSuggestion {
                suggestion,
                kind: Some(SuggestionKind::Value(value_type)),
            });
        }

        None
    })
    .collect()
}

pub struct CustomCompletion<T: Completer> {
    decl_id: DeclId,

Review comment (suggestion):
I moved `map_value_completions` to this file since it's the only place calling that function.

And this is the span related change.

Code after:
                    "span" => {
                        if let Value::Record { val: span, .. } = value {
                            let start = span
                                .get("start")
                                .and_then(|val| val.as_int().ok())
                                .and_then(|x| usize::try_from(x).ok());
                            let end = span
                                .get("end")
                                .and_then(|val| val.as_int().ok())
                                .and_then(|x| usize::try_from(x).ok());
                            // TODO: error on invalid spans?
                            match (start, end) {
                                (Some(start), Some(end)) => {
                                    suggestion.span = reedline::Span {
                                        start: start.min(end),
                                        end,
                                    };
                                }
                                (Some(start), None) => {
                                    suggestion.span.start = start.min(suggestion.span.end);
                                }
                                (None, Some(end)) => {
                                    suggestion.span.end = end.max(suggestion.span.start);
                                }
                                _ => (),
                            }
                        }
                    }
                    _ => (),
                }
            });

            return Some(SemanticSuggestion {
                suggestion,
                kind: Some(SuggestionKind::Value(value_type)),
            });
        }

        None
    })
    .collect()
}

pub struct CustomCompletion<T: Completer> {
    decl_id: DeclId,
    line: String,
    line_pos: usize,
    fallback: T,
}

impl<T: Completer> CustomCompletion<T> {