Skip to content

Commit

Permalink
add $.extra_usage to modules (nushell#11649)
Browse files Browse the repository at this point in the history
- should fix nushell#11648

# Description
this PR
- adds a test that should pass but fails
- adds `$.extra_usage` to the output of `scope modules`, fixing both the
new test and the linked issue

# User-Facing Changes
`$.extra_usage` is now a column in the output of `scope modules`

# Tests + Formatting
a new test case has been added to `correct_scope_modules_fields`

# After Submitting
  • Loading branch information
amtoine authored and dmatos2012 committed Feb 20, 2024
1 parent 8512182 commit 2d76987
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/nu-engine/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,9 @@ impl<'e, 's> ScopeData<'e, 's> {
|block_id| Value::block(block_id, span),
);

let module_usage = self
let (module_usage, module_extra_usage) = self
.engine_state
.build_module_usage(*module_id)
.map(|(usage, _)| usage)
.unwrap_or_default();

Value::record(
Expand All @@ -520,6 +519,7 @@ impl<'e, 's> ScopeData<'e, 's> {
"constants" => Value::list(export_consts, span),
"env_block" => export_env_block,
"usage" => Value::string(module_usage, span),
"extra_usage" => Value::string(module_extra_usage, span),
"module_id" => Value::int(*module_id as i64, span),
},
span,
Expand Down
9 changes: 9 additions & 0 deletions tests/scope/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ fn correctly_report_of_shadowed_alias() {
fn correct_scope_modules_fields() {
let module_setup = r#"
# nice spam
#
# and some extra usage for spam
export module eggs {
export module bacon {
Expand Down Expand Up @@ -123,6 +125,13 @@ fn correct_scope_modules_fields() {
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "nice spam");

let inp = &[
"use spam.nu",
"scope modules | where name == spam | get 0.extra_usage",
];
let actual = nu!(cwd: dirs.test(), &inp.join("; "));
assert_eq!(actual.out, "and some extra usage for spam");

let inp = &[
"use spam.nu",
"scope modules | where name == spam | get 0.env_block | is-empty",
Expand Down

0 comments on commit 2d76987

Please sign in to comment.