Hiding of environment variables (#362)

* Remember environment variables from previous scope

* Re-introduce env var hiding

Right now, hiding decls is broken

* Re-introduce hidden field of import patterns

All tests pass now.

* Remove/Address tests TODOs

* Fix test typo; Report hiding error

* Add a few more tests

* Fix wrong expected test result
This commit is contained in:
Jakub Žádník
2021-11-30 08:14:05 +02:00
committed by GitHub
parent 21ddfc61f4
commit c17e1473db
9 changed files with 232 additions and 56 deletions

View File

@ -6,7 +6,7 @@ use nu_protocol::{
engine::StateWorkingSet,
span, Exportable, Overlay, Span, SyntaxShape, Type, CONFIG_VARIABLE_ID,
};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::path::Path;
#[cfg(feature = "plugin")]
@ -711,6 +711,7 @@ pub fn parse_use(
span: spans[1],
},
members: import_pattern.members,
hidden: HashSet::new(),
},
overlay,
)
@ -836,11 +837,14 @@ pub fn parse_hide(
},
)
} else {
// TODO: Or it could be an env var
return (
garbage_statement(spans),
Some(ParseError::ModuleNotFound(spans[1])),
);
// Or it could be an env var
(
false,
Overlay {
decls: HashMap::new(),
env_vars: HashMap::new(),
},
)
}
} else {
return (
@ -893,6 +897,8 @@ pub fn parse_hide(
// TODO: `use spam; use spam foo; hide foo` will hide both `foo` and `spam foo` since
// they point to the same DeclId. Do we want to keep it that way?
working_set.hide_decls(&decls_to_hide);
let import_pattern = import_pattern
.with_hidden(decls_to_hide.iter().map(|(name, _)| name.clone()).collect());
// Create the Hide command call
let hide_decl_id = working_set

View File

@ -20,6 +20,8 @@ use crate::parse_keywords::{
parse_alias, parse_def, parse_def_predecl, parse_hide, parse_let, parse_module, parse_use,
};
use std::collections::HashSet;
#[cfg(feature = "plugin")]
use crate::parse_keywords::parse_plugin;
@ -1807,6 +1809,7 @@ pub fn parse_import_pattern(
span: Span::unknown(),
},
members: vec![],
hidden: HashSet::new(),
},
Some(ParseError::WrongImportPattern(span(spans))),
);
@ -1823,6 +1826,7 @@ pub fn parse_import_pattern(
span: *head_span,
},
members: vec![ImportPatternMember::Glob { span: *tail_span }],
hidden: HashSet::new(),
},
error,
)
@ -1850,6 +1854,7 @@ pub fn parse_import_pattern(
span: *head_span,
},
members: vec![ImportPatternMember::List { names: output }],
hidden: HashSet::new(),
},
error,
)
@ -1861,6 +1866,7 @@ pub fn parse_import_pattern(
span: *head_span,
},
members: vec![],
hidden: HashSet::new(),
},
Some(ParseError::ExportNotFound(result.span)),
),
@ -1877,6 +1883,7 @@ pub fn parse_import_pattern(
name: tail.to_vec(),
span: *tail_span,
}],
hidden: HashSet::new(),
},
error,
)
@ -1889,6 +1896,7 @@ pub fn parse_import_pattern(
span: *head_span,
},
members: vec![],
hidden: HashSet::new(),
},
None,
)