pub struct EngineState {Show 17 fields
pub spans: Vec<Span>,
pub scope: ScopeFrame,
pub signal_handlers: Option<Handlers>,
pub env_vars: Arc<EnvVars>,
pub previous_env_vars: Arc<HashMap<String, Value>>,
pub config: Arc<Config>,
pub pipeline_externals_state: Arc<(AtomicU32, AtomicU32)>,
pub repl_state: Arc<Mutex<ReplState>>,
pub table_decl_id: Option<DeclId>,
pub plugin_path: Option<PathBuf>,
pub history_enabled: bool,
pub history_session_id: i64,
pub file: Option<PathBuf>,
pub regex_cache: Arc<Mutex<LruCache<String, Regex>>>,
pub is_interactive: bool,
pub is_login: bool,
pub debugger: Arc<Mutex<Box<dyn Debugger>>>,
/* private fields */
}
Expand description
The core global engine state. This includes all global definitions as well as any global state that will persist for the whole session.
Declarations, variables, blocks, and other forms of data are held in the global state and referenced elsewhere using their IDs. These IDs are simply their index into the global state. This allows us to more easily handle creating blocks, binding variables and callsites, and more, because each of these will refer to the corresponding IDs rather than their definitions directly. At runtime, this means less copying and smaller structures.
Many of the larger objects in this structure are stored within Arc
to decrease the cost of
cloning EngineState
. While Arc
s are generally immutable, they can be modified using
Arc::make_mut
, which automatically clones to a new allocation if there are other copies of
the Arc
already in use, but will let us modify the Arc
directly if we have the only
reference to it.
Note that the runtime stack is not part of this global state. Runtime stacks are handled differently, but they also rely on using IDs rather than full definitions.
Fields§
§spans: Vec<Span>
§scope: ScopeFrame
§signal_handlers: Option<Handlers>
§env_vars: Arc<EnvVars>
§previous_env_vars: Arc<HashMap<String, Value>>
§config: Arc<Config>
§pipeline_externals_state: Arc<(AtomicU32, AtomicU32)>
§repl_state: Arc<Mutex<ReplState>>
§table_decl_id: Option<DeclId>
§plugin_path: Option<PathBuf>
§history_enabled: bool
§history_session_id: i64
§file: Option<PathBuf>
§regex_cache: Arc<Mutex<LruCache<String, Regex>>>
§is_interactive: bool
§is_login: bool
§debugger: Arc<Mutex<Box<dyn Debugger>>>
Implementations§
Source§impl EngineState
impl EngineState
pub fn new() -> Self
pub fn signals(&self) -> &Signals
pub fn reset_signals(&mut self)
pub fn set_signals(&mut self, signals: Signals)
Sourcepub fn merge_delta(&mut self, delta: StateDelta) -> Result<(), ShellError>
pub fn merge_delta(&mut self, delta: StateDelta) -> Result<(), ShellError>
Merges a StateDelta
onto the current state. These deltas come from a system, like the parser, that
creates a new set of definitions and visible symbols in the current scope. We make this transactional
as there are times when we want to run the parser and immediately throw away the results (namely:
syntax highlighting and completions).
When we want to preserve what the parser has created, we can take its output (the StateDelta
) and
use this function to merge it into the global state.
Sourcepub fn merge_env(&mut self, stack: &mut Stack) -> Result<(), ShellError>
pub fn merge_env(&mut self, stack: &mut Stack) -> Result<(), ShellError>
Merge the environment from the runtime Stack into the engine state
pub fn has_overlay(&self, name: &[u8]) -> bool
pub fn active_overlay_ids<'a, 'b>(
&'b self,
removed_overlays: &'a [Vec<u8>],
) -> impl DoubleEndedIterator<Item = &OverlayId> + 'awhere
'b: 'a,
pub fn active_overlays<'a, 'b>(
&'b self,
removed_overlays: &'a [Vec<u8>],
) -> impl DoubleEndedIterator<Item = &OverlayFrame> + 'awhere
'b: 'a,
pub fn active_overlay_names<'a, 'b>(
&'b self,
removed_overlays: &'a [Vec<u8>],
) -> impl DoubleEndedIterator<Item = &[u8]> + 'awhere
'b: 'a,
Sourcepub fn translate_overlay_ids(&self, other: &ScopeFrame) -> Vec<OverlayId>
pub fn translate_overlay_ids(&self, other: &ScopeFrame) -> Vec<OverlayId>
Translate overlay IDs from other to IDs in self
pub fn last_overlay_name(&self, removed_overlays: &[Vec<u8>]) -> &[u8] ⓘ
pub fn last_overlay(&self, removed_overlays: &[Vec<u8>]) -> &OverlayFrame
pub fn get_overlay_name(&self, overlay_id: OverlayId) -> &[u8] ⓘ
pub fn get_overlay(&self, overlay_id: OverlayId) -> &OverlayFrame
pub fn render_env_vars(&self) -> HashMap<&str, &Value>
pub fn add_env_var(&mut self, name: String, val: Value)
pub fn get_env_var(&self, name: &str) -> Option<&Value>
pub fn get_path_env_var(&self) -> Option<&Value>
pub fn plugins(&self) -> &[Arc<dyn RegisteredPlugin>]
pub fn update_plugin_file( &self, updated_items: Vec<PluginRegistryItem>, ) -> Result<(), ShellError>
pub fn num_files(&self) -> usize
pub fn num_virtual_paths(&self) -> usize
pub fn num_vars(&self) -> usize
pub fn num_decls(&self) -> usize
pub fn num_blocks(&self) -> usize
pub fn num_modules(&self) -> usize
pub fn num_spans(&self) -> usize
pub fn print_vars(&self)
pub fn print_decls(&self)
pub fn print_blocks(&self)
pub fn print_contents(&self)
pub fn find_decl( &self, name: &[u8], removed_overlays: &[Vec<u8>], ) -> Option<DeclId>
pub fn find_decl_name( &self, decl_id: DeclId, removed_overlays: &[Vec<u8>], ) -> Option<&[u8]>
pub fn get_module_comments(&self, module_id: ModuleId) -> Option<&[Span]>
pub fn plugin_decls(&self) -> impl Iterator<Item = &Box<dyn Command + 'static>>
pub fn find_module( &self, name: &[u8], removed_overlays: &[Vec<u8>], ) -> Option<ModuleId>
pub fn which_module_has_decl( &self, decl_name: &[u8], removed_overlays: &[Vec<u8>], ) -> Option<&[u8]>
pub fn find_overlay(&self, name: &[u8]) -> Option<OverlayId>
pub fn find_active_overlay(&self, name: &[u8]) -> Option<OverlayId>
pub fn find_commands_by_predicate( &self, predicate: impl Fn(&[u8]) -> bool, ignore_deprecated: bool, ) -> Vec<(Vec<u8>, Option<String>, CommandType)>
pub fn get_span_contents(&self, span: Span) -> &[u8] ⓘ
Sourcepub fn get_config(&self) -> &Arc<Config>
pub fn get_config(&self) -> &Arc<Config>
Get the global config from the engine state.
Use Stack::get_config()
instead whenever the Stack
is available, as it takes into
account local changes to $env.config
.
pub fn set_config(&mut self, conf: impl Into<Arc<Config>>)
Sourcepub fn get_plugin_config(&self, plugin: &str) -> Option<&Value>
pub fn get_plugin_config(&self, plugin: &str) -> Option<&Value>
Fetch the configuration for a plugin
The plugin
must match the registered name of a plugin. For plugin add nu_plugin_example
the plugin name to use will be "example"
Sourcepub fn history_config(&self) -> Option<HistoryConfig>
pub fn history_config(&self) -> Option<HistoryConfig>
Returns the configuration settings for command history or None
if history is disabled
pub fn get_var(&self, var_id: VarId) -> &Variable
pub fn get_constant(&self, var_id: VarId) -> Option<&Value>
pub fn generate_nu_constant(&mut self)
pub fn get_decl(&self, decl_id: DeclId) -> &dyn Command
Sourcepub fn get_decls_sorted(&self, include_hidden: bool) -> Vec<(Vec<u8>, DeclId)>
pub fn get_decls_sorted(&self, include_hidden: bool) -> Vec<(Vec<u8>, DeclId)>
Get all commands within scope, sorted by the commands’ names
pub fn get_signature(&self, decl: &dyn Command) -> Signature
Sourcepub fn get_signatures_and_declids(
&self,
include_hidden: bool,
) -> Vec<(Signature, DeclId)>
pub fn get_signatures_and_declids( &self, include_hidden: bool, ) -> Vec<(Signature, DeclId)>
Get signatures of all commands within scope with their decl ids.
pub fn get_block(&self, block_id: BlockId) -> &Arc<Block>
Sourcepub fn try_get_block(&self, block_id: BlockId) -> Option<&Arc<Block>>
pub fn try_get_block(&self, block_id: BlockId) -> Option<&Arc<Block>>
Optionally get a block by id, if it exists
Prefer to use .get_block()
in most cases - BlockId
s that don’t exist
are normally a compiler error. This only exists to stop plugins from crashing the engine if
they send us something invalid.
pub fn get_module(&self, module_id: ModuleId) -> &Module
pub fn get_virtual_path( &self, virtual_path_id: VirtualPathId, ) -> &(String, VirtualPath)
pub fn next_span_start(&self) -> usize
pub fn files(&self) -> impl Iterator<Item = &CachedFile>
pub fn add_file(&mut self, filename: Arc<str>, content: Arc<[u8]>) -> FileId
pub fn set_config_path(&mut self, key: &str, val: PathBuf)
pub fn get_config_path(&self, key: &str) -> Option<&PathBuf>
pub fn build_desc(&self, spans: &[Span]) -> (String, String)
pub fn build_module_desc(&self, module_id: ModuleId) -> Option<(String, String)>
Sourcepub fn current_work_dir(&self) -> String
👎Deprecated since 0.92.3: please use EngineState::cwd()
instead
pub fn current_work_dir(&self) -> String
EngineState::cwd()
insteadReturns the current working directory, which is guaranteed to be canonicalized.
Returns an empty String if $env.PWD doesn’t exist.
Sourcepub fn cwd(&self, stack: Option<&Stack>) -> Result<AbsolutePathBuf, ShellError>
pub fn cwd(&self, stack: Option<&Stack>) -> Result<AbsolutePathBuf, ShellError>
Returns the current working directory, which is guaranteed to be an absolute path without trailing slashes (unless it’s the root path), but might contain symlink components.
If stack
is supplied, also considers modifications to the working
directory on the stack that have yet to be merged into the engine state.
Sourcepub fn cwd_as_string(&self, stack: Option<&Stack>) -> Result<String, ShellError>
pub fn cwd_as_string(&self, stack: Option<&Stack>) -> Result<String, ShellError>
Like EngineState::cwd()
, but returns a String instead of a PathBuf for convenience.
pub fn get_file_contents(&self) -> &[CachedFile]
pub fn get_startup_time(&self) -> i64
pub fn set_startup_time(&mut self, startup_time: i64)
pub fn activate_debugger( &self, debugger: Box<dyn Debugger>, ) -> Result<(), PoisonError<MutexGuard<'_, Box<dyn Debugger>>>>
pub fn deactivate_debugger( &self, ) -> Result<Box<dyn Debugger>, PoisonError<MutexGuard<'_, Box<dyn Debugger>>>>
pub fn is_debugging(&self) -> bool
pub fn recover_from_panic(&mut self)
Sourcepub fn find_span_id(&self, span: Span) -> Option<SpanId>
pub fn find_span_id(&self, span: Span) -> Option<SpanId>
Find ID of a span (should be avoided if possible)
Trait Implementations§
Source§impl Clone for EngineState
impl Clone for EngineState
Source§fn clone(&self) -> EngineState
fn clone(&self) -> EngineState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Default for EngineState
impl Default for EngineState
Auto Trait Implementations§
impl !Freeze for EngineState
impl !RefUnwindSafe for EngineState
impl Send for EngineState
impl Sync for EngineState
impl Unpin for EngineState
impl !UnwindSafe for EngineState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoSpanned for T
impl<T> IntoSpanned for T
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more