diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index a646663b2..6dae201d6 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -4423,6 +4423,8 @@ pub fn parse_value( span: Span, shape: &SyntaxShape, ) -> Expression { + trace!("parsing: value: {}", shape); + let bytes = working_set.get_span_contents(span); if bytes.is_empty() { @@ -4595,7 +4597,7 @@ pub fn parse_value( if starting_error_count == working_set.parse_errors.len() { return s; } else { - match working_set.parse_errors.first() { + match working_set.parse_errors.get(starting_error_count) { Some(ParseError::Expected(_, _)) => { working_set.parse_errors.truncate(starting_error_count); continue; diff --git a/src/tests.rs b/src/tests.rs index 4d5f21325..e46cfa1fb 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -8,6 +8,7 @@ mod test_custom_commands; mod test_engine; mod test_env; mod test_hiding; +mod test_ide; mod test_iteration; mod test_known_external; mod test_math; @@ -101,6 +102,34 @@ pub fn run_test_contains(input: &str, expected: &str) -> TestResult { Ok(()) } +#[cfg(test)] +pub fn test_ide_contains(input: &str, ide_commands: &[&str], expected: &str) -> TestResult { + let mut file = NamedTempFile::new()?; + let name = file.path(); + + let mut cmd = Command::cargo_bin("nu")?; + for ide_command in ide_commands { + cmd.arg(ide_command); + } + cmd.arg(name); + + writeln!(file, "{input}")?; + + let output = cmd.output()?; + + let stderr = String::from_utf8_lossy(&output.stderr).to_string(); + let stdout = String::from_utf8_lossy(&output.stdout).to_string(); + + println!("stdout: {stdout}"); + println!("stderr: {stderr}"); + + assert!(output.status.success()); + + assert!(stdout.contains(expected)); + + Ok(()) +} + #[cfg(test)] pub fn fail_test(input: &str, expected: &str) -> TestResult { let mut file = NamedTempFile::new()?; diff --git a/src/tests/test_ide.rs b/src/tests/test_ide.rs new file mode 100644 index 000000000..d7404c0dc --- /dev/null +++ b/src/tests/test_ide.rs @@ -0,0 +1,10 @@ +use crate::tests::{test_ide_contains, TestResult}; + +#[test] +fn parser_recovers() -> TestResult { + test_ide_contains( + "3 + \"bob\"\nlet x = \"fred\"\n", + &["--ide-check"], + "\"typename\":\"String\"", + ) +}