diff options
author | Aleksey Kladov <[email protected]> | 2019-04-02 12:04:23 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-04-02 12:49:46 +0100 |
commit | 7d6bd5d1379061180e771f7b833a9fecdc85a0b8 (patch) | |
tree | f2c8c4b116f73d8b5da458c50ba5b7a03a42c4f8 /crates/ra_ide_api/src | |
parent | 2d680ff93aa30a52ffe40bb7d359e19565dca733 (diff) |
always show token text
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/syntax_tree.rs | 169 |
1 files changed, 85 insertions, 84 deletions
diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs index a4e4c3dbe..c7288220c 100644 --- a/crates/ra_ide_api/src/syntax_tree.rs +++ b/crates/ra_ide_api/src/syntax_tree.rs | |||
@@ -93,6 +93,8 @@ fn syntax_tree_for_token(node: SyntaxToken, text_range: TextRange) -> Option<Str | |||
93 | 93 | ||
94 | #[cfg(test)] | 94 | #[cfg(test)] |
95 | mod tests { | 95 | mod tests { |
96 | use test_utils::assert_eq_text; | ||
97 | |||
96 | use crate::mock_analysis::{single_file, single_file_with_range}; | 98 | use crate::mock_analysis::{single_file, single_file_with_range}; |
97 | 99 | ||
98 | #[test] | 100 | #[test] |
@@ -101,23 +103,23 @@ mod tests { | |||
101 | let (analysis, file_id) = single_file(r#"fn foo() {}"#); | 103 | let (analysis, file_id) = single_file(r#"fn foo() {}"#); |
102 | let syn = analysis.syntax_tree(file_id, None); | 104 | let syn = analysis.syntax_tree(file_id, None); |
103 | 105 | ||
104 | assert_eq!( | 106 | assert_eq_text!( |
105 | syn.trim(), | 107 | syn.trim(), |
106 | r#" | 108 | r#" |
107 | SOURCE_FILE@[0; 11) | 109 | SOURCE_FILE@[0; 11) |
108 | FN_DEF@[0; 11) | 110 | FN_DEF@[0; 11) |
109 | FN_KW@[0; 2) | 111 | FN_KW@[0; 2) "fn" |
110 | WHITESPACE@[2; 3) | 112 | WHITESPACE@[2; 3) " " |
111 | NAME@[3; 6) | 113 | NAME@[3; 6) |
112 | IDENT@[3; 6) "foo" | 114 | IDENT@[3; 6) "foo" |
113 | PARAM_LIST@[6; 8) | 115 | PARAM_LIST@[6; 8) |
114 | L_PAREN@[6; 7) | 116 | L_PAREN@[6; 7) "(" |
115 | R_PAREN@[7; 8) | 117 | R_PAREN@[7; 8) ")" |
116 | WHITESPACE@[8; 9) | 118 | WHITESPACE@[8; 9) " " |
117 | BLOCK@[9; 11) | 119 | BLOCK@[9; 11) |
118 | L_CURLY@[9; 10) | 120 | L_CURLY@[9; 10) "{" |
119 | R_CURLY@[10; 11) | 121 | R_CURLY@[10; 11) "}" |
120 | "# | 122 | "# |
121 | .trim() | 123 | .trim() |
122 | ); | 124 | ); |
123 | 125 | ||
@@ -133,40 +135,40 @@ fn test() { | |||
133 | ); | 135 | ); |
134 | let syn = analysis.syntax_tree(file_id, None); | 136 | let syn = analysis.syntax_tree(file_id, None); |
135 | 137 | ||
136 | assert_eq!( | 138 | assert_eq_text!( |
137 | syn.trim(), | 139 | syn.trim(), |
138 | r#" | 140 | r#" |
139 | SOURCE_FILE@[0; 60) | 141 | SOURCE_FILE@[0; 60) |
140 | FN_DEF@[0; 60) | 142 | FN_DEF@[0; 60) |
141 | FN_KW@[0; 2) | 143 | FN_KW@[0; 2) "fn" |
142 | WHITESPACE@[2; 3) | 144 | WHITESPACE@[2; 3) " " |
143 | NAME@[3; 7) | 145 | NAME@[3; 7) |
144 | IDENT@[3; 7) "test" | 146 | IDENT@[3; 7) "test" |
145 | PARAM_LIST@[7; 9) | 147 | PARAM_LIST@[7; 9) |
146 | L_PAREN@[7; 8) | 148 | L_PAREN@[7; 8) "(" |
147 | R_PAREN@[8; 9) | 149 | R_PAREN@[8; 9) ")" |
148 | WHITESPACE@[9; 10) | 150 | WHITESPACE@[9; 10) " " |
149 | BLOCK@[10; 60) | 151 | BLOCK@[10; 60) |
150 | L_CURLY@[10; 11) | 152 | L_CURLY@[10; 11) "{" |
151 | WHITESPACE@[11; 16) | 153 | WHITESPACE@[11; 16) "\n " |
152 | EXPR_STMT@[16; 58) | 154 | EXPR_STMT@[16; 58) |
153 | MACRO_CALL@[16; 57) | 155 | MACRO_CALL@[16; 57) |
154 | PATH@[16; 22) | 156 | PATH@[16; 22) |
155 | PATH_SEGMENT@[16; 22) | 157 | PATH_SEGMENT@[16; 22) |
156 | NAME_REF@[16; 22) | 158 | NAME_REF@[16; 22) |
157 | IDENT@[16; 22) "assert" | 159 | IDENT@[16; 22) "assert" |
158 | EXCL@[22; 23) | 160 | EXCL@[22; 23) "!" |
159 | TOKEN_TREE@[23; 57) | 161 | TOKEN_TREE@[23; 57) |
160 | L_PAREN@[23; 24) | 162 | L_PAREN@[23; 24) "(" |
161 | STRING@[24; 52) | 163 | STRING@[24; 52) "\"\n fn foo() {\n ..." |
162 | COMMA@[52; 53) | 164 | COMMA@[52; 53) "," |
163 | WHITESPACE@[53; 54) | 165 | WHITESPACE@[53; 54) " " |
164 | STRING@[54; 56) | 166 | STRING@[54; 56) "\"\"" |
165 | R_PAREN@[56; 57) | 167 | R_PAREN@[56; 57) ")" |
166 | SEMI@[57; 58) | 168 | SEMI@[57; 58) ";" |
167 | WHITESPACE@[58; 59) | 169 | WHITESPACE@[58; 59) "\n" |
168 | R_CURLY@[59; 60) | 170 | R_CURLY@[59; 60) "}" |
169 | "# | 171 | "# |
170 | .trim() | 172 | .trim() |
171 | ); | 173 | ); |
172 | } | 174 | } |
@@ -176,22 +178,22 @@ SOURCE_FILE@[0; 60) | |||
176 | let (analysis, range) = single_file_with_range(r#"<|>fn foo() {}<|>"#.trim()); | 178 | let (analysis, range) = single_file_with_range(r#"<|>fn foo() {}<|>"#.trim()); |
177 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); | 179 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); |
178 | 180 | ||
179 | assert_eq!( | 181 | assert_eq_text!( |
180 | syn.trim(), | 182 | syn.trim(), |
181 | r#" | 183 | r#" |
182 | FN_DEF@[0; 11) | 184 | FN_DEF@[0; 11) |
183 | FN_KW@[0; 2) | 185 | FN_KW@[0; 2) "fn" |
184 | WHITESPACE@[2; 3) | 186 | WHITESPACE@[2; 3) " " |
185 | NAME@[3; 6) | 187 | NAME@[3; 6) |
186 | IDENT@[3; 6) "foo" | 188 | IDENT@[3; 6) "foo" |
187 | PARAM_LIST@[6; 8) | 189 | PARAM_LIST@[6; 8) |
188 | L_PAREN@[6; 7) | 190 | L_PAREN@[6; 7) "(" |
189 | R_PAREN@[7; 8) | 191 | R_PAREN@[7; 8) ")" |
190 | WHITESPACE@[8; 9) | 192 | WHITESPACE@[8; 9) " " |
191 | BLOCK@[9; 11) | 193 | BLOCK@[9; 11) |
192 | L_CURLY@[9; 10) | 194 | L_CURLY@[9; 10) "{" |
193 | R_CURLY@[10; 11) | 195 | R_CURLY@[10; 11) "}" |
194 | "# | 196 | "# |
195 | .trim() | 197 | .trim() |
196 | ); | 198 | ); |
197 | 199 | ||
@@ -206,7 +208,7 @@ FN_DEF@[0; 11) | |||
206 | ); | 208 | ); |
207 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); | 209 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); |
208 | 210 | ||
209 | assert_eq!( | 211 | assert_eq_text!( |
210 | syn.trim(), | 212 | syn.trim(), |
211 | r#" | 213 | r#" |
212 | EXPR_STMT@[16; 58) | 214 | EXPR_STMT@[16; 58) |
@@ -215,16 +217,16 @@ EXPR_STMT@[16; 58) | |||
215 | PATH_SEGMENT@[16; 22) | 217 | PATH_SEGMENT@[16; 22) |
216 | NAME_REF@[16; 22) | 218 | NAME_REF@[16; 22) |
217 | IDENT@[16; 22) "assert" | 219 | IDENT@[16; 22) "assert" |
218 | EXCL@[22; 23) | 220 | EXCL@[22; 23) "!" |
219 | TOKEN_TREE@[23; 57) | 221 | TOKEN_TREE@[23; 57) |
220 | L_PAREN@[23; 24) | 222 | L_PAREN@[23; 24) "(" |
221 | STRING@[24; 52) | 223 | STRING@[24; 52) "\"\n fn foo() {\n ..." |
222 | COMMA@[52; 53) | 224 | COMMA@[52; 53) "," |
223 | WHITESPACE@[53; 54) | 225 | WHITESPACE@[53; 54) " " |
224 | STRING@[54; 56) | 226 | STRING@[54; 56) "\"\"" |
225 | R_PAREN@[56; 57) | 227 | R_PAREN@[56; 57) ")" |
226 | SEMI@[57; 58) | 228 | SEMI@[57; 58) ";" |
227 | "# | 229 | "# |
228 | .trim() | 230 | .trim() |
229 | ); | 231 | ); |
230 | } | 232 | } |
@@ -243,23 +245,23 @@ fn bar() { | |||
243 | .trim(), | 245 | .trim(), |
244 | ); | 246 | ); |
245 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); | 247 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); |
246 | assert_eq!( | 248 | assert_eq_text!( |
247 | syn.trim(), | 249 | syn.trim(), |
248 | r#" | 250 | r#" |
249 | SOURCE_FILE@[0; 12) | 251 | SOURCE_FILE@[0; 12) |
250 | FN_DEF@[0; 12) | 252 | FN_DEF@[0; 12) |
251 | FN_KW@[0; 2) | 253 | FN_KW@[0; 2) "fn" |
252 | WHITESPACE@[2; 3) | 254 | WHITESPACE@[2; 3) " " |
253 | NAME@[3; 6) | 255 | NAME@[3; 6) |
254 | IDENT@[3; 6) "foo" | 256 | IDENT@[3; 6) "foo" |
255 | PARAM_LIST@[6; 8) | 257 | PARAM_LIST@[6; 8) |
256 | L_PAREN@[6; 7) | 258 | L_PAREN@[6; 7) "(" |
257 | R_PAREN@[7; 8) | 259 | R_PAREN@[7; 8) ")" |
258 | WHITESPACE@[8; 9) | 260 | WHITESPACE@[8; 9) " " |
259 | BLOCK@[9; 12) | 261 | BLOCK@[9; 12) |
260 | L_CURLY@[9; 10) | 262 | L_CURLY@[9; 10) "{" |
261 | WHITESPACE@[10; 11) | 263 | WHITESPACE@[10; 11) "\n" |
262 | R_CURLY@[11; 12) | 264 | R_CURLY@[11; 12) "}" |
263 | "# | 265 | "# |
264 | .trim() | 266 | .trim() |
265 | ); | 267 | ); |
@@ -277,23 +279,23 @@ fn bar() { | |||
277 | .trim(), | 279 | .trim(), |
278 | ); | 280 | ); |
279 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); | 281 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); |
280 | assert_eq!( | 282 | assert_eq_text!( |
281 | syn.trim(), | 283 | syn.trim(), |
282 | r#" | 284 | r#" |
283 | SOURCE_FILE@[0; 12) | 285 | SOURCE_FILE@[0; 12) |
284 | FN_DEF@[0; 12) | 286 | FN_DEF@[0; 12) |
285 | FN_KW@[0; 2) | 287 | FN_KW@[0; 2) "fn" |
286 | WHITESPACE@[2; 3) | 288 | WHITESPACE@[2; 3) " " |
287 | NAME@[3; 6) | 289 | NAME@[3; 6) |
288 | IDENT@[3; 6) "foo" | 290 | IDENT@[3; 6) "foo" |
289 | PARAM_LIST@[6; 8) | 291 | PARAM_LIST@[6; 8) |
290 | L_PAREN@[6; 7) | 292 | L_PAREN@[6; 7) "(" |
291 | R_PAREN@[7; 8) | 293 | R_PAREN@[7; 8) ")" |
292 | WHITESPACE@[8; 9) | 294 | WHITESPACE@[8; 9) " " |
293 | BLOCK@[9; 12) | 295 | BLOCK@[9; 12) |
294 | L_CURLY@[9; 10) | 296 | L_CURLY@[9; 10) "{" |
295 | WHITESPACE@[10; 11) | 297 | WHITESPACE@[10; 11) "\n" |
296 | R_CURLY@[11; 12) | 298 | R_CURLY@[11; 12) "}" |
297 | "# | 299 | "# |
298 | .trim() | 300 | .trim() |
299 | ); | 301 | ); |
@@ -310,38 +312,37 @@ fn bar() { | |||
310 | .trim(), | 312 | .trim(), |
311 | ); | 313 | ); |
312 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); | 314 | let syn = analysis.syntax_tree(range.file_id, Some(range.range)); |
313 | assert_eq!( | 315 | assert_eq_text!( |
314 | syn.trim(), | 316 | syn.trim(), |
315 | r#" | 317 | r#" |
316 | SOURCE_FILE@[0; 25) | 318 | SOURCE_FILE@[0; 25) |
317 | FN_DEF@[0; 12) | 319 | FN_DEF@[0; 12) |
318 | FN_KW@[0; 2) | 320 | FN_KW@[0; 2) "fn" |
319 | WHITESPACE@[2; 3) | 321 | WHITESPACE@[2; 3) " " |
320 | NAME@[3; 6) | 322 | NAME@[3; 6) |
321 | IDENT@[3; 6) "foo" | 323 | IDENT@[3; 6) "foo" |
322 | PARAM_LIST@[6; 8) | 324 | PARAM_LIST@[6; 8) |
323 | L_PAREN@[6; 7) | 325 | L_PAREN@[6; 7) "(" |
324 | R_PAREN@[7; 8) | 326 | R_PAREN@[7; 8) ")" |
325 | WHITESPACE@[8; 9) | 327 | WHITESPACE@[8; 9) " " |
326 | BLOCK@[9; 12) | 328 | BLOCK@[9; 12) |
327 | L_CURLY@[9; 10) | 329 | L_CURLY@[9; 10) "{" |
328 | WHITESPACE@[10; 11) | 330 | WHITESPACE@[10; 11) "\n" |
329 | R_CURLY@[11; 12) | 331 | R_CURLY@[11; 12) "}" |
330 | WHITESPACE@[12; 13) | 332 | WHITESPACE@[12; 13) "\n" |
331 | FN_DEF@[13; 25) | 333 | FN_DEF@[13; 25) |
332 | FN_KW@[13; 15) | 334 | FN_KW@[13; 15) "fn" |
333 | WHITESPACE@[15; 16) | 335 | WHITESPACE@[15; 16) " " |
334 | NAME@[16; 19) | 336 | NAME@[16; 19) |
335 | IDENT@[16; 19) "bar" | 337 | IDENT@[16; 19) "bar" |
336 | PARAM_LIST@[19; 21) | 338 | PARAM_LIST@[19; 21) |
337 | L_PAREN@[19; 20) | 339 | L_PAREN@[19; 20) "(" |
338 | R_PAREN@[20; 21) | 340 | R_PAREN@[20; 21) ")" |
339 | WHITESPACE@[21; 22) | 341 | WHITESPACE@[21; 22) " " |
340 | BLOCK@[22; 25) | 342 | BLOCK@[22; 25) |
341 | L_CURLY@[22; 23) | 343 | L_CURLY@[22; 23) "{" |
342 | WHITESPACE@[23; 24) | 344 | WHITESPACE@[23; 24) "\n" |
343 | R_CURLY@[24; 25) | 345 | R_CURLY@[24; 25) "}" |
344 | |||
345 | "# | 346 | "# |
346 | .trim() | 347 | .trim() |
347 | ); | 348 | ); |