Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion tooling/lsp/src/requests/inlay_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,15 @@ impl<'a> InlayHintCollector<'a> {
self.collect_in_expression(expression);
}
}
ExpressionKind::Lambda(lambda) => self.collect_in_expression(&lambda.body),
ExpressionKind::Lambda(lambda) => {
for (pattern, typ) in &lambda.parameters {
if matches!(typ.typ, UnresolvedTypeData::Unspecified) {
self.collect_in_pattern(pattern);
}
}

self.collect_in_expression(&lambda.body);
}
ExpressionKind::Parenthesized(parenthesized) => {
self.collect_in_expression(parenthesized);
}
Expand Down Expand Up @@ -895,6 +903,34 @@ mod inlay_hints_tests {
);
}

#[test]
async fn test_type_inlay_hints_in_lambda() {
let inlay_hints = get_inlay_hints(102, 105, type_hints()).await;
assert_eq!(inlay_hints.len(), 1);

let position = Position { line: 104, character: 35 };

let inlay_hint = &inlay_hints[0];
assert_eq!(inlay_hint.position, position);

if let InlayHintLabel::LabelParts(labels) = &inlay_hint.label {
assert_eq!(labels.len(), 2);
assert_eq!(labels[0].value, ": ");
assert_eq!(labels[0].location, None);
assert_eq!(labels[1].value, "i32");
} else {
panic!("Expected InlayHintLabel::LabelParts, got {:?}", inlay_hint.label);
}

assert_eq!(
inlay_hint.text_edits,
Some(vec![TextEdit {
range: Range { start: position, end: position },
new_text: ": i32".to_string(),
}])
);
}

#[test]
async fn test_do_not_panic_when_given_line_is_too_big() {
let inlay_hints = get_inlay_hints(0, 100000, type_hints()).await;
Expand Down
11 changes: 10 additions & 1 deletion tooling/lsp/test_programs/inlay_hints/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ fn call_yet_another_function() {

fn struct_member_hint() {
let SomeStruct { one } = SomeStruct { one: 1 };
}
}

fn some_map<T, U>(x: T, f: fn(T) -> U) -> U {
f(x)
}

fn hint_on_lambda_parameter() {
let value: i32 = 1;
let _: i32 = some_map(value, |x| x + 1);
}