forked from extern/nushell
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();
|
||||
|
||||
//println!("{:?} {:?}", alias_name, replacement);
|
||||
|
||||
working_set.add_alias(alias_name, replacement);
|
||||
}
|
||||
|
||||
@ -311,15 +309,15 @@ pub fn parse_export(
|
||||
|
||||
pub fn parse_module_block(
|
||||
working_set: &mut StateWorkingSet,
|
||||
spans: &[Span],
|
||||
span: Span,
|
||||
) -> (Block, Option<ParseError>) {
|
||||
let mut error = None;
|
||||
|
||||
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);
|
||||
|
||||
let (output, err) = lite_parse(&output);
|
||||
@ -380,8 +378,8 @@ pub fn parse_module_block(
|
||||
|
||||
stmt
|
||||
} else {
|
||||
error = Some(ParseError::Expected("not a pipeline".into(), spans[0]));
|
||||
garbage_statement(spans)
|
||||
error = Some(ParseError::Expected("not a pipeline".into(), span));
|
||||
garbage_statement(&[span])
|
||||
}
|
||||
})
|
||||
.into();
|
||||
@ -441,7 +439,7 @@ pub fn parse_module(
|
||||
|
||||
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);
|
||||
|
||||
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 (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);
|
||||
|
||||
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();
|
||||
|
||||
if let Some((_, _, last)) = self.delta.file_contents.last() {
|
||||
permanent_span_start + *last
|
||||
*last
|
||||
} else {
|
||||
permanent_span_start
|
||||
}
|
||||
@ -561,7 +561,7 @@ impl<'a> StateWorkingSet<'a> {
|
||||
if permanent_end <= span.start {
|
||||
for (contents, start, finish) in &self.delta.file_contents {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user