aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/inlay_hints.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/inlay_hints.rs')
-rw-r--r--crates/ra_ide_api/src/inlay_hints.rs23
1 files changed, 6 insertions, 17 deletions
diff --git a/crates/ra_ide_api/src/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs
index 24a7ca5e7..45149bf0c 100644
--- a/crates/ra_ide_api/src/inlay_hints.rs
+++ b/crates/ra_ide_api/src/inlay_hints.rs
@@ -1,7 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use crate::{db::RootDatabase, FileId}; 3use crate::{db::RootDatabase, FileId};
4use hir::{HirDisplay, SourceAnalyzer, Ty}; 4use hir::{HirDisplay, SourceAnalyzer};
5use ra_syntax::{ 5use ra_syntax::{
6 ast::{self, AstNode, TypeAscriptionOwner}, 6 ast::{self, AstNode, TypeAscriptionOwner},
7 match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange, 7 match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange,
@@ -100,8 +100,11 @@ fn get_pat_type_hints(
100 .into_iter() 100 .into_iter()
101 .filter(|pat| !skip_root_pat_hint || pat != original_pat) 101 .filter(|pat| !skip_root_pat_hint || pat != original_pat)
102 .filter_map(|pat| { 102 .filter_map(|pat| {
103 get_node_displayable_type(db, &analyzer, &pat) 103 let ty = analyzer.type_of_pat(db, &pat)?;
104 .map(|pat_type| (pat.syntax().text_range(), pat_type)) 104 if ty.is_unknown() {
105 return None;
106 }
107 Some((pat.syntax().text_range(), ty))
105 }) 108 })
106 .map(|(range, pat_type)| InlayHint { 109 .map(|(range, pat_type)| InlayHint {
107 range, 110 range,
@@ -158,20 +161,6 @@ fn get_leaf_pats(root_pat: ast::Pat) -> Vec<ast::Pat> {
158 leaf_pats 161 leaf_pats
159} 162}
160 163
161fn get_node_displayable_type(
162 db: &RootDatabase,
163 analyzer: &SourceAnalyzer,
164 node_pat: &ast::Pat,
165) -> Option<Ty> {
166 analyzer.type_of_pat(db, node_pat).and_then(|resolved_type| {
167 if let Ty::Apply(_) = resolved_type {
168 Some(resolved_type)
169 } else {
170 None
171 }
172 })
173}
174
175#[cfg(test)] 164#[cfg(test)]
176mod tests { 165mod tests {
177 use crate::mock_analysis::single_file; 166 use crate::mock_analysis::single_file;