Hide alias (#4432)

* Add alias interning

Now, AliasId is used to reference aliases stored in EngineState, similar
to decls, blocks, etc.

* Fix wrong message

* Fix using decl instead of alias

* Extend also alias id visibility

* Merge also aliases from delta

* Add alias hiding code

Does not work yet but passes tests at least.

* Fix wrong alias lookup and visibility appending

* Add hide alias tests

* Fmt & Clippy

* Fix random clippy warnings in "which" command
This commit is contained in:
Jakub Žádník
2022-02-12 11:50:37 +02:00
committed by GitHub
parent fcc13224c1
commit 328f7e92a0
9 changed files with 378 additions and 57 deletions

View File

@ -17,11 +17,11 @@ impl Command for Hide {
}
fn usage(&self) -> &str {
"Hide definitions in the current scope"
"Hide symbols in the current scope"
}
fn extra_usage(&self) -> &str {
"If there is a definition and an environment variable with the same name in the current scope, first the definition will be hidden, then the environment variable."
"Symbols are hidden by priority: First aliases, then custom commands, then environment variables."
}
fn run(
@ -67,7 +67,7 @@ impl Command for Hide {
overlay.env_var_with_head(name, &import_pattern.head.name)
{
output.push((name, id));
} else if !overlay.has_decl(name) {
} else if !(overlay.has_alias(name) || overlay.has_decl(name)) {
return Err(ShellError::EnvVarNotFoundAtRuntime(
String::from_utf8_lossy(name).into(),
*span,
@ -84,7 +84,7 @@ impl Command for Hide {
overlay.env_var_with_head(name, &import_pattern.head.name)
{
output.push((name, id));
} else if !overlay.has_decl(name) {
} else if !(overlay.has_alias(name) || overlay.has_decl(name)) {
return Err(ShellError::EnvVarNotFoundAtRuntime(
String::from_utf8_lossy(name).into(),
*span,