mirror of
https://github.com/nushell/nushell.git
synced 2025-02-22 21:41:26 +01:00
Fix wrong spans of multiple files
The introduction of `use <file.nu>` added the possibility of calling `working_set.add_file()` more than once per parse pass. Some of the logic handling the file contents offsets prevented it from working and hopefully, this commit fixes it.
This commit is contained in:
parent
2dcfecbbd7
commit
7112664b3f
@ -218,8 +218,6 @@ pub fn parse_alias(
|
|||||||
|
|
||||||
let replacement = spans[3..].to_vec();
|
let replacement = spans[3..].to_vec();
|
||||||
|
|
||||||
//println!("{:?} {:?}", alias_name, replacement);
|
|
||||||
|
|
||||||
working_set.add_alias(alias_name, replacement);
|
working_set.add_alias(alias_name, replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,15 +309,15 @@ pub fn parse_export(
|
|||||||
|
|
||||||
pub fn parse_module_block(
|
pub fn parse_module_block(
|
||||||
working_set: &mut StateWorkingSet,
|
working_set: &mut StateWorkingSet,
|
||||||
spans: &[Span],
|
span: Span,
|
||||||
) -> (Block, Option<ParseError>) {
|
) -> (Block, Option<ParseError>) {
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
working_set.enter_scope();
|
working_set.enter_scope();
|
||||||
|
|
||||||
let source = working_set.get_span_contents(spans[0]);
|
let source = working_set.get_span_contents(span);
|
||||||
|
|
||||||
let (output, err) = lex(source, spans[0].start, &[], &[]);
|
let (output, err) = lex(source, span.start, &[], &[]);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
|
|
||||||
let (output, err) = lite_parse(&output);
|
let (output, err) = lite_parse(&output);
|
||||||
@ -380,8 +378,8 @@ pub fn parse_module_block(
|
|||||||
|
|
||||||
stmt
|
stmt
|
||||||
} else {
|
} else {
|
||||||
error = Some(ParseError::Expected("not a pipeline".into(), spans[0]));
|
error = Some(ParseError::Expected("not a pipeline".into(), span));
|
||||||
garbage_statement(spans)
|
garbage_statement(&[span])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.into();
|
.into();
|
||||||
@ -441,7 +439,7 @@ pub fn parse_module(
|
|||||||
|
|
||||||
let block_span = Span { start, end };
|
let block_span = Span { start, end };
|
||||||
|
|
||||||
let (block, err) = parse_module_block(working_set, &[block_span]);
|
let (block, err) = parse_module_block(working_set, block_span);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
|
|
||||||
let block_id = working_set.add_module(&module_name, block);
|
let block_id = working_set.add_module(&module_name, block);
|
||||||
@ -530,7 +528,7 @@ pub fn parse_use(
|
|||||||
let span_end = working_set.next_span_start();
|
let span_end = working_set.next_span_start();
|
||||||
|
|
||||||
let (block, err) =
|
let (block, err) =
|
||||||
parse_module_block(working_set, &[Span::new(span_start, span_end)]);
|
parse_module_block(working_set, Span::new(span_start, span_end));
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
|
|
||||||
let block_id = working_set.add_module(&module_name, block);
|
let block_id = working_set.add_module(&module_name, block);
|
||||||
|
@ -501,7 +501,7 @@ impl<'a> StateWorkingSet<'a> {
|
|||||||
let permanent_span_start = self.permanent_state.next_span_start();
|
let permanent_span_start = self.permanent_state.next_span_start();
|
||||||
|
|
||||||
if let Some((_, _, last)) = self.delta.file_contents.last() {
|
if let Some((_, _, last)) = self.delta.file_contents.last() {
|
||||||
permanent_span_start + *last
|
*last
|
||||||
} else {
|
} else {
|
||||||
permanent_span_start
|
permanent_span_start
|
||||||
}
|
}
|
||||||
@ -561,7 +561,7 @@ impl<'a> StateWorkingSet<'a> {
|
|||||||
if permanent_end <= span.start {
|
if permanent_end <= span.start {
|
||||||
for (contents, start, finish) in &self.delta.file_contents {
|
for (contents, start, finish) in &self.delta.file_contents {
|
||||||
if (span.start >= *start) && (span.end <= *finish) {
|
if (span.start >= *start) && (span.end <= *finish) {
|
||||||
return &contents[(span.start - permanent_end)..(span.end - permanent_end)];
|
return &contents[(span.start - start)..(span.end - start)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user