nushell/crates/nu-cli/src/validation.rs

21 lines
627 B
Rust
Raw Normal View History

2021-09-22 05:29:53 +00:00
use nu_parser::{parse, ParseError};
use nu_protocol::engine::{EngineState, StateWorkingSet};
use reedline::{ValidationResult, Validator};
pub struct NuValidator {
2021-10-25 06:31:39 +00:00
pub engine_state: EngineState,
2021-09-22 05:29:53 +00:00
}
impl Validator for NuValidator {
fn validate(&self, line: &str) -> ValidationResult {
2021-10-25 06:31:39 +00:00
let mut working_set = StateWorkingSet::new(&self.engine_state);
let (_, err) = parse(&mut working_set, None, line.as_bytes(), false, &[]);
2021-09-22 05:29:53 +00:00
if matches!(err, Some(ParseError::UnexpectedEof(..))) {
ValidationResult::Incomplete
} else {
ValidationResult::Complete
}
}
}