1 //! Implementation of "closure return type" inlay hints.
2 use ide_db
::{base_db::FileId, famous_defs::FamousDefs}
;
3 use syntax
::ast
::{self, AstNode}
;
6 inlay_hints
::closure_has_block_body
, ClosureReturnTypeHints
, InlayHint
, InlayHintsConfig
,
7 InlayKind
, InlayTooltip
,
10 use super::label_of_ty
;
13 acc
: &mut Vec
<InlayHint
>,
14 famous_defs @
FamousDefs(sema
, _
): &FamousDefs
<'_
, '_
>,
15 config
: &InlayHintsConfig
,
17 closure
: ast
::ClosureExpr
,
19 if config
.closure_return_type_hints
== ClosureReturnTypeHints
::Never
{
23 if closure
.ret_type().is_some() {
27 if !closure_has_block_body(&closure
)
28 && config
.closure_return_type_hints
== ClosureReturnTypeHints
::WithBlock
33 let param_list
= closure
.param_list()?
;
35 let closure
= sema
.descend_node_into_attributes(closure
).pop()?
;
36 let ty
= sema
.type_of_expr(&ast
::Expr
::ClosureExpr(closure
))?
.adjusted();
37 let callable
= ty
.as_callable(sema
.db
)?
;
38 let ty
= callable
.return_type();
43 range
: param_list
.syntax().text_range(),
44 kind
: InlayKind
::ClosureReturnTypeHint
,
45 label
: label_of_ty(famous_defs
, config
, ty
)?
,
46 tooltip
: Some(InlayTooltip
::HoverRanged(file_id
, param_list
.syntax().text_range())),