This commit is contained in:
JT
2021-10-26 05:58:58 +13:00
parent baac60a5a7
commit 5d19017603
59 changed files with 125 additions and 140 deletions

View File

@ -1,6 +1,6 @@
use crate::{ast::Call, value::Value, BlockId, Example, PipelineData, ShellError, Signature};
use crate::{ast::Call, BlockId, Example, PipelineData, ShellError, Signature};
use super::{EngineState, EvaluationContext, Stack};
use super::{EngineState, Stack};
pub trait Command: Send + Sync + CommandClone {
fn name(&self) -> &str;

View File

@ -1,7 +1,7 @@
use super::Command;
use crate::{ast::Block, BlockId, DeclId, Example, Signature, Span, Type, VarId};
use core::panic;
use std::{collections::HashMap, slice::Iter};
use std::collections::HashMap;
#[derive(Clone)]
pub struct EngineState {
@ -167,7 +167,7 @@ impl EngineState {
pub fn print_contents(&self) {
for (contents, _, _) in self.file_contents.iter() {
let string = String::from_utf8_lossy(&contents);
let string = String::from_utf8_lossy(contents);
println!("{}", string);
}
}
@ -204,7 +204,7 @@ impl EngineState {
pub fn get_span_contents(&self, span: &Span) -> &[u8] {
for (contents, start, finish) in &self.file_contents {
if span.start >= *start && span.start <= *finish {
if span.start >= *start && span.end <= *finish {
return &contents[(span.start - start)..(span.end - start)];
}
}
@ -262,7 +262,11 @@ impl EngineState {
}
pub fn next_span_start(&self) -> usize {
self.file_contents.len()
if let Some((_, _, last)) = self.file_contents.last() {
*last
} else {
0
}
}
pub fn files(&self) -> impl Iterator<Item = &(String, usize, usize)> {
@ -494,7 +498,13 @@ impl<'a> StateWorkingSet<'a> {
}
pub fn next_span_start(&self) -> usize {
self.permanent_state.next_span_start() + self.delta.file_contents.len()
let permanent_span_start = self.permanent_state.next_span_start();
if let Some((_, _, last)) = self.delta.file_contents.last() {
permanent_span_start + *last
} else {
permanent_span_start
}
}
pub fn global_span_offset(&self) -> usize {
@ -550,7 +560,7 @@ impl<'a> StateWorkingSet<'a> {
let permanent_end = self.permanent_state.next_span_start();
if permanent_end <= span.start {
for (contents, start, finish) in &self.delta.file_contents {
if (span.start >= *start) && (span.start <= *finish) {
if (span.start >= *start) && (span.end <= *finish) {
return &contents[(span.start - permanent_end)..(span.end - permanent_end)];
}
}

View File

@ -1,5 +1,5 @@
use super::EngineState;
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use std::collections::HashMap;
use crate::{Example, ShellError, Signature, Value, VarId};

View File

@ -1,13 +1,10 @@
use crate::ast::Call;
use crate::engine::Command;
use crate::engine::CommandClone;
use crate::engine::EngineState;
use crate::engine::EvaluationContext;
use crate::engine::Stack;
use crate::BlockId;
use crate::PipelineData;
use crate::SyntaxShape;
use crate::Value;
use crate::VarId;
#[derive(Debug, Clone, PartialEq, Eq)]