From f0e0ab35fcd9a742718a3147091c77083d0554e1 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:19:37 -0500 Subject: [PATCH] allow custom commands to show up in `$nu.scope.commands` better (#8910) # Description This PR allows our custom commands to show up in `$nu.scope.commands` better. It still needs work because this PR hard code the input and output types as `Type::Any` but the reason they're being missed in the first place is that they are not assigned an input and output type. This allows things like this now. Note the `where is_custom == true` ![image](https://user-images.githubusercontent.com/343840/232523925-97eeef78-9722-4184-b60f-9d06f994c8e3.png) Another example. ![image](https://user-images.githubusercontent.com/343840/232525706-d4d088d8-6597-43ba-97c8-ab03c2c7408c.png) ![image](https://user-images.githubusercontent.com/343840/232525797-b7e9ded3-b299-489e-af33-7390f4291bfd.png) # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-engine/src/scope.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/nu-engine/src/scope.rs b/crates/nu-engine/src/scope.rs index d94a231e6..747369ce3 100644 --- a/crates/nu-engine/src/scope.rs +++ b/crates/nu-engine/src/scope.rs @@ -281,6 +281,21 @@ impl<'e, 's> ScopeData<'e, 's> { ) }) .collect::>(); + + // Until we allow custom commands to have input and output types, let's just + // make them Type::Any Type::Any so they can show up in our $nu.scope.commands + // a little bit better. If sigs is empty, we're pretty sure that we're dealing + // with a custom command. + if sigs.is_empty() { + let any_type = &Type::Any; + sigs.push(( + any_type.to_shape().to_string(), + Value::List { + vals: self.collect_signature_entries(any_type, any_type, signature, span), + span, + }, + )); + } sigs.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2)); // For most commands, input types are not repeated in // `input_output_types`, i.e. each input type has only one associated