diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 24 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 4 |
2 files changed, 13 insertions, 15 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 4c5004f67..3154df457 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use crate::{db::RootDatabase, FileId}; | 3 | use crate::{db::RootDatabase, FileId}; |
4 | use hir::{HirDisplay, SourceAnalyzer, TruncateOptions}; | 4 | use hir::{HirDisplay, SourceAnalyzer}; |
5 | use ra_syntax::{ | 5 | use 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, |
@@ -23,11 +23,11 @@ pub(crate) fn inlay_hints( | |||
23 | db: &RootDatabase, | 23 | db: &RootDatabase, |
24 | file_id: FileId, | 24 | file_id: FileId, |
25 | file: &SourceFile, | 25 | file: &SourceFile, |
26 | truncate_options: &TruncateOptions, | 26 | max_inlay_hint_length: Option<usize>, |
27 | ) -> Vec<InlayHint> { | 27 | ) -> Vec<InlayHint> { |
28 | file.syntax() | 28 | file.syntax() |
29 | .descendants() | 29 | .descendants() |
30 | .map(|node| get_inlay_hints(db, file_id, &node, truncate_options).unwrap_or_default()) | 30 | .map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length).unwrap_or_default()) |
31 | .flatten() | 31 | .flatten() |
32 | .collect() | 32 | .collect() |
33 | } | 33 | } |
@@ -36,7 +36,7 @@ fn get_inlay_hints( | |||
36 | db: &RootDatabase, | 36 | db: &RootDatabase, |
37 | file_id: FileId, | 37 | file_id: FileId, |
38 | node: &SyntaxNode, | 38 | node: &SyntaxNode, |
39 | truncate_options: &TruncateOptions, | 39 | max_inlay_hint_length: Option<usize>, |
40 | ) -> Option<Vec<InlayHint>> { | 40 | ) -> Option<Vec<InlayHint>> { |
41 | let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None); | 41 | let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None); |
42 | match_ast! { | 42 | match_ast! { |
@@ -46,7 +46,7 @@ fn get_inlay_hints( | |||
46 | return None; | 46 | return None; |
47 | } | 47 | } |
48 | let pat = it.pat()?; | 48 | let pat = it.pat()?; |
49 | Some(get_pat_type_hints(db, &analyzer, pat, false, truncate_options)) | 49 | Some(get_pat_type_hints(db, &analyzer, pat, false, max_inlay_hint_length)) |
50 | }, | 50 | }, |
51 | ast::LambdaExpr(it) => { | 51 | ast::LambdaExpr(it) => { |
52 | it.param_list().map(|param_list| { | 52 | it.param_list().map(|param_list| { |
@@ -54,22 +54,22 @@ fn get_inlay_hints( | |||
54 | .params() | 54 | .params() |
55 | .filter(|closure_param| closure_param.ascribed_type().is_none()) | 55 | .filter(|closure_param| closure_param.ascribed_type().is_none()) |
56 | .filter_map(|closure_param| closure_param.pat()) | 56 | .filter_map(|closure_param| closure_param.pat()) |
57 | .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false, truncate_options)) | 57 | .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, false, max_inlay_hint_length)) |
58 | .flatten() | 58 | .flatten() |
59 | .collect() | 59 | .collect() |
60 | }) | 60 | }) |
61 | }, | 61 | }, |
62 | ast::ForExpr(it) => { | 62 | ast::ForExpr(it) => { |
63 | let pat = it.pat()?; | 63 | let pat = it.pat()?; |
64 | Some(get_pat_type_hints(db, &analyzer, pat, false, truncate_options)) | 64 | Some(get_pat_type_hints(db, &analyzer, pat, false, max_inlay_hint_length)) |
65 | }, | 65 | }, |
66 | ast::IfExpr(it) => { | 66 | ast::IfExpr(it) => { |
67 | let pat = it.condition()?.pat()?; | 67 | let pat = it.condition()?.pat()?; |
68 | Some(get_pat_type_hints(db, &analyzer, pat, true, truncate_options)) | 68 | Some(get_pat_type_hints(db, &analyzer, pat, true, max_inlay_hint_length)) |
69 | }, | 69 | }, |
70 | ast::WhileExpr(it) => { | 70 | ast::WhileExpr(it) => { |
71 | let pat = it.condition()?.pat()?; | 71 | let pat = it.condition()?.pat()?; |
72 | Some(get_pat_type_hints(db, &analyzer, pat, true, truncate_options)) | 72 | Some(get_pat_type_hints(db, &analyzer, pat, true, max_inlay_hint_length)) |
73 | }, | 73 | }, |
74 | ast::MatchArmList(it) => { | 74 | ast::MatchArmList(it) => { |
75 | Some( | 75 | Some( |
@@ -77,7 +77,7 @@ fn get_inlay_hints( | |||
77 | .arms() | 77 | .arms() |
78 | .map(|match_arm| match_arm.pats()) | 78 | .map(|match_arm| match_arm.pats()) |
79 | .flatten() | 79 | .flatten() |
80 | .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true, truncate_options)) | 80 | .map(|root_pat| get_pat_type_hints(db, &analyzer, root_pat, true, max_inlay_hint_length)) |
81 | .flatten() | 81 | .flatten() |
82 | .collect(), | 82 | .collect(), |
83 | ) | 83 | ) |
@@ -92,7 +92,7 @@ fn get_pat_type_hints( | |||
92 | analyzer: &SourceAnalyzer, | 92 | analyzer: &SourceAnalyzer, |
93 | root_pat: ast::Pat, | 93 | root_pat: ast::Pat, |
94 | skip_root_pat_hint: bool, | 94 | skip_root_pat_hint: bool, |
95 | truncate_options: &TruncateOptions, | 95 | max_inlay_hint_length: Option<usize>, |
96 | ) -> Vec<InlayHint> { | 96 | ) -> Vec<InlayHint> { |
97 | let original_pat = &root_pat.clone(); | 97 | let original_pat = &root_pat.clone(); |
98 | 98 | ||
@@ -109,7 +109,7 @@ fn get_pat_type_hints( | |||
109 | .map(|(range, pat_type)| InlayHint { | 109 | .map(|(range, pat_type)| InlayHint { |
110 | range, | 110 | range, |
111 | kind: InlayKind::TypeHint, | 111 | kind: InlayKind::TypeHint, |
112 | label: pat_type.display_truncated(db, truncate_options).to_string().into(), | 112 | label: pat_type.display_truncated(db, max_inlay_hint_length).to_string().into(), |
113 | }) | 113 | }) |
114 | .collect() | 114 | .collect() |
115 | } | 115 | } |
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 875919e60..779a81b2c 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -349,10 +349,8 @@ impl Analysis { | |||
349 | file_id: FileId, | 349 | file_id: FileId, |
350 | max_inlay_hint_length: Option<usize>, | 350 | max_inlay_hint_length: Option<usize>, |
351 | ) -> Cancelable<Vec<InlayHint>> { | 351 | ) -> Cancelable<Vec<InlayHint>> { |
352 | let truncate_options = | ||
353 | hir::TruncateOptions { max_length: max_inlay_hint_length, show_default_types: false }; | ||
354 | self.with_db(|db| { | 352 | self.with_db(|db| { |
355 | inlay_hints::inlay_hints(db, file_id, &db.parse(file_id).tree(), &truncate_options) | 353 | inlay_hints::inlay_hints(db, file_id, &db.parse(file_id).tree(), max_inlay_hint_length) |
356 | }) | 354 | }) |
357 | } | 355 | } |
358 | 356 | ||