mirror of
https://github.com/nushell/nushell.git
synced 2025-05-19 01:10:48 +02:00
# Description `Value` describes the types of first-class values that users and scripts can create, manipulate, pass around, and store. However, `Block`s are not first-class values in the language, so this PR removes it from `Value`. This removes some unnecessary code, and this change should be invisible to the user except for the change to `scope modules` described below. # User-Facing Changes Breaking change: the output of `scope modules` was changed so that `env_block` is now `has_env_block` which is a boolean value instead of a `Block`. # After Submitting Update the language guide possibly.
56 lines
1.5 KiB
Rust
56 lines
1.5 KiB
Rust
use std::str::FromStr;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{record, Config, Span, Value};
|
|
|
|
use super::helper::ReconstructVal;
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Default)]
|
|
pub enum CompletionAlgorithm {
|
|
#[default]
|
|
Prefix,
|
|
Fuzzy,
|
|
}
|
|
|
|
impl FromStr for CompletionAlgorithm {
|
|
type Err = &'static str;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
match s.to_ascii_lowercase().as_str() {
|
|
"prefix" => Ok(Self::Prefix),
|
|
"fuzzy" => Ok(Self::Fuzzy),
|
|
_ => Err("expected either 'prefix' or 'fuzzy'"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ReconstructVal for CompletionAlgorithm {
|
|
fn reconstruct_value(&self, span: Span) -> Value {
|
|
let str = match self {
|
|
CompletionAlgorithm::Prefix => "prefix",
|
|
CompletionAlgorithm::Fuzzy => "fuzzy",
|
|
};
|
|
Value::string(str, span)
|
|
}
|
|
}
|
|
|
|
pub(super) fn reconstruct_external_completer(config: &Config, span: Span) -> Value {
|
|
if let Some(closure) = config.external_completer.as_ref() {
|
|
Value::closure(closure.clone(), span)
|
|
} else {
|
|
Value::nothing(span)
|
|
}
|
|
}
|
|
|
|
pub(super) fn reconstruct_external(config: &Config, span: Span) -> Value {
|
|
Value::record(
|
|
record! {
|
|
"max_results" => Value::int(config.max_external_completion_results, span),
|
|
"completer" => reconstruct_external_completer(config, span),
|
|
"enable" => Value::bool(config.enable_external_completion, span),
|
|
},
|
|
span,
|
|
)
|
|
}
|