mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
multiline validation
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
mod completions;
|
||||
mod errors;
|
||||
mod syntax_highlight;
|
||||
mod validation;
|
||||
|
||||
pub use completions::NuCompleter;
|
||||
pub use errors::report_error;
|
||||
pub use syntax_highlight::NuHighlighter;
|
||||
pub use validation::NuValidator;
|
||||
|
23
crates/nu-cli/src/validation.rs
Normal file
23
crates/nu-cli/src/validation.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use nu_parser::{parse, ParseError};
|
||||
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
||||
use reedline::{ValidationResult, Validator};
|
||||
|
||||
pub struct NuValidator {
|
||||
pub engine_state: Rc<RefCell<EngineState>>,
|
||||
}
|
||||
|
||||
impl Validator for NuValidator {
|
||||
fn validate(&self, line: &str) -> ValidationResult {
|
||||
let engine_state = self.engine_state.borrow();
|
||||
let mut working_set = StateWorkingSet::new(&*engine_state);
|
||||
let (_, err) = parse(&mut working_set, None, line.as_bytes(), false);
|
||||
|
||||
if matches!(err, Some(ParseError::UnexpectedEof(..))) {
|
||||
ValidationResult::Incomplete
|
||||
} else {
|
||||
ValidationResult::Complete
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user