Skip to content

Commit b0721f7

Browse files
committed
add hover for builtin functions
1 parent 3ba8a08 commit b0721f7

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/backend.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,23 @@ impl Backend {
323323
range: Some(Range { start, end }),
324324
})
325325
}
326-
_ => None,
326+
other => {
327+
let template = completion::builtin::match_callname(other.to_owned())?;
328+
let description = format!(
329+
"```simplicityhl\nfn {}({}) -> {}\n```\n{}",
330+
template.display_name,
331+
template.args.join(", "),
332+
template.return_type,
333+
template.description
334+
);
335+
Some(Hover {
336+
contents: tower_lsp_server::lsp_types::HoverContents::Markup(MarkupContent {
337+
kind: MarkupKind::Markdown,
338+
value: description,
339+
}),
340+
range: Some(Range { start, end }),
341+
})
342+
}
327343
}
328344
}
329345
}

src/completion/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn get_builtin_functions() -> Vec<FunctionTemplate> {
5050
.collect()
5151
}
5252

53-
fn match_callname(call: CallName) -> Option<FunctionTemplate> {
53+
pub fn match_callname(call: CallName) -> Option<FunctionTemplate> {
5454
match call {
5555
CallName::UnwrapLeft(aliased_type) => {
5656
let ty = aliased_type.to_string();
@@ -94,13 +94,13 @@ fn match_callname(call: CallName) -> Option<FunctionTemplate> {
9494
CallName::Assert => Some(FunctionTemplate::simple(
9595
"assert!",
9696
str_vec!["bool"],
97-
"",
97+
"()",
9898
"Fails program if argument is 'false'",
9999
)),
100100
CallName::Panic => Some(FunctionTemplate::simple(
101101
"panic!",
102102
str_vec![],
103-
"",
103+
"()",
104104
"Fails program",
105105
)),
106106
CallName::Debug => Some(FunctionTemplate::simple(

0 commit comments

Comments
 (0)