mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 22:57:07 +02:00
limit the ide-check error amount (#8875)
# Description This PR limits the amount of errors returned with the --ide-check flag. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
parent
3603610026
commit
a33a7960bb
@ -37,9 +37,8 @@ pub(crate) fn gather_commandline_args() -> (Vec<String>, String, Vec<String>) {
|
|||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
"--plugin-config" => args.next().map(|a| escape_quote_string(&a)),
|
"--plugin-config" => args.next().map(|a| escape_quote_string(&a)),
|
||||||
"--log-level" | "--log-target" | "--testbin" | "--threads" | "-t"
|
"--log-level" | "--log-target" | "--testbin" | "--threads" | "-t"
|
||||||
| "--include-path" | "-I" | "--ide-goto-def" | "--ide-hover" | "--ide-complete" => {
|
| "--include-path" | "-I" | "--ide-goto-def" | "--ide-hover" | "--ide-complete"
|
||||||
args.next()
|
| "--ide-check" => args.next(),
|
||||||
}
|
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,12 +91,6 @@ pub(crate) fn parse_commandline_args(
|
|||||||
)) = pipeline.elements.get(0)
|
)) = pipeline.elements.get(0)
|
||||||
{
|
{
|
||||||
let redirect_stdin = call.get_named_arg("stdin");
|
let redirect_stdin = call.get_named_arg("stdin");
|
||||||
let ide_goto_def: Option<Value> =
|
|
||||||
call.get_flag(engine_state, &mut stack, "ide-goto-def")?;
|
|
||||||
let ide_hover: Option<Value> = call.get_flag(engine_state, &mut stack, "ide-hover")?;
|
|
||||||
let ide_complete: Option<Value> =
|
|
||||||
call.get_flag(engine_state, &mut stack, "ide-complete")?;
|
|
||||||
let ide_check = call.get_named_arg("ide-check");
|
|
||||||
let login_shell = call.get_named_arg("login");
|
let login_shell = call.get_named_arg("login");
|
||||||
let interactive_shell = call.get_named_arg("interactive");
|
let interactive_shell = call.get_named_arg("interactive");
|
||||||
let commands: Option<Expression> = call.get_flag_expr("commands");
|
let commands: Option<Expression> = call.get_flag_expr("commands");
|
||||||
@ -115,6 +108,13 @@ pub(crate) fn parse_commandline_args(
|
|||||||
let table_mode: Option<Value> =
|
let table_mode: Option<Value> =
|
||||||
call.get_flag(engine_state, &mut stack, "table-mode")?;
|
call.get_flag(engine_state, &mut stack, "table-mode")?;
|
||||||
|
|
||||||
|
let ide_goto_def: Option<Value> =
|
||||||
|
call.get_flag(engine_state, &mut stack, "ide-goto-def")?;
|
||||||
|
let ide_hover: Option<Value> = call.get_flag(engine_state, &mut stack, "ide-hover")?;
|
||||||
|
let ide_complete: Option<Value> =
|
||||||
|
call.get_flag(engine_state, &mut stack, "ide-complete")?;
|
||||||
|
let ide_check: Option<Value> = call.get_flag(engine_state, &mut stack, "ide-check")?;
|
||||||
|
|
||||||
fn extract_contents(
|
fn extract_contents(
|
||||||
expression: Option<Expression>,
|
expression: Option<Expression>,
|
||||||
) -> Result<Option<Spanned<String>>, ShellError> {
|
) -> Result<Option<Spanned<String>>, ShellError> {
|
||||||
@ -229,7 +229,7 @@ pub(crate) struct NushellCliArgs {
|
|||||||
pub(crate) ide_goto_def: Option<Value>,
|
pub(crate) ide_goto_def: Option<Value>,
|
||||||
pub(crate) ide_hover: Option<Value>,
|
pub(crate) ide_hover: Option<Value>,
|
||||||
pub(crate) ide_complete: Option<Value>,
|
pub(crate) ide_complete: Option<Value>,
|
||||||
pub(crate) ide_check: Option<Spanned<String>>,
|
pub(crate) ide_check: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -312,8 +312,9 @@ impl Command for Nu {
|
|||||||
"list completions for the item at the given position",
|
"list completions for the item at the given position",
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.switch(
|
.named(
|
||||||
"ide-check",
|
"ide-check",
|
||||||
|
SyntaxShape::Int,
|
||||||
"run a diagnostic check on the given source",
|
"run a diagnostic check on the given source",
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
14
src/ide.rs
14
src/ide.rs
@ -74,18 +74,28 @@ fn read_in_file<'a>(
|
|||||||
(file, working_set)
|
(file, working_set)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(engine_state: &mut EngineState, file_path: &String) {
|
pub fn check(engine_state: &mut EngineState, file_path: &String, max_errors: &Value) {
|
||||||
let cwd = std::env::current_dir().expect("Could not get current working directory.");
|
let cwd = std::env::current_dir().expect("Could not get current working directory.");
|
||||||
engine_state.add_env_var("PWD".into(), Value::test_string(cwd.to_string_lossy()));
|
engine_state.add_env_var("PWD".into(), Value::test_string(cwd.to_string_lossy()));
|
||||||
|
|
||||||
let mut working_set = StateWorkingSet::new(engine_state);
|
let mut working_set = StateWorkingSet::new(engine_state);
|
||||||
let file = std::fs::read(file_path);
|
let file = std::fs::read(file_path);
|
||||||
|
|
||||||
|
let max_errors = if let Ok(max_errors) = max_errors.as_i64() {
|
||||||
|
max_errors as usize
|
||||||
|
} else {
|
||||||
|
100
|
||||||
|
};
|
||||||
|
|
||||||
if let Ok(contents) = file {
|
if let Ok(contents) = file {
|
||||||
let offset = working_set.next_span_start();
|
let offset = working_set.next_span_start();
|
||||||
let block = parse(&mut working_set, Some(file_path), &contents, false);
|
let block = parse(&mut working_set, Some(file_path), &contents, false);
|
||||||
|
|
||||||
for err in &working_set.parse_errors {
|
for (idx, err) in working_set.parse_errors.iter().enumerate() {
|
||||||
|
if idx >= max_errors {
|
||||||
|
// eprintln!("Too many errors, stopping here. idx: {idx} max_errors: {max_errors}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
let mut span = err.span();
|
let mut span = err.span();
|
||||||
span.start -= offset;
|
span.start -= offset;
|
||||||
span.end -= offset;
|
span.end -= offset;
|
||||||
|
@ -167,8 +167,8 @@ fn main() -> Result<()> {
|
|||||||
ide::complete(Arc::new(engine_state), &script_name, &ide_complete);
|
ide::complete(Arc::new(engine_state), &script_name, &ide_complete);
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else if parsed_nu_cli_args.ide_check.is_some() {
|
} else if let Some(max_errors) = parsed_nu_cli_args.ide_check {
|
||||||
ide::check(&mut engine_state, &script_name);
|
ide::check(&mut engine_state, &script_name, &max_errors);
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use crate::tests::{test_ide_contains, TestResult};
|
|||||||
fn parser_recovers() -> TestResult {
|
fn parser_recovers() -> TestResult {
|
||||||
test_ide_contains(
|
test_ide_contains(
|
||||||
"3 + \"bob\"\nlet x = \"fred\"\n",
|
"3 + \"bob\"\nlet x = \"fred\"\n",
|
||||||
&["--ide-check"],
|
&["--ide-check 5"],
|
||||||
"\"typename\":\"string\"",
|
"\"typename\":\"string\"",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user