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

Code before:
                match key.as_str() {
                    "value" => {
                        value_type = value.get_type();
                        // Convert the value to string
                        if let Ok(val_str) = value.coerce_string() {
                            // Update the suggestion value
                            suggestion.value = val_str;
                        }
                    }
                    "description" => {
                        // Convert the value to string
                        if let Ok(desc_str) = value.coerce_string() {
                            // Update the suggestion value
                            suggestion.description = Some(desc_str);
                        }
                    }
                    "style" => {
                        // Convert the value to string
                        suggestion.style = match value {
                            Value::String { val, .. } => Some(lookup_ansi_color_style(val)),
                            Value::Record { .. } => Some(color_record_to_nustyle(value)),
                            _ => None,
                        };
                    }
                    _ => (),
                }
            });

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

        None
    })
    .collect()
}

#[cfg(test)]
mod completer_tests {
    use super::*;

    #[test]
    fn test_completion_helper() {
        let mut engine_state =
            nu_command::add_shell_command_context(nu_cmd_lang::create_default_context());

        // Custom additions
        let delta = {
            let working_set = nu_protocol::engine::StateWorkingSet::new(&engine_state);

Review comment (suggestion):
This is a general deficiency of both the reedline and the explore config that it doesn't error on invalid config while the rest is pretty good at raising it.

Code after:
                match key.as_str() {
                    "value" => {
                        value_type = value.get_type();
                        // Convert the value to string
                        if let Ok(val_str) = value.coerce_string() {
                            // Update the suggestion value
                            suggestion.value = val_str;
                        }
                    }
                    "description" => {
                        // Convert the value to string
                        if let Ok(desc_str) = value.coerce_string() {
                            // Update the suggestion value
                            suggestion.description = Some(desc_str);
                        }
                    }
                    "style" => {
                        // Convert the value to string
                        suggestion.style = match value {
                            Value::String { val, .. } => Some(lookup_ansi_color_style(val)),
                            Value::Record { .. } => Some(color_record_to_nustyle(value)),
                            _ => None,
                        };
                    }
                    "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());
                            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)),
            });
        }