aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/inlay_hints.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/inlay_hints.rs')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index f2e4f7ee5..1bacead63 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -2,7 +2,7 @@ use hir::{Adt, Callable, HirDisplay, Semantics, Type};
2use ra_ide_db::RootDatabase; 2use ra_ide_db::RootDatabase;
3use ra_prof::profile; 3use ra_prof::profile;
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, 5 ast::{self, ArgListOwner, AstNode},
6 match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, 6 match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T,
7}; 7};
8use stdx::to_lower_snake_case; 8use stdx::to_lower_snake_case;
@@ -78,7 +78,7 @@ pub(crate) fn inlay_hints(
78 match node { 78 match node {
79 ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, 79 ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); },
80 ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, 80 ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); },
81 ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); }, 81 ast::IdentPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); },
82 _ => (), 82 _ => (),
83 } 83 }
84 } 84 }
@@ -96,7 +96,7 @@ fn get_chaining_hints(
96 return None; 96 return None;
97 } 97 }
98 98
99 if matches!(expr, ast::Expr::RecordLit(_)) { 99 if matches!(expr, ast::Expr::RecordExpr(_)) {
100 return None; 100 return None;
101 } 101 }
102 102
@@ -161,7 +161,7 @@ fn get_param_name_hints(
161 Either::Left(self_param) => Some((self_param.to_string(), arg)), 161 Either::Left(self_param) => Some((self_param.to_string(), arg)),
162 Either::Right(pat) => { 162 Either::Right(pat) => {
163 let param_name = match pat { 163 let param_name = match pat {
164 ast::Pat::BindPat(it) => it.name()?.to_string(), 164 ast::Pat::IdentPat(it) => it.name()?.to_string(),
165 it => it.to_string(), 165 it => it.to_string(),
166 }; 166 };
167 Some((param_name, arg)) 167 Some((param_name, arg))
@@ -182,7 +182,7 @@ fn get_bind_pat_hints(
182 acc: &mut Vec<InlayHint>, 182 acc: &mut Vec<InlayHint>,
183 sema: &Semantics<RootDatabase>, 183 sema: &Semantics<RootDatabase>,
184 config: &InlayHintsConfig, 184 config: &InlayHintsConfig,
185 pat: ast::BindPat, 185 pat: ast::IdentPat,
186) -> Option<()> { 186) -> Option<()> {
187 if !config.type_hints { 187 if !config.type_hints {
188 return None; 188 return None;
@@ -202,7 +202,7 @@ fn get_bind_pat_hints(
202 Some(()) 202 Some(())
203} 203}
204 204
205fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type) -> bool { 205fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &Type) -> bool {
206 if let Some(Adt::Enum(enum_data)) = pat_ty.as_adt() { 206 if let Some(Adt::Enum(enum_data)) = pat_ty.as_adt() {
207 let pat_text = bind_pat.to_string(); 207 let pat_text = bind_pat.to_string();
208 enum_data 208 enum_data
@@ -215,7 +215,11 @@ fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type
215 } 215 }
216} 216}
217 217
218fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type) -> bool { 218fn should_not_display_type_hint(
219 db: &RootDatabase,
220 bind_pat: &ast::IdentPat,
221 pat_ty: &Type,
222) -> bool {
219 if pat_ty.is_unknown() { 223 if pat_ty.is_unknown() {
220 return true; 224 return true;
221 } 225 }
@@ -230,10 +234,10 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_
230 match_ast! { 234 match_ast! {
231 match node { 235 match node {
232 ast::LetStmt(it) => { 236 ast::LetStmt(it) => {
233 return it.ascribed_type().is_some() 237 return it.ty().is_some()
234 }, 238 },
235 ast::Param(it) => { 239 ast::Param(it) => {
236 return it.ascribed_type().is_some() 240 return it.ty().is_some()
237 }, 241 },
238 ast::MatchArm(_it) => { 242 ast::MatchArm(_it) => {
239 return pat_is_enum_variant(db, bind_pat, pat_ty); 243 return pat_is_enum_variant(db, bind_pat, pat_ty);