1
1
use either:: Either ;
2
2
use hir:: { AsAssocItem , HasAttrs , HasSource , HirDisplay , Semantics } ;
3
3
use ide_db:: {
4
- base_db:: SourceDatabase ,
4
+ base_db:: { FileRange , SourceDatabase } ,
5
5
defs:: { Definition , NameClass , NameRefClass } ,
6
6
helpers:: {
7
7
generated_lints:: { CLIPPY_LINTS , DEFAULT_LINTS , FEATURES } ,
@@ -12,8 +12,12 @@ use ide_db::{
12
12
use itertools:: Itertools ;
13
13
use stdx:: format_to;
14
14
use syntax:: {
15
- algo, ast, display:: fn_as_proc_macro_label, match_ast, AstNode , AstToken , Direction ,
16
- SyntaxKind :: * , SyntaxToken , T ,
15
+ algo:: { self , find_node_at_range} ,
16
+ ast,
17
+ display:: fn_as_proc_macro_label,
18
+ match_ast, AstNode , AstToken , Direction ,
19
+ SyntaxKind :: * ,
20
+ SyntaxToken , T ,
17
21
} ;
18
22
19
23
use crate :: {
@@ -246,6 +250,24 @@ pub(crate) fn hover_range(
246
250
range : FileRange ,
247
251
config : & HoverConfig ,
248
252
) -> Option < RangeInfo < HoverResult > > {
253
+ let sema = hir:: Semantics :: new ( db) ;
254
+ let file = sema. parse ( range. file_id ) . syntax ( ) . clone ( ) ;
255
+ let expr = find_node_at_range :: < ast:: Expr > ( & file, range. range ) ?;
256
+ let ty = sema. type_of_expr ( & expr) ?;
257
+
258
+ if ty. is_unknown ( ) {
259
+ return None ;
260
+ }
261
+
262
+ let mut res = HoverResult :: default ( ) ;
263
+
264
+ res. markup = if config. markdown ( ) {
265
+ Markup :: fenced_block ( & ty. display ( db) )
266
+ } else {
267
+ ty. display ( db) . to_string ( ) . into ( )
268
+ } ;
269
+
270
+ Some ( RangeInfo :: new ( range. range , res) )
249
271
}
250
272
251
273
fn show_implementations_action ( db : & RootDatabase , def : Definition ) -> Option < HoverAction > {
0 commit comments