mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Back to working state
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use nu_protocol::{EngineState, Signature, StateWorkingSet, SyntaxShape};
|
||||
use nu_protocol::{
|
||||
engine::{EngineState, StateWorkingSet},
|
||||
Signature, SyntaxShape,
|
||||
};
|
||||
|
||||
pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
let engine_state = Rc::new(RefCell::new(EngineState::new()));
|
||||
@ -10,7 +13,7 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
|
||||
let sig =
|
||||
Signature::build("where").required("cond", SyntaxShape::RowCondition, "condition");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("if")
|
||||
.required("cond", SyntaxShape::Expression, "condition")
|
||||
@ -20,7 +23,7 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
SyntaxShape::Keyword(b"else".to_vec(), Box::new(SyntaxShape::Expression)),
|
||||
"optional else followed by else block",
|
||||
);
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("let")
|
||||
.required("var_name", SyntaxShape::VarWithOptType, "variable name")
|
||||
@ -29,7 +32,7 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
|
||||
"equals sign followed by value",
|
||||
);
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("let-env")
|
||||
.required("var_name", SyntaxShape::String, "variable name")
|
||||
@ -38,7 +41,7 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::String)),
|
||||
"equals sign followed by value",
|
||||
);
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("alias")
|
||||
.required("name", SyntaxShape::String, "name of the alias")
|
||||
@ -47,16 +50,16 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
|
||||
"equals sign followed by value",
|
||||
);
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("build-string").rest(SyntaxShape::String, "list of string");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("def")
|
||||
.required("def_name", SyntaxShape::String, "definition name")
|
||||
.required("params", SyntaxShape::Signature, "parameters")
|
||||
.required("block", SyntaxShape::Block, "body of the definition");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("for")
|
||||
.required(
|
||||
@ -70,11 +73,11 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
"range of the loop",
|
||||
)
|
||||
.required("block", SyntaxShape::Block, "the block to run");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig =
|
||||
Signature::build("benchmark").required("block", SyntaxShape::Block, "the block to run");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
// let sig = Signature::build("foo").named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'));
|
||||
// working_set.add_decl(sig.into());
|
||||
@ -84,25 +87,25 @@ pub fn create_default_context() -> Rc<RefCell<EngineState>> {
|
||||
// .switch("--rock", "rock!!", Some('r'));
|
||||
// working_set.add_decl(sig.into());
|
||||
let sig = Signature::build("exit");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
let sig = Signature::build("vars");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
let sig = Signature::build("decls");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
let sig = Signature::build("blocks");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
let sig = Signature::build("stack");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("add");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
let sig = Signature::build("add it");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
let sig = Signature::build("add it together")
|
||||
.required("x", SyntaxShape::Int, "x value")
|
||||
.required("y", SyntaxShape::Int, "y value");
|
||||
working_set.add_decl(sig.into());
|
||||
working_set.add_decl(sig.predeclare());
|
||||
|
||||
working_set.render()
|
||||
};
|
||||
|
@ -3,7 +3,7 @@ use core::ops::Range;
|
||||
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
||||
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
|
||||
use nu_parser::ParseError;
|
||||
use nu_protocol::{ShellError, Span, StateWorkingSet};
|
||||
use nu_protocol::{engine::StateWorkingSet, ShellError, Span};
|
||||
|
||||
fn convert_span_to_diag(
|
||||
working_set: &StateWorkingSet,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use nu_ansi_term::Style;
|
||||
use nu_parser::FlatShape;
|
||||
use nu_protocol::{EngineState, StateWorkingSet};
|
||||
use nu_parser::{flatten_block, parse_source, FlatShape};
|
||||
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
||||
use reedline::{Highlighter, StyledText};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
@ -13,9 +13,9 @@ impl Highlighter for NuHighlighter {
|
||||
let (shapes, global_span_offset) = {
|
||||
let engine_state = self.engine_state.borrow();
|
||||
let mut working_set = StateWorkingSet::new(&*engine_state);
|
||||
let (block, _) = working_set.parse_source(line.as_bytes(), false);
|
||||
let (block, _) = parse_source(&mut working_set, line.as_bytes(), false);
|
||||
|
||||
let shapes = working_set.flatten_block(&block);
|
||||
let shapes = flatten_block(&working_set, &block);
|
||||
(shapes, engine_state.next_span_start())
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user