Cleanup dot completiont tests

This commit is contained in:
Aleksey Kladov 2020-07-04 10:36:12 +02:00
parent caeddff543
commit f2f6a46aa4
4 changed files with 408 additions and 721 deletions

File diff suppressed because it is too large Load diff

View file

@ -35,6 +35,19 @@ pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
} }
_ => {} _ => {}
} }
// Suggest .await syntax for types that implement Future trait
if let Some(receiver) = &ctx.dot_receiver {
if let Some(ty) = ctx.sema.type_of_expr(receiver) {
if ty.impls_future(ctx.db) {
CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await")
.kind(CompletionItemKind::Keyword)
.detail("expr.await")
.insert_text("await")
.add_to(acc);
}
};
}
} }
pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
@ -490,4 +503,26 @@ Some multi-line comment<|>
expect![[""]], expect![[""]],
); );
} }
#[test]
fn test_completion_await_impls_future() {
check(
r#"
//- /main.rs
use std::future::*;
struct A {}
impl Future for A {}
fn foo(a: A) { a.<|> }
//- /std/lib.rs
pub mod future {
#[lang = "future_trait"]
pub trait Future {}
}
"#,
expect![[r#"
kw await expr.await
"#]],
)
}
} }

View file

@ -1205,6 +1205,45 @@ mod tests {
); );
} }
#[test]
fn test_super_super_completion() {
assert_debug_snapshot!(
do_reference_completion(
r"
mod a {
const A: usize = 0;
mod b {
const B: usize = 0;
mod c {
use super::super::<|>
}
}
}
",
),
@r###"
[
CompletionItem {
label: "A",
source_range: 120..120,
delete: 120..120,
insert: "A",
kind: Const,
},
CompletionItem {
label: "b",
source_range: 120..120,
delete: 120..120,
insert: "b",
kind: Module,
},
]
"###
);
}
#[test] #[test]
fn completes_reexported_items_under_correct_name() { fn completes_reexported_items_under_correct_name() {
assert_debug_snapshot!( assert_debug_snapshot!(

View file

@ -643,6 +643,75 @@ fn foo() { A { the<|> } }
); );
} }
#[test]
fn renders_docs() {
check(
r#"
struct S {
/// Field docs
foo:
}
impl S {
/// Method docs
fn bar(self) { self.<|> }
}"#,
expect![[r#"
[
CompletionItem {
label: "bar()",
source_range: 94..94,
delete: 94..94,
insert: "bar()$0",
kind: Method,
lookup: "bar",
detail: "fn bar(self)",
documentation: Documentation(
"Method docs",
),
},
CompletionItem {
label: "foo",
source_range: 94..94,
delete: 94..94,
insert: "foo",
kind: Field,
detail: "{unknown}",
documentation: Documentation(
"Field docs",
),
},
]
"#]],
)
}
#[test]
fn dont_render_attrs() {
check(
r#"
struct S;
impl S {
#[inline]
fn the_method(&self) { }
}
fn foo(s: S) { s.<|> }
"#,
expect![[r#"
[
CompletionItem {
label: "the_method()",
source_range: 81..81,
delete: 81..81,
insert: "the_method()$0",
kind: Method,
lookup: "the_method",
detail: "fn the_method(&self)",
},
]
"#]],
)
}
#[test] #[test]
fn inserts_parens_for_function_calls() { fn inserts_parens_for_function_calls() {
mark::check!(inserts_parens_for_function_calls); mark::check!(inserts_parens_for_function_calls);