aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/keyword.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/keyword.rs')
-rw-r--r--crates/ide_completion/src/completions/keyword.rs109
1 files changed, 17 insertions, 92 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index 0fccbeccf..73bbc4345 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -75,7 +75,9 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
75 return; 75 return;
76 } 76 }
77 77
78 if expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field() { 78 if !ctx.has_visibility_prev_sibling()
79 && (expects_item || ctx.expects_non_trait_assoc_item() || ctx.expect_record_field())
80 {
79 add_keyword("pub(crate)", "pub(crate) "); 81 add_keyword("pub(crate)", "pub(crate) ");
80 add_keyword("pub", "pub "); 82 add_keyword("pub", "pub ");
81 } 83 }
@@ -88,11 +90,13 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
88 } 90 }
89 91
90 if expects_item || has_block_expr_parent { 92 if expects_item || has_block_expr_parent {
93 if !ctx.has_visibility_prev_sibling() {
94 add_keyword("impl", "impl $1 {\n $0\n}");
95 add_keyword("extern", "extern $0");
96 }
91 add_keyword("use", "use $0"); 97 add_keyword("use", "use $0");
92 add_keyword("impl", "impl $1 {\n $0\n}");
93 add_keyword("trait", "trait $1 {\n $0\n}"); 98 add_keyword("trait", "trait $1 {\n $0\n}");
94 add_keyword("static", "static $0"); 99 add_keyword("static", "static $0");
95 add_keyword("extern", "extern $0");
96 add_keyword("mod", "mod $0"); 100 add_keyword("mod", "mod $0");
97 } 101 }
98 102
@@ -186,12 +190,12 @@ mod tests {
186 use expect_test::{expect, Expect}; 190 use expect_test::{expect, Expect};
187 191
188 use crate::{ 192 use crate::{
189 test_utils::{check_edit, completion_list}, 193 tests::{check_edit, filtered_completion_list},
190 CompletionKind, 194 CompletionKind,
191 }; 195 };
192 196
193 fn check(ra_fixture: &str, expect: Expect) { 197 fn check(ra_fixture: &str, expect: Expect) {
194 let actual = completion_list(ra_fixture, CompletionKind::Keyword); 198 let actual = filtered_completion_list(ra_fixture, CompletionKind::Keyword);
195 expect.assert_eq(&actual) 199 expect.assert_eq(&actual)
196 } 200 }
197 201
@@ -231,30 +235,6 @@ mod tests {
231 } 235 }
232 236
233 #[test] 237 #[test]
234 fn test_keywords_at_source_file_level() {
235 check(
236 r"m$0",
237 expect![[r#"
238 kw pub(crate)
239 kw pub
240 kw unsafe
241 kw fn
242 kw const
243 kw type
244 kw use
245 kw impl
246 kw trait
247 kw static
248 kw extern
249 kw mod
250 kw enum
251 kw struct
252 kw union
253 "#]],
254 );
255 }
256
257 #[test]
258 fn test_keywords_in_function() { 238 fn test_keywords_in_function() {
259 check( 239 check(
260 r"fn quux() { $0 }", 240 r"fn quux() { $0 }",
@@ -263,11 +243,11 @@ mod tests {
263 kw fn 243 kw fn
264 kw const 244 kw const
265 kw type 245 kw type
266 kw use
267 kw impl 246 kw impl
247 kw extern
248 kw use
268 kw trait 249 kw trait
269 kw static 250 kw static
270 kw extern
271 kw mod 251 kw mod
272 kw match 252 kw match
273 kw while 253 kw while
@@ -291,11 +271,11 @@ mod tests {
291 kw fn 271 kw fn
292 kw const 272 kw const
293 kw type 273 kw type
294 kw use
295 kw impl 274 kw impl
275 kw extern
276 kw use
296 kw trait 277 kw trait
297 kw static 278 kw static
298 kw extern
299 kw mod 279 kw mod
300 kw match 280 kw match
301 kw while 281 kw while
@@ -319,11 +299,11 @@ mod tests {
319 kw fn 299 kw fn
320 kw const 300 kw const
321 kw type 301 kw type
322 kw use
323 kw impl 302 kw impl
303 kw extern
304 kw use
324 kw trait 305 kw trait
325 kw static 306 kw static
326 kw extern
327 kw mod 307 kw mod
328 kw match 308 kw match
329 kw while 309 kw while
@@ -370,49 +350,6 @@ fn quux() -> i32 {
370 } 350 }
371 351
372 #[test] 352 #[test]
373 fn test_keywords_in_trait_def() {
374 check(
375 r"trait My { $0 }",
376 expect![[r#"
377 kw unsafe
378 kw fn
379 kw const
380 kw type
381 "#]],
382 );
383 }
384
385 #[test]
386 fn test_keywords_in_impl_def() {
387 check(
388 r"impl My { $0 }",
389 expect![[r#"
390 kw pub(crate)
391 kw pub
392 kw unsafe
393 kw fn
394 kw const
395 kw type
396 "#]],
397 );
398 }
399
400 #[test]
401 fn test_keywords_in_impl_def_with_attr() {
402 check(
403 r"impl My { #[foo] $0 }",
404 expect![[r#"
405 kw pub(crate)
406 kw pub
407 kw unsafe
408 kw fn
409 kw const
410 kw type
411 "#]],
412 );
413 }
414
415 #[test]
416 fn test_keywords_in_loop() { 353 fn test_keywords_in_loop() {
417 check( 354 check(
418 r"fn my() { loop { $0 } }", 355 r"fn my() { loop { $0 } }",
@@ -421,11 +358,11 @@ fn quux() -> i32 {
421 kw fn 358 kw fn
422 kw const 359 kw const
423 kw type 360 kw type
424 kw use
425 kw impl 361 kw impl
362 kw extern
363 kw use
426 kw trait 364 kw trait
427 kw static 365 kw static
428 kw extern
429 kw mod 366 kw mod
430 kw match 367 kw match
431 kw while 368 kw while
@@ -443,18 +380,6 @@ fn quux() -> i32 {
443 } 380 }
444 381
445 #[test] 382 #[test]
446 fn test_keywords_after_unsafe_in_item_list() {
447 check(
448 r"unsafe $0",
449 expect![[r#"
450 kw fn
451 kw trait
452 kw impl
453 "#]],
454 );
455 }
456
457 #[test]
458 fn test_keywords_after_unsafe_in_block_expr() { 383 fn test_keywords_after_unsafe_in_block_expr() {
459 check( 384 check(
460 r"fn my_fn() { unsafe $0 }", 385 r"fn my_fn() { unsafe $0 }",