mirror of
https://github.com/nushell/nushell
synced 2025-01-05 01:39:02 +00:00
5664ee7bda
A small but easy optimization for `evaluate_repl()`: clone `engine_state` 1x instead of 3x. This reduces time spent in a simple REPL eval (`enter` key pressed with no command text) by about 10%, as measured in [Superluminal](https://superluminal.eu/).
21 lines
652 B
Rust
21 lines
652 B
Rust
use nu_parser::{parse, ParseError};
|
|
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
|
use reedline::{ValidationResult, Validator};
|
|
use std::sync::Arc;
|
|
|
|
pub struct NuValidator {
|
|
pub engine_state: Arc<EngineState>,
|
|
}
|
|
|
|
impl Validator for NuValidator {
|
|
fn validate(&self, line: &str) -> ValidationResult {
|
|
let mut working_set = StateWorkingSet::new(&self.engine_state);
|
|
let (_, err) = parse(&mut working_set, None, line.as_bytes(), false, &[]);
|
|
|
|
if matches!(err, Some(ParseError::UnexpectedEof(..))) {
|
|
ValidationResult::Incomplete
|
|
} else {
|
|
ValidationResult::Complete
|
|
}
|
|
}
|
|
}
|