Reworking help aliases (#8372)

This commit is contained in:
Klementiev Dmitry 2023-03-10 23:14:55 +05:00 committed by GitHub
parent 3e9bb4028a
commit 0ff1cb1ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,8 @@
use nu_protocol::{
engine::{EngineState, Stack, Visibility},
engine::{Command, EngineState, Stack, Visibility},
ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::collections::HashMap;
@ -494,6 +495,36 @@ impl<'e, 's> ScopeData<'e, 's> {
});
}
}
for (name_bytes, decl_id) in self.engine_state.get_decls_sorted(false) {
if self.visibility.is_decl_id_visible(&decl_id) {
let decl = self.engine_state.get_decl(decl_id);
if let Some(alias) = decl.as_alias() {
let name = String::from_utf8_lossy(&name_bytes).to_string();
let sig = decl.signature().update_from_command(name, decl.borrow());
let key = sig.name;
aliases.push(Value::Record {
cols: vec!["name".into(), "expansion".into(), "usage".into()],
vals: vec![
Value::String { val: key, span },
Value::String {
val: String::from_utf8_lossy(
self.engine_state
.get_span_contents(&alias.wrapped_call.span),
)
.to_string(),
span,
},
Value::String {
val: alias.signature().usage,
span,
},
],
span,
});
}
}
}
aliases.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
aliases