* WIP: Start laying overlays

* Rename Overlay->Module; Start adding overlay

* Revamp adding overlay

* Add overlay add tests; Disable debug print

* Fix overlay add; Add overlay remove

* Add overlay remove tests

* Add missing overlay remove file

* Add overlay list command

* (WIP?) Enable overlays for env vars

* Move OverlayFrames to ScopeFrames

* (WIP) Move everything to overlays only

ScopeFrame contains nothing but overlays now

* Fix predecls

* Fix wrong overlay id translation and aliases

* Fix broken env lookup logic

* Remove TODOs

* Add overlay add + remove for environment

* Add a few overlay tests; Fix overlay add name

* Some cleanup; Fix overlay add/remove names

* Clippy

* Fmt

* Remove walls of comments

* List overlays from stack; Add debugging flag

Currently, the engine state ordering is somehow broken.

* Fix (?) overlay list test

* Fix tests on Windows

* Fix activated overlay ordering

* Check for active overlays equality in overlay list

This removes the -p flag: Either both parser and engine will have the
same overlays, or the command will fail.

* Add merging on overlay remove

* Change help message and comment

* Add some remove-merge/discard tests

* (WIP) Track removed overlays properly

* Clippy; Fmt

* Fix getting last overlay; Fix predecls in overlays

* Remove merging; Fix re-add overwriting stuff

Also some error message tweaks.

* Fix overlay error in the engine

* Update variable_completions.rs

* Adds flags and optional arguments to view-source (#5446)

* added flags and optional arguments to view-source

* removed redundant code

* removed redundant code

* fmt

* fix bug in shell_integration (#5450)

* fix bug in shell_integration

* add some comments

* enable cd to work with directory abbreviations (#5452)

* enable cd to work with abbreviations

* add abbreviation example

* fix tests

* make it configurable

* make cd recornize symblic link (#5454)

* implement seq char command to generate single character sequence (#5453)

* add tmp code

* add seq char command

* Add split number flag in `split row` (#5434)

Signed-off-by: Yuheng Su <gipsyh.icu@gmail.com>

* Add two more overlay tests

* Add ModuleId to OverlayFrame

* Fix env conversion accidentally activating overlay

It activated overlay from permanent state prematurely which would
cause `overlay add` to misbehave.

* Remove unused parameter; Add overlay list test

* Remove added traces

* Add overlay commands examples

* Modify TODO

* Fix $nu.scope iteration

* Disallow removing default overlay

* Refactor some parser errors

* Remove last overlay if no argument

* Diversify overlay examples

* Make it possible to update overlay's module

In case the origin module updates, the overlay add loads the new module,
makes it overlay's origin and applies the changes. Before, it was
impossible to update the overlay if the module changed.

Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
Co-authored-by: pwygab <88221256+merelymyself@users.noreply.github.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: WindSoilder <WindSoilder@outlook.com>
Co-authored-by: Yuheng Su <gipsyh.icu@gmail.com>
This commit is contained in:
Jakub Žádník
2022-05-07 22:39:22 +03:00
committed by GitHub
parent 1cb449b2d1
commit 9b99b2f6ac
46 changed files with 2638 additions and 607 deletions

View File

@ -169,10 +169,8 @@ pub fn eval_call(
}
// add new env vars from callee to caller
for env_vars in callee_stack.env_vars {
for (var, value) in env_vars {
caller_stack.add_env_var(var, value);
}
for (var, value) in callee_stack.get_stack_env_vars() {
caller_stack.add_env_var(var, value);
}
}
@ -195,7 +193,7 @@ fn eval_external(
redirect_stderr: bool,
) -> Result<PipelineData, ShellError> {
let decl_id = engine_state
.find_decl("run-external".as_bytes())
.find_decl("run-external".as_bytes(), &[])
.ok_or(ShellError::ExternalNotSupported(head.span))?;
let command = engine_state.get_decl(decl_id);
@ -660,7 +658,7 @@ pub fn eval_block(
// Drain the input to the screen via tabular output
let config = engine_state.get_config();
match engine_state.find_decl("table".as_bytes()) {
match engine_state.find_decl("table".as_bytes(), &[]) {
Some(decl_id) => {
let table = engine_state.get_decl(decl_id).run(
engine_state,
@ -716,7 +714,7 @@ pub fn eval_block(
// Drain the input to the screen via tabular output
let config = engine_state.get_config();
match engine_state.find_decl("table".as_bytes()) {
match engine_state.find_decl("table".as_bytes(), &[]) {
Some(decl_id) => {
let table = engine_state.get_decl(decl_id).run(
engine_state,
@ -806,21 +804,21 @@ pub fn create_scope(
let mut vars = vec![];
let mut commands = vec![];
let mut aliases = vec![];
let mut overlays = vec![];
let mut modules = vec![];
let mut vars_map = HashMap::new();
let mut commands_map = HashMap::new();
let mut aliases_map = HashMap::new();
let mut overlays_map = HashMap::new();
let mut modules_map = HashMap::new();
let mut visibility = Visibility::new();
for frame in &engine_state.scope {
vars_map.extend(&frame.vars);
commands_map.extend(&frame.decls);
aliases_map.extend(&frame.aliases);
overlays_map.extend(&frame.overlays);
for overlay_frame in engine_state.active_overlays(&[]) {
vars_map.extend(&overlay_frame.vars);
commands_map.extend(&overlay_frame.decls);
aliases_map.extend(&overlay_frame.aliases);
modules_map.extend(&overlay_frame.modules);
visibility.merge_with(frame.visibility.clone());
visibility.merge_with(overlay_frame.visibility.clone());
}
for var in vars_map {
@ -846,14 +844,14 @@ pub fn create_scope(
let mut cols = vec![];
let mut vals = vec![];
let mut overlay_commands = vec![];
for overlay in &overlays_map {
let overlay_name = String::from_utf8_lossy(*overlay.0).to_string();
let overlay_id = engine_state.find_overlay(*overlay.0);
if let Some(overlay_id) = overlay_id {
let overlay = engine_state.get_overlay(overlay_id);
if overlay.has_decl(command_name) {
overlay_commands.push(overlay_name);
let mut module_commands = vec![];
for module in &modules_map {
let module_name = String::from_utf8_lossy(module.0).to_string();
let module_id = engine_state.find_module(module.0, &[]);
if let Some(module_id) = module_id {
let module = engine_state.get_module(module_id);
if module.has_decl(command_name) {
module_commands.push(module_name);
}
}
}
@ -865,7 +863,7 @@ pub fn create_scope(
});
cols.push("module_name".into());
vals.push(Value::string(overlay_commands.join(", "), span));
vals.push(Value::string(module_commands.join(", "), span));
let decl = engine_state.get_decl(*decl_id);
let signature = decl.signature();
@ -1132,9 +1130,9 @@ pub fn create_scope(
}
}
for overlay in overlays_map {
overlays.push(Value::String {
val: String::from_utf8_lossy(overlay.0).to_string(),
for module in modules_map {
modules.push(Value::String {
val: String::from_utf8_lossy(module.0).to_string(),
span,
});
}
@ -1179,10 +1177,10 @@ pub fn create_scope(
span,
});
overlays.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
output_cols.push("overlays".to_string());
modules.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
output_cols.push("modules".to_string());
output_vals.push(Value::List {
vals: overlays,
vals: modules,
span,
});