mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 12:09:00 +02:00
Add warning when using $in at the beginning of a block
This commit is contained in:
@ -1132,6 +1132,21 @@ impl<'a> GetSpan for &'a StateWorkingSet<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl GetSpan for StateWorkingSet<'_> {
|
||||
fn get_span(&self, span_id: SpanId) -> Span {
|
||||
let num_permanent_spans = self.permanent_state.num_spans();
|
||||
if span_id.get() < num_permanent_spans {
|
||||
self.permanent_state.get_span(span_id)
|
||||
} else {
|
||||
*self
|
||||
.delta
|
||||
.spans
|
||||
.get(span_id.get() - num_permanent_spans)
|
||||
.expect("internal error: missing span")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl miette::SourceCode for &StateWorkingSet<'_> {
|
||||
fn read_span<'b>(
|
||||
&'b self,
|
||||
|
@ -14,12 +14,20 @@ pub enum ParseWarning {
|
||||
span: Span,
|
||||
url: String,
|
||||
},
|
||||
|
||||
#[error("Found $in at the start of a command.")]
|
||||
#[diagnostic(help("Using $in at the start of a command collects the pipeline input.\nIf you did mean to collect the pipeline input, replace this with the `collect` command."))]
|
||||
UnnecessaryInVariable {
|
||||
#[label("try removing this")]
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
impl ParseWarning {
|
||||
pub fn span(&self) -> Span {
|
||||
match self {
|
||||
ParseWarning::DeprecatedWarning { span, .. } => *span,
|
||||
ParseWarning::UnnecessaryInVariable { span, .. } => *span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user