1 //! Completes `where` and `for` keywords.
3 use syntax::ast::{self, Item};
5 use crate::{CompletionContext, Completions};
7 pub(crate) fn complete_for_and_where(
9 ctx: &CompletionContext<'_>,
10 keyword_item: &ast::Item,
12 let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet);
16 if it.for_token().is_none() && it.trait_().is_none() && it.self_ty().is_some() {
17 add_keyword("for", "for");
19 add_keyword("where", "where");
27 add_keyword("where", "where");
35 use expect_test::{expect, Expect};
37 use crate::tests::{check_edit, completion_list};
39 fn check(ra_fixture: &str, expect: Expect) {
40 let actual = completion_list(ra_fixture);
41 expect.assert_eq(&actual)
45 fn test_else_edit_after_if() {
48 r#"fn quux() { if true { () } $0 }"#,
49 r#"fn quux() { if true { () } else {
56 fn test_keywords_after_unsafe_in_block_expr() {
58 r"fn my_fn() { unsafe $0 }",
68 fn test_completion_await_impls_future() {
79 me into_future() (as IntoFuture) fn(self) -> <Self as IntoFuture>::IntoFuture
81 sn call function(expr)
86 sn match match expr {}
103 me into_future() (use core::future::IntoFuture) fn(self) -> <Self as IntoFuture>::IntoFuture
104 sn box Box::new(expr)
105 sn call function(expr)
110 sn match match expr {}
118 fn test_completion_await_impls_into_future() {
124 impl IntoFuture for A {}
125 fn foo(a: A) { a.$0 }
129 me into_future() (as IntoFuture) fn(self) -> <Self as IntoFuture>::IntoFuture
130 sn box Box::new(expr)
131 sn call function(expr)
136 sn match match expr {}
145 cov_mark::check!(let_semi);
149 fn main() { let x = $0 }
152 fn main() { let x = match $1 {
196 fn if_completion_in_match_guard() {
217 fn if_completion_in_match_arm_expr() {
240 fn if_completion_in_match_arm_expr_block() {