aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorSteffen Lyngbaek <[email protected]>2020-03-10 18:21:56 +0000
committerSteffen Lyngbaek <[email protected]>2020-03-10 21:36:01 +0000
commitcfb48df149bfa8a15b113b1a252598457a4ea392 (patch)
tree8672e75715e2def7963e6250700125b17f233009 /crates/ra_ide/src
parente98aff109a1c4bda6a05f16981898425c302aa0c (diff)
Address Issues from Github
- Updated naming of config - Define struct in ra_ide and use remote derive in rust-analyzer/config - Make inlayConfig type more flexible to support more future types - Remove constructor only used in tests
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/inlay_hints.rs61
-rw-r--r--crates/ra_ide/src/lib.rs5
2 files changed, 37 insertions, 29 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 0f1c13c14..8454a975b 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -3,7 +3,6 @@
3use hir::{Adt, HirDisplay, Semantics, Type}; 3use hir::{Adt, HirDisplay, Semantics, Type};
4use ra_ide_db::RootDatabase; 4use ra_ide_db::RootDatabase;
5use ra_prof::profile; 5use ra_prof::profile;
6use ra_project_model::{InlayHintDisplayType, InlayHintOptions};
7use ra_syntax::{ 6use ra_syntax::{
8 ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, 7 ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner},
9 match_ast, SmolStr, TextRange, 8 match_ast, SmolStr, TextRange,
@@ -11,7 +10,19 @@ use ra_syntax::{
11 10
12use crate::{FileId, FunctionSignature}; 11use crate::{FileId, FunctionSignature};
13 12
14#[derive(Debug, PartialEq, Eq)] 13#[derive(Clone, Debug, PartialEq, Eq)]
14pub struct InlayConfig {
15 pub display_type: Vec<InlayKind>,
16 pub max_length: Option<usize>,
17}
18
19impl Default for InlayConfig {
20 fn default() -> Self {
21 Self { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: None }
22 }
23}
24
25#[derive(Clone, Debug, PartialEq, Eq)]
15pub enum InlayKind { 26pub enum InlayKind {
16 TypeHint, 27 TypeHint,
17 ParameterHint, 28 ParameterHint,
@@ -27,7 +38,7 @@ pub struct InlayHint {
27pub(crate) fn inlay_hints( 38pub(crate) fn inlay_hints(
28 db: &RootDatabase, 39 db: &RootDatabase,
29 file_id: FileId, 40 file_id: FileId,
30 inlay_hint_opts: &InlayHintOptions, 41 inlay_hint_opts: &InlayConfig,
31) -> Vec<InlayHint> { 42) -> Vec<InlayHint> {
32 let _p = profile("inlay_hints"); 43 let _p = profile("inlay_hints");
33 let sema = Semantics::new(db); 44 let sema = Semantics::new(db);
@@ -50,12 +61,11 @@ pub(crate) fn inlay_hints(
50fn get_param_name_hints( 61fn get_param_name_hints(
51 acc: &mut Vec<InlayHint>, 62 acc: &mut Vec<InlayHint>,
52 sema: &Semantics<RootDatabase>, 63 sema: &Semantics<RootDatabase>,
53 inlay_hint_opts: &InlayHintOptions, 64 inlay_hint_opts: &InlayConfig,
54 expr: ast::Expr, 65 expr: ast::Expr,
55) -> Option<()> { 66) -> Option<()> {
56 match inlay_hint_opts.display_type { 67 if !inlay_hint_opts.display_type.contains(&InlayKind::ParameterHint) {
57 InlayHintDisplayType::Off | InlayHintDisplayType::TypeHints => return None, 68 return None;
58 _ => {}
59 } 69 }
60 70
61 let args = match &expr { 71 let args = match &expr {
@@ -91,12 +101,11 @@ fn get_param_name_hints(
91fn get_bind_pat_hints( 101fn get_bind_pat_hints(
92 acc: &mut Vec<InlayHint>, 102 acc: &mut Vec<InlayHint>,
93 sema: &Semantics<RootDatabase>, 103 sema: &Semantics<RootDatabase>,
94 inlay_hint_opts: &InlayHintOptions, 104 inlay_hint_opts: &InlayConfig,
95 pat: ast::BindPat, 105 pat: ast::BindPat,
96) -> Option<()> { 106) -> Option<()> {
97 match inlay_hint_opts.display_type { 107 if !inlay_hint_opts.display_type.contains(&InlayKind::TypeHint) {
98 InlayHintDisplayType::Off | InlayHintDisplayType::ParameterHints => return None, 108 return None;
99 _ => {}
100 } 109 }
101 110
102 let ty = sema.type_of_pat(&pat.clone().into())?; 111 let ty = sema.type_of_pat(&pat.clone().into())?;
@@ -214,10 +223,10 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
214 223
215#[cfg(test)] 224#[cfg(test)]
216mod tests { 225mod tests {
226 use crate::inlay_hints::{InlayConfig, InlayKind};
217 use insta::assert_debug_snapshot; 227 use insta::assert_debug_snapshot;
218 228
219 use crate::mock_analysis::single_file; 229 use crate::mock_analysis::single_file;
220 use ra_project_model::{InlayHintDisplayType, InlayHintOptions};
221 230
222 #[test] 231 #[test]
223 fn param_hints_only() { 232 fn param_hints_only() {
@@ -228,7 +237,7 @@ mod tests {
228 let _x = foo(4, 4); 237 let _x = foo(4, 4);
229 }"#, 238 }"#,
230 ); 239 );
231 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions{ display_type: InlayHintDisplayType::ParameterHints, max_length: None}).unwrap(), @r###" 240 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![InlayKind::ParameterHint], max_length: None}).unwrap(), @r###"
232 [ 241 [
233 InlayHint { 242 InlayHint {
234 range: [106; 107), 243 range: [106; 107),
@@ -252,7 +261,7 @@ mod tests {
252 let _x = foo(4, 4); 261 let _x = foo(4, 4);
253 }"#, 262 }"#,
254 ); 263 );
255 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions{ display_type: InlayHintDisplayType::Off, max_length: None}).unwrap(), @r###"[]"###); 264 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![], max_length: None}).unwrap(), @r###"[]"###);
256 } 265 }
257 266
258 #[test] 267 #[test]
@@ -264,7 +273,7 @@ mod tests {
264 let _x = foo(4, 4); 273 let _x = foo(4, 4);
265 }"#, 274 }"#,
266 ); 275 );
267 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions{ display_type: InlayHintDisplayType::TypeHints, max_length: None}).unwrap(), @r###" 276 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![InlayKind::TypeHint], max_length: None}).unwrap(), @r###"
268 [ 277 [
269 InlayHint { 278 InlayHint {
270 range: [97; 99), 279 range: [97; 99),
@@ -288,7 +297,7 @@ fn main() {
288}"#, 297}"#,
289 ); 298 );
290 299
291 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 300 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
292 [ 301 [
293 InlayHint { 302 InlayHint {
294 range: [69; 71), 303 range: [69; 71),
@@ -345,7 +354,7 @@ fn main() {
345}"#, 354}"#,
346 ); 355 );
347 356
348 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 357 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
349 [ 358 [
350 InlayHint { 359 InlayHint {
351 range: [193; 197), 360 range: [193; 197),
@@ -425,7 +434,7 @@ fn main() {
425}"#, 434}"#,
426 ); 435 );
427 436
428 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 437 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
429 [ 438 [
430 InlayHint { 439 InlayHint {
431 range: [21; 30), 440 range: [21; 30),
@@ -489,7 +498,7 @@ fn main() {
489}"#, 498}"#,
490 ); 499 );
491 500
492 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 501 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
493 [ 502 [
494 InlayHint { 503 InlayHint {
495 range: [21; 30), 504 range: [21; 30),
@@ -539,7 +548,7 @@ fn main() {
539}"#, 548}"#,
540 ); 549 );
541 550
542 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 551 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
543 [ 552 [
544 InlayHint { 553 InlayHint {
545 range: [188; 192), 554 range: [188; 192),
@@ -634,7 +643,7 @@ fn main() {
634}"#, 643}"#,
635 ); 644 );
636 645
637 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 646 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
638 [ 647 [
639 InlayHint { 648 InlayHint {
640 range: [188; 192), 649 range: [188; 192),
@@ -729,7 +738,7 @@ fn main() {
729}"#, 738}"#,
730 ); 739 );
731 740
732 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 741 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
733 [ 742 [
734 InlayHint { 743 InlayHint {
735 range: [252; 256), 744 range: [252; 256),
@@ -801,7 +810,7 @@ fn main() {
801}"#, 810}"#,
802 ); 811 );
803 812
804 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(Some(8))).unwrap(), @r###" 813 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###"
805 [ 814 [
806 InlayHint { 815 InlayHint {
807 range: [74; 75), 816 range: [74; 75),
@@ -889,7 +898,7 @@ fn main() {
889}"#, 898}"#,
890 ); 899 );
891 900
892 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(None)).unwrap(), @r###" 901 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###"
893 [ 902 [
894 InlayHint { 903 InlayHint {
895 range: [798; 809), 904 range: [798; 809),
@@ -1011,7 +1020,7 @@ fn main() {
1011}"#, 1020}"#,
1012 ); 1021 );
1013 1022
1014 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(Some(8))).unwrap(), @r###" 1023 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###"
1015 [] 1024 []
1016 "### 1025 "###
1017 ); 1026 );
@@ -1037,7 +1046,7 @@ fn main() {
1037}"#, 1046}"#,
1038 ); 1047 );
1039 1048
1040 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintOptions::new(Some(8))).unwrap(), @r###" 1049 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###"
1041 [] 1050 []
1042 "### 1051 "###
1043 ); 1052 );
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 8b1292a41..a3acfd225 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -44,7 +44,6 @@ mod marks;
44#[cfg(test)] 44#[cfg(test)]
45mod test_utils; 45mod test_utils;
46 46
47use ra_project_model::InlayHintOptions;
48use std::sync::Arc; 47use std::sync::Arc;
49 48
50use ra_cfg::CfgOptions; 49use ra_cfg::CfgOptions;
@@ -69,7 +68,7 @@ pub use crate::{
69 expand_macro::ExpandedMacro, 68 expand_macro::ExpandedMacro,
70 folding_ranges::{Fold, FoldKind}, 69 folding_ranges::{Fold, FoldKind},
71 hover::HoverResult, 70 hover::HoverResult,
72 inlay_hints::{InlayHint, InlayKind}, 71 inlay_hints::{InlayConfig, InlayHint, InlayKind},
73 references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, 72 references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
74 runnables::{Runnable, RunnableKind, TestId}, 73 runnables::{Runnable, RunnableKind, TestId},
75 source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, 74 source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
@@ -319,7 +318,7 @@ impl Analysis {
319 pub fn inlay_hints( 318 pub fn inlay_hints(
320 &self, 319 &self,
321 file_id: FileId, 320 file_id: FileId,
322 inlay_hint_opts: &InlayHintOptions, 321 inlay_hint_opts: &InlayConfig,
323 ) -> Cancelable<Vec<InlayHint>> { 322 ) -> Cancelable<Vec<InlayHint>> {
324 self.with_db(|db| inlay_hints::inlay_hints(db, file_id, inlay_hint_opts)) 323 self.with_db(|db| inlay_hints::inlay_hints(db, file_id, inlay_hint_opts))
325 } 324 }