mirror of
https://github.com/oxalica/nil.git
synced 2025-12-23 09:19:49 +00:00
Tweak builtins and hint user about missing docs
This commit is contained in:
parent
28fcc1fa37
commit
02be7d9628
4 changed files with 23 additions and 17 deletions
|
|
@ -68,13 +68,14 @@ fn main() {
|
|||
"true" | "false" | "null" => "Const",
|
||||
_ => "Function",
|
||||
};
|
||||
let summary = builtins_dump
|
||||
let args = builtins_dump
|
||||
.get(name)
|
||||
.map(|b @ DumpBuiltin { args, arity, .. }| {
|
||||
assert_eq!(args.len(), *arity, "Arity mismatch: {b:?}");
|
||||
let args = args.iter().flat_map(|arg| [" ", arg]).collect::<String>();
|
||||
format!("builtins.{name}{args}")
|
||||
});
|
||||
args.iter().flat_map(|arg| [" ", arg]).collect::<String>()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let summary = format!("`builtins.{name}{args}`");
|
||||
let doc = builtins_dump.get(name).map(|b| &b.doc);
|
||||
phf_gen.entry(name, &format!("crate::Builtin {{ kind: crate::BuiltinKind::{kind}, is_global: {is_global}, summary: {summary:?}, doc: {doc:?} }}"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
pub struct Builtin {
|
||||
pub kind: BuiltinKind,
|
||||
pub is_global: bool,
|
||||
pub summary: Option<&'static str>,
|
||||
pub summary: &'static str,
|
||||
pub doc: Option<&'static str>,
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ mod tests {
|
|||
Builtin {
|
||||
kind: BuiltinKind::Const,
|
||||
is_global: true,
|
||||
summary: None,
|
||||
summary: "`builtins.true`",
|
||||
doc: None,
|
||||
},
|
||||
);
|
||||
|
|
@ -37,7 +37,7 @@ mod tests {
|
|||
Builtin {
|
||||
kind: BuiltinKind::Function,
|
||||
is_global: false,
|
||||
summary: Some("builtins.attrNames set"),
|
||||
summary: "`builtins.attrNames set`",
|
||||
doc: Some(
|
||||
"\
|
||||
Return the names of the attributes in the set *set* in an
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ fn complete_expr(
|
|||
source_range,
|
||||
replace: name.into(),
|
||||
kind: b.kind.into(),
|
||||
brief: b.summary.map(|s| s.to_owned()),
|
||||
brief: Some(b.summary.into()),
|
||||
doc: b.doc.map(|s| s.to_owned()),
|
||||
})
|
||||
.for_each(&mut feed);
|
||||
|
|
|
|||
|
|
@ -42,14 +42,11 @@ pub(crate) fn hover(
|
|||
None => {}
|
||||
Some(ResolveResult::Builtin(name)) => {
|
||||
let b = &ALL_BUILTINS[*name];
|
||||
let mut markup = String::new();
|
||||
match b.summary {
|
||||
None => writeln!(markup, "`builtins.{name}`").unwrap(),
|
||||
Some(summary) => writeln!(markup, "`{summary}`").unwrap(),
|
||||
}
|
||||
if let Some(doc) = b.doc {
|
||||
writeln!(markup, "\n{doc}").unwrap();
|
||||
}
|
||||
let markup = format!(
|
||||
"{}\n\n{}",
|
||||
b.summary,
|
||||
b.doc.unwrap_or("(No documentation from Nix)"),
|
||||
);
|
||||
return Some(HoverResult { range, markup });
|
||||
}
|
||||
Some(ResolveResult::WithExprs(withs)) => {
|
||||
|
|
@ -166,7 +163,15 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn builtin() {
|
||||
check("$0true", "true", expect!["`builtins.true`"]);
|
||||
check(
|
||||
"$0true",
|
||||
"true",
|
||||
expect![[r#"
|
||||
`builtins.true`
|
||||
|
||||
(No documentation from Nix)
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
"$0map",
|
||||
"map",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue