aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2019-07-21 18:51:27 +0100
committerKirill Bulatov <[email protected]>2019-07-21 18:51:27 +0100
commit24784c60df583d1807faa889a84312df1d2e3b22 (patch)
tree69fee254755a8db21a8ad55e894b3a26a3c9a2b0
parent201b344f2b0c9e84606115d135cd658d0a955d2c (diff)
Code review fixes
-rw-r--r--crates/ra_ide_api/src/inlay_hints.rs64
-rw-r--r--crates/ra_ide_api/src/lib.rs4
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap63
3 files changed, 62 insertions, 69 deletions
diff --git a/crates/ra_ide_api/src/inlay_hints.rs b/crates/ra_ide_api/src/inlay_hints.rs
index 4d1df65d0..739a44b19 100644
--- a/crates/ra_ide_api/src/inlay_hints.rs
+++ b/crates/ra_ide_api/src/inlay_hints.rs
@@ -61,7 +61,7 @@ fn get_inlay_hints(node: &SyntaxNode) -> Vec<InlayHint> {
61 } 61 }
62 }) 62 })
63 .accept(&node) 63 .accept(&node)
64 .unwrap_or_else(Vec::new) 64 .unwrap_or_default()
65} 65}
66 66
67#[cfg(test)] 67#[cfg(test)]
@@ -93,7 +93,7 @@ fn main() {
93 let i_squared = i * i; 93 let i_squared = i * i;
94 i_squared 94 i_squared
95 }); 95 });
96 96
97 let test: i32 = 33; 97 let test: i32 = 33;
98 98
99 let (x, c) = (42, 'a'); 99 let (x, c) = (42, 'a');
@@ -104,7 +104,63 @@ fn main() {
104 ) 104 )
105 .ok() 105 .ok()
106 .unwrap(); 106 .unwrap();
107 let hints = inlay_hints(&file); 107 assert_debug_snapshot_matches!(inlay_hints(&file), @r#"[
108 assert_debug_snapshot_matches!("inlay_hints", hints); 108 InlayHint {
109 range: [71; 75),
110 text: "let test = 54;",
111 inlay_kind: LetBinding,
112 },
113 InlayHint {
114 range: [90; 94),
115 text: "let test = InnerStruct {};",
116 inlay_kind: LetBinding,
117 },
118 InlayHint {
119 range: [121; 125),
120 text: "let test = OuterStruct {};",
121 inlay_kind: LetBinding,
122 },
123 InlayHint {
124 range: [152; 156),
125 text: "let test = vec![222];",
126 inlay_kind: LetBinding,
127 },
128 InlayHint {
129 range: [178; 186),
130 text: "let mut test = Vec::new();",
131 inlay_kind: LetBinding,
132 },
133 InlayHint {
134 range: [229; 233),
135 text: "let test = test.into_iter().map(|i| i * i).collect::<Vec<_>>();",
136 inlay_kind: LetBinding,
137 },
138 InlayHint {
139 range: [258; 259),
140 text: "i",
141 inlay_kind: ClosureParameter,
142 },
143 InlayHint {
144 range: [297; 305),
145 text: "let mut test = 33;",
146 inlay_kind: LetBinding,
147 },
148 InlayHint {
149 range: [417; 426),
150 text: "let i_squared = i * i;",
151 inlay_kind: LetBinding,
152 },
153 InlayHint {
154 range: [496; 502),
155 text: "let (x, c) = (42, \'a\');",
156 inlay_kind: LetBinding,
157 },
158 InlayHint {
159 range: [524; 528),
160 text: "let test = (42, \'a\');",
161 inlay_kind: LetBinding,
162 },
163]"#
164 );
109 } 165 }
110} 166}
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index af163088a..32168f12d 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -399,8 +399,8 @@ impl Analysis {
399 } 399 }
400 400
401 /// Returns a list of the places in the file where type hints can be displayed. 401 /// Returns a list of the places in the file where type hints can be displayed.
402 pub fn inlay_hints(&self, file_id: FileId) -> Vec<InlayHint> { 402 pub fn inlay_hints(&self, file_id: FileId) -> Cancelable<Vec<InlayHint>> {
403 inlay_hints::inlay_hints(&self.db.parse(file_id).tree()) 403 self.with_db(|db| inlay_hints::inlay_hints(&db.parse(file_id).tree()))
404 } 404 }
405 405
406 /// Returns the set of folding ranges. 406 /// Returns the set of folding ranges.
diff --git a/crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap b/crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap
deleted file mode 100644
index f4d562314..000000000
--- a/crates/ra_ide_api/src/snapshots/tests__inlay_hints.snap
+++ /dev/null
@@ -1,63 +0,0 @@
1---
2created: "2019-07-20T20:13:53.385368Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/inlay_hints.rs
5expression: hints
6---
7[
8 InlayHint {
9 range: [71; 75),
10 text: "let test = 54;",
11 inlay_kind: LetBinding,
12 },
13 InlayHint {
14 range: [90; 94),
15 text: "let test = InnerStruct {};",
16 inlay_kind: LetBinding,
17 },
18 InlayHint {
19 range: [121; 125),
20 text: "let test = OuterStruct {};",
21 inlay_kind: LetBinding,
22 },
23 InlayHint {
24 range: [152; 156),
25 text: "let test = vec![222];",
26 inlay_kind: LetBinding,
27 },
28 InlayHint {
29 range: [178; 186),
30 text: "let mut test = Vec::new();",
31 inlay_kind: LetBinding,
32 },
33 InlayHint {
34 range: [229; 233),
35 text: "let test = test.into_iter().map(|i| i * i).collect::<Vec<_>>();",
36 inlay_kind: LetBinding,
37 },
38 InlayHint {
39 range: [258; 259),
40 text: "i",
41 inlay_kind: ClosureParameter,
42 },
43 InlayHint {
44 range: [297; 305),
45 text: "let mut test = 33;",
46 inlay_kind: LetBinding,
47 },
48 InlayHint {
49 range: [417; 426),
50 text: "let i_squared = i * i;",
51 inlay_kind: LetBinding,
52 },
53 InlayHint {
54 range: [500; 506),
55 text: "let (x, c) = (42, \'a\');",
56 inlay_kind: LetBinding,
57 },
58 InlayHint {
59 range: [528; 532),
60 text: "let test = (42, \'a\');",
61 inlay_kind: LetBinding,
62 },
63]