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
16 changes: 16 additions & 0 deletions ndc_lsp/src/features/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,20 @@ mod tests {
)
);
}

#[test]
fn lambda_inside_call_gets_return_type_inlay() {
let info = collect_hints("[1,2,3].map(fn(y) => y / 2.0);");
assert!(info.hints.iter().any(
|hint| matches!(&hint.label, InlayHintLabel::String(label) if label.starts_with(" -> "))
));
}

#[test]
fn lambda_inside_list_literal_gets_return_type_inlay() {
let info = collect_hints("let fns = [fn(x) => x + 1];");
assert!(info.hints.iter().any(
|hint| matches!(&hint.label, InlayHintLabel::String(label) if label.starts_with(" -> "))
));
}
}
59 changes: 57 additions & 2 deletions ndc_lsp/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,59 @@ fn walk_expression(visitor: &mut impl AstVisitor, expr: &ExpressionLocation) {
}
}
Expression::Return { value } => walk_expression(visitor, value),
_ => {}
Expression::Logical { left, right, .. } => {
walk_expression(visitor, left);
walk_expression(visitor, right);
}
Expression::Assignment { l_value, r_value }
| Expression::OpAssignment {
l_value, r_value, ..
} => {
walk_lvalue(visitor, l_value, false);
walk_expression(visitor, r_value);
}
Expression::Call {
function,
arguments,
} => {
walk_expression(visitor, function);
for arg in arguments {
walk_expression(visitor, arg);
Comment thread
timfennis marked this conversation as resolved.
}
}
Expression::Tuple { values } | Expression::List { values } => {
for v in values {
walk_expression(visitor, v);
}
}
Expression::Map { values, default } => {
for (key, value) in values {
walk_expression(visitor, key);
if let Some(v) = value {
walk_expression(visitor, v);
}
}
if let Some(d) = default {
walk_expression(visitor, d);
}
}
Expression::RangeInclusive { start, end } | Expression::RangeExclusive { start, end } => {
if let Some(s) = start {
walk_expression(visitor, s);
}
if let Some(e) = end {
walk_expression(visitor, e);
}
}
Expression::Identifier { .. }
| Expression::BoolLiteral(_)
| Expression::StringLiteral(_)
| Expression::Int64Literal(_)
| Expression::Float64Literal(_)
| Expression::BigIntLiteral(_)
| Expression::ComplexLiteral(_)
| Expression::Break
| Expression::Continue => {}
}
}

Expand All @@ -138,6 +190,9 @@ fn walk_lvalue(visitor: &mut impl AstVisitor, lvalue: &Lvalue, has_annotation: b
walk_lvalue(visitor, lv, has_annotation);
}
}
Lvalue::Index { .. } => {}
Lvalue::Index { value, index, .. } => {
walk_expression(visitor, value);
walk_expression(visitor, index);
}
}
}
Loading