mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 06:58:36 +02:00
Add Span
merging functions (#12511)
# Description This PR adds a few functions to `Span` for merging spans together: - `Span::append`: merges two spans that are known to be in order. - `Span::concat`: returns a span that encompasses all the spans in a slice. The spans must be in order. - `Span::merge`: merges two spans (no order necessary). - `Span::merge_many`: merges an iterator of spans into a single span (no order necessary). These are meant to replace the free-standing `nu_protocol::span` function. The spans in a `LiteCommand` (the `parts`) should always be in order based on the lite parser and lexer. So, the parser code sees the most usage of `Span::append` and `Span::concat` where the order is known. In other code areas, `Span::merge` and `Span::merge_many` are used since the order between spans is often not known.
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::span;
|
||||
use std::io::IsTerminal as _;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -57,12 +56,9 @@ impl Command for IsTerminal {
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
let spans: Vec<_> = call.arguments.iter().map(|arg| arg.span()).collect();
|
||||
let span = span(&spans);
|
||||
|
||||
return Err(ShellError::IncompatibleParametersSingle {
|
||||
msg: "Only one stream may be checked".into(),
|
||||
span,
|
||||
span: Span::merge_many(call.arguments.iter().map(|arg| arg.span())),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,5 +1,4 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::span;
|
||||
use std::process::{Command as CommandSys, Stdio};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -96,7 +95,7 @@ impl Command for Kill {
|
||||
})?
|
||||
.span,
|
||||
right_message: "signal".to_string(),
|
||||
right_span: span(&[
|
||||
right_span: Span::merge(
|
||||
call.get_named_arg("signal")
|
||||
.ok_or_else(|| ShellError::GenericError {
|
||||
error: "Flag error".into(),
|
||||
@ -107,7 +106,7 @@ impl Command for Kill {
|
||||
})?
|
||||
.span,
|
||||
signal_span,
|
||||
]),
|
||||
),
|
||||
});
|
||||
}
|
||||
cmd.arg("-9");
|
||||
|
Reference in New Issue
Block a user