2019-09-30 11:58:53 +03:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2020-04-12 17:45:07 +02:00
|
|
|
use hir::{
|
|
|
|
HasVisibility,
|
|
|
|
// HirDisplay,
|
|
|
|
Type,
|
|
|
|
};
|
2019-01-08 22:33:36 +03:00
|
|
|
|
2019-08-03 01:16:20 +07:00
|
|
|
use crate::{
|
2020-04-12 17:45:07 +02:00
|
|
|
call_info::call_info,
|
|
|
|
completion::{
|
|
|
|
completion_context::CompletionContext,
|
2020-04-16 18:30:08 +02:00
|
|
|
completion_item::{CompletionKind, Completions, ScoreOption},
|
2020-04-12 17:45:07 +02:00
|
|
|
},
|
|
|
|
// CallInfo,
|
2019-08-03 01:16:20 +07:00
|
|
|
CompletionItem,
|
|
|
|
};
|
2019-06-29 12:19:03 +02:00
|
|
|
use rustc_hash::FxHashSet;
|
2020-04-12 17:45:07 +02:00
|
|
|
// use std::cmp::Ordering;
|
2019-01-08 22:33:36 +03:00
|
|
|
|
2019-08-03 01:15:43 +07:00
|
|
|
/// Complete dot accesses, i.e. fields or methods (and .await syntax).
|
2019-01-15 21:09:51 +03:00
|
|
|
pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
2019-08-04 08:03:17 +07:00
|
|
|
let dot_receiver = match &ctx.dot_receiver {
|
|
|
|
Some(expr) => expr,
|
|
|
|
_ => return,
|
|
|
|
};
|
2019-08-03 01:15:43 +07:00
|
|
|
|
2020-02-18 18:35:10 +01:00
|
|
|
let receiver_ty = match ctx.sema.type_of_expr(&dot_receiver) {
|
2019-08-04 08:03:17 +07:00
|
|
|
Some(ty) => ty,
|
|
|
|
_ => return,
|
|
|
|
};
|
2019-08-03 01:15:43 +07:00
|
|
|
|
2019-08-04 08:03:17 +07:00
|
|
|
if !ctx.is_call {
|
2019-11-26 14:02:57 +03:00
|
|
|
complete_fields(acc, ctx, &receiver_ty);
|
2019-08-04 08:03:17 +07:00
|
|
|
}
|
2019-11-26 14:02:57 +03:00
|
|
|
complete_methods(acc, ctx, &receiver_ty);
|
2019-08-04 08:03:17 +07:00
|
|
|
|
|
|
|
// Suggest .await syntax for types that implement Future trait
|
2020-01-14 11:27:00 +01:00
|
|
|
if receiver_ty.impls_future(ctx.db) {
|
2019-08-04 08:03:17 +07:00
|
|
|
CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await")
|
|
|
|
.detail("expr.await")
|
|
|
|
.insert_text("await")
|
|
|
|
.add_to(acc);
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 14:02:57 +03:00
|
|
|
fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
|
|
|
|
for receiver in receiver.autoderef(ctx.db) {
|
2020-04-12 17:45:07 +02:00
|
|
|
let fields = receiver.fields(ctx.db);
|
|
|
|
|
2020-04-15 22:10:57 +02:00
|
|
|
if let Some(record_field) = &ctx.record_field_syntax {
|
2020-04-16 18:30:08 +02:00
|
|
|
acc.with_score_option(ScoreOption::RecordField(record_field.clone()));
|
2020-04-15 22:10:57 +02:00
|
|
|
} else if let Some(call_info) = call_info(ctx.db, ctx.file_position) {
|
2020-04-16 18:30:08 +02:00
|
|
|
acc.with_score_option(ScoreOption::CallFn(call_info));
|
2020-04-11 22:54:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (field, ty) in fields {
|
2020-03-07 17:53:22 +01:00
|
|
|
if ctx.scope().module().map_or(false, |m| !field.is_visible_from(ctx.db, m)) {
|
2019-12-24 21:46:07 +01:00
|
|
|
// Skip private field. FIXME: If the definition location of the
|
|
|
|
// field is editable, we should show the completion
|
|
|
|
continue;
|
|
|
|
}
|
2019-11-26 14:02:57 +03:00
|
|
|
acc.add_field(ctx, field, &ty);
|
|
|
|
}
|
|
|
|
for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
|
2019-12-24 21:46:07 +01:00
|
|
|
// FIXME: Handle visibility
|
2019-11-26 14:02:57 +03:00
|
|
|
acc.add_tuple_field(ctx, i, &ty);
|
|
|
|
}
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 14:02:57 +03:00
|
|
|
fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) {
|
2020-03-07 17:53:22 +01:00
|
|
|
if let Some(krate) = ctx.krate {
|
2020-01-14 14:42:52 +01:00
|
|
|
let mut seen_methods = FxHashSet::default();
|
2020-02-18 18:35:10 +01:00
|
|
|
let traits_in_scope = ctx.scope().traits_in_scope();
|
2020-01-14 14:42:52 +01:00
|
|
|
receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| {
|
2020-03-07 23:03:56 +01:00
|
|
|
if func.has_self_param(ctx.db)
|
|
|
|
&& ctx.scope().module().map_or(true, |m| func.is_visible_from(ctx.db, m))
|
|
|
|
&& seen_methods.insert(func.name(ctx.db))
|
|
|
|
{
|
2020-04-03 19:33:12 +02:00
|
|
|
acc.add_function(ctx, func, None);
|
2020-01-14 14:42:52 +01:00
|
|
|
}
|
|
|
|
None::<()>
|
|
|
|
});
|
|
|
|
}
|
2019-01-07 19:12:19 +01:00
|
|
|
}
|
|
|
|
|
2019-01-08 22:33:36 +03:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-04-16 18:30:08 +02:00
|
|
|
use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind};
|
2019-08-29 16:49:10 +03:00
|
|
|
use insta::assert_debug_snapshot;
|
2019-01-08 22:33:36 +03:00
|
|
|
|
2019-04-10 13:47:20 +03:00
|
|
|
fn do_ref_completion(code: &str) -> Vec<CompletionItem> {
|
|
|
|
do_completion(code, CompletionKind::Reference)
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-11-15 12:56:24 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [94; 94),
|
|
|
|
delete: [94; 94),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-01-08 22:33:36 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-11 22:54:18 +02:00
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion_in_func_call() {
|
|
|
|
assert_debug_snapshot!(
|
2020-04-16 18:30:08 +02:00
|
|
|
do_ref_completion(
|
2020-04-11 22:54:18 +02:00
|
|
|
r"
|
|
|
|
struct A { another_field: i64, the_field: u32, my_string: String }
|
|
|
|
fn test(my_param: u32) -> u32 { my_param }
|
|
|
|
fn foo(a: A) {
|
|
|
|
test(a.<|>)
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "another_field",
|
|
|
|
source_range: [201; 201),
|
|
|
|
delete: [201; 201),
|
|
|
|
insert: "another_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "i64",
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "my_string",
|
|
|
|
source_range: [201; 201),
|
|
|
|
delete: [201; 201),
|
|
|
|
insert: "my_string",
|
|
|
|
kind: Field,
|
|
|
|
detail: "{unknown}",
|
|
|
|
},
|
2020-04-16 18:30:08 +02:00
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [201; 201),
|
|
|
|
delete: [201; 201),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
score: TypeMatch,
|
|
|
|
},
|
2020-04-11 22:54:18 +02:00
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion_in_func_call_with_type_and_name() {
|
|
|
|
assert_debug_snapshot!(
|
2020-04-16 18:30:08 +02:00
|
|
|
do_ref_completion(
|
2020-04-11 22:54:18 +02:00
|
|
|
r"
|
|
|
|
struct A { another_field: i64, another_good_type: u32, the_field: u32 }
|
|
|
|
fn test(the_field: u32) -> u32 { the_field }
|
|
|
|
fn foo(a: A) {
|
|
|
|
test(a.<|>)
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
2020-04-16 18:30:08 +02:00
|
|
|
label: "another_field",
|
2020-04-11 22:54:18 +02:00
|
|
|
source_range: [208; 208),
|
|
|
|
delete: [208; 208),
|
2020-04-16 18:30:08 +02:00
|
|
|
insert: "another_field",
|
2020-04-11 22:54:18 +02:00
|
|
|
kind: Field,
|
2020-04-16 18:30:08 +02:00
|
|
|
detail: "i64",
|
2020-04-11 22:54:18 +02:00
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "another_good_type",
|
|
|
|
source_range: [208; 208),
|
|
|
|
delete: [208; 208),
|
|
|
|
insert: "another_good_type",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
2020-04-16 18:30:08 +02:00
|
|
|
score: TypeMatch,
|
2020-04-11 22:54:18 +02:00
|
|
|
},
|
|
|
|
CompletionItem {
|
2020-04-16 18:30:08 +02:00
|
|
|
label: "the_field",
|
2020-04-11 22:54:18 +02:00
|
|
|
source_range: [208; 208),
|
|
|
|
delete: [208; 208),
|
2020-04-16 18:30:08 +02:00
|
|
|
insert: "the_field",
|
2020-04-11 22:54:18 +02:00
|
|
|
kind: Field,
|
2020-04-16 18:30:08 +02:00
|
|
|
detail: "u32",
|
|
|
|
score: TypeAndNameMatch,
|
2020-04-11 22:54:18 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-15 22:10:57 +02:00
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion_in_record_lit() {
|
|
|
|
assert_debug_snapshot!(
|
2020-04-16 18:30:08 +02:00
|
|
|
do_ref_completion(
|
2020-04-15 22:10:57 +02:00
|
|
|
r"
|
|
|
|
struct A { another_field: i64, another_good_type: u32, the_field: u32 }
|
|
|
|
struct B { my_string: String, my_vec: Vec<u32>, the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
let b = B {
|
|
|
|
the_field: a.<|>
|
|
|
|
};
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
2020-04-16 18:30:08 +02:00
|
|
|
label: "another_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
source_range: [270; 270),
|
|
|
|
delete: [270; 270),
|
2020-04-16 18:30:08 +02:00
|
|
|
insert: "another_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
kind: Field,
|
2020-04-16 18:30:08 +02:00
|
|
|
detail: "i64",
|
2020-04-15 22:10:57 +02:00
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "another_good_type",
|
|
|
|
source_range: [270; 270),
|
|
|
|
delete: [270; 270),
|
|
|
|
insert: "another_good_type",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
2020-04-16 18:30:08 +02:00
|
|
|
score: TypeMatch,
|
2020-04-15 22:10:57 +02:00
|
|
|
},
|
|
|
|
CompletionItem {
|
2020-04-16 18:30:08 +02:00
|
|
|
label: "the_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
source_range: [270; 270),
|
|
|
|
delete: [270; 270),
|
2020-04-16 18:30:08 +02:00
|
|
|
insert: "the_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
kind: Field,
|
2020-04-16 18:30:08 +02:00
|
|
|
detail: "u32",
|
|
|
|
score: TypeAndNameMatch,
|
2020-04-15 22:10:57 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion_in_record_lit_and_fn_call() {
|
|
|
|
assert_debug_snapshot!(
|
2020-04-16 18:30:08 +02:00
|
|
|
do_ref_completion(
|
2020-04-15 22:10:57 +02:00
|
|
|
r"
|
|
|
|
struct A { another_field: i64, another_good_type: u32, the_field: u32 }
|
|
|
|
struct B { my_string: String, my_vec: Vec<u32>, the_field: u32 }
|
|
|
|
fn test(the_field: i64) -> i64 { the_field }
|
|
|
|
fn foo(a: A) {
|
|
|
|
let b = B {
|
|
|
|
the_field: test(a.<|>)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "another_field",
|
|
|
|
source_range: [336; 336),
|
|
|
|
delete: [336; 336),
|
|
|
|
insert: "another_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "i64",
|
2020-04-16 18:30:08 +02:00
|
|
|
score: TypeMatch,
|
2020-04-15 22:10:57 +02:00
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "another_good_type",
|
|
|
|
source_range: [336; 336),
|
|
|
|
delete: [336; 336),
|
|
|
|
insert: "another_good_type",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [336; 336),
|
|
|
|
delete: [336; 336),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion_in_fn_call_and_record_lit() {
|
|
|
|
assert_debug_snapshot!(
|
2020-04-16 18:30:08 +02:00
|
|
|
do_ref_completion(
|
2020-04-15 22:10:57 +02:00
|
|
|
r"
|
|
|
|
struct A { another_field: i64, another_good_type: u32, the_field: u32 }
|
|
|
|
struct B { my_string: String, my_vec: Vec<u32>, the_field: u32 }
|
|
|
|
fn test(the_field: i64) -> i64 { the_field }
|
|
|
|
fn foo(a: A) {
|
|
|
|
test(B {
|
|
|
|
the_field: a.<|>
|
|
|
|
});
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
2020-04-16 18:30:08 +02:00
|
|
|
label: "another_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
source_range: [328; 328),
|
|
|
|
delete: [328; 328),
|
2020-04-16 18:30:08 +02:00
|
|
|
insert: "another_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
kind: Field,
|
2020-04-16 18:30:08 +02:00
|
|
|
detail: "i64",
|
2020-04-15 22:10:57 +02:00
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "another_good_type",
|
|
|
|
source_range: [328; 328),
|
|
|
|
delete: [328; 328),
|
|
|
|
insert: "another_good_type",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
2020-04-16 18:30:08 +02:00
|
|
|
score: TypeMatch,
|
2020-04-15 22:10:57 +02:00
|
|
|
},
|
|
|
|
CompletionItem {
|
2020-04-16 18:30:08 +02:00
|
|
|
label: "the_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
source_range: [328; 328),
|
|
|
|
delete: [328; 328),
|
2020-04-16 18:30:08 +02:00
|
|
|
insert: "the_field",
|
2020-04-15 22:10:57 +02:00
|
|
|
kind: Field,
|
2020-04-16 18:30:08 +02:00
|
|
|
detail: "u32",
|
|
|
|
score: TypeAndNameMatch,
|
2020-04-15 22:10:57 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-08 22:33:36 +03:00
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion_self() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-01-08 22:33:36 +03:00
|
|
|
r"
|
2019-01-25 14:29:56 -05:00
|
|
|
struct A {
|
|
|
|
/// This is the_field
|
|
|
|
the_field: (u32,)
|
|
|
|
}
|
2019-01-08 22:33:36 +03:00
|
|
|
impl A {
|
|
|
|
fn foo(self) {
|
|
|
|
self.<|>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-10-10 13:03:20 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
2019-10-10 16:37:56 +03:00
|
|
|
label: "foo()",
|
2019-10-10 13:03:20 +03:00
|
|
|
source_range: [187; 187),
|
|
|
|
delete: [187; 187),
|
|
|
|
insert: "foo()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "foo",
|
|
|
|
detail: "fn foo(self)",
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [187; 187),
|
|
|
|
delete: [187; 187),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "(u32,)",
|
|
|
|
documentation: Documentation(
|
|
|
|
"This is the_field",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-01-08 22:33:36 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_struct_field_completion_autoderef() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-01-08 22:33:36 +03:00
|
|
|
r"
|
2019-01-09 18:46:02 +03:00
|
|
|
struct A { the_field: (u32, i32) }
|
2019-01-08 22:33:36 +03:00
|
|
|
impl A {
|
|
|
|
fn foo(&self) {
|
|
|
|
self.<|>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-10-10 13:03:20 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
2019-10-10 16:37:56 +03:00
|
|
|
label: "foo()",
|
2019-10-10 13:03:20 +03:00
|
|
|
source_range: [126; 126),
|
|
|
|
delete: [126; 126),
|
|
|
|
insert: "foo()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "foo",
|
|
|
|
detail: "fn foo(&self)",
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [126; 126),
|
|
|
|
delete: [126; 126),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "(u32, i32)",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-01-08 22:33:36 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_struct_field_completion_for_method_call() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-01-08 22:33:36 +03:00
|
|
|
r"
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>()
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
|
|
|
@"[]"
|
2019-01-08 22:33:36 +03:00
|
|
|
);
|
|
|
|
}
|
2019-01-07 19:12:19 +01:00
|
|
|
|
2019-12-24 21:46:07 +01:00
|
|
|
#[test]
|
|
|
|
fn test_struct_field_visibility_private() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
mod inner {
|
|
|
|
struct A {
|
|
|
|
private_field: u32,
|
|
|
|
pub pub_field: u32,
|
|
|
|
pub(crate) crate_field: u32,
|
|
|
|
pub(super) super_field: u32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn foo(a: inner::A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "crate_field",
|
|
|
|
source_range: [313; 313),
|
|
|
|
delete: [313; 313),
|
|
|
|
insert: "crate_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "pub_field",
|
|
|
|
source_range: [313; 313),
|
|
|
|
delete: [313; 313),
|
|
|
|
insert: "pub_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "super_field",
|
|
|
|
source_range: [313; 313),
|
|
|
|
delete: [313; 313),
|
|
|
|
insert: "super_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:12:19 +01:00
|
|
|
#[test]
|
|
|
|
fn test_method_completion() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-01-07 19:12:19 +01:00
|
|
|
r"
|
|
|
|
struct A {}
|
|
|
|
impl A {
|
|
|
|
fn the_method(&self) {}
|
|
|
|
}
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-10-10 13:03:20 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
2019-10-10 16:37:56 +03:00
|
|
|
label: "the_method()",
|
2019-10-10 13:03:20 +03:00
|
|
|
source_range: [144; 144),
|
|
|
|
delete: [144; 144),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-01-07 19:12:19 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-02 19:27:31 +01:00
|
|
|
#[test]
|
|
|
|
fn test_method_completion_only_fitting_impls() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct A<T> {}
|
|
|
|
impl A<u32> {
|
|
|
|
fn the_method(&self) {}
|
|
|
|
}
|
|
|
|
impl A<i32> {
|
|
|
|
fn the_other_method(&self) {}
|
|
|
|
}
|
|
|
|
fn foo(a: A<u32>) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_method()",
|
|
|
|
source_range: [243; 243),
|
|
|
|
delete: [243; 243),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-07 23:03:56 +01:00
|
|
|
#[test]
|
|
|
|
fn test_method_completion_private() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct A {}
|
|
|
|
mod m {
|
|
|
|
impl super::A {
|
|
|
|
fn private_method(&self) {}
|
|
|
|
pub(super) fn the_method(&self) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_method()",
|
|
|
|
source_range: [256; 256),
|
|
|
|
delete: [256; 256),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "pub(super) fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-14 16:08:10 +02:00
|
|
|
#[test]
|
|
|
|
fn test_trait_method_completion() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-14 16:08:10 +02:00
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct A {}
|
|
|
|
trait Trait { fn the_method(&self); }
|
|
|
|
impl Trait for A {}
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-10-10 13:03:20 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
2019-10-10 16:37:56 +03:00
|
|
|
label: "the_method()",
|
2019-10-10 13:03:20 +03:00
|
|
|
source_range: [151; 151),
|
|
|
|
delete: [151; 151),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-04-14 16:08:10 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-29 12:19:03 +02:00
|
|
|
#[test]
|
|
|
|
fn test_trait_method_completion_deduplicated() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-06-29 12:19:03 +02:00
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct A {}
|
|
|
|
trait Trait { fn the_method(&self); }
|
|
|
|
impl<T> Trait for T {}
|
|
|
|
fn foo(a: &A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
2019-10-10 13:03:20 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
2019-10-10 16:37:56 +03:00
|
|
|
label: "the_method()",
|
2019-10-10 13:03:20 +03:00
|
|
|
source_range: [155; 155),
|
|
|
|
delete: [155; 155),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
2019-06-29 12:19:03 +02:00
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-14 20:48:36 +01:00
|
|
|
#[test]
|
|
|
|
fn completes_trait_method_from_other_module() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct A {}
|
|
|
|
mod m {
|
|
|
|
pub trait Trait { fn the_method(&self); }
|
|
|
|
}
|
|
|
|
use m::Trait;
|
|
|
|
impl Trait for A {}
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_method()",
|
|
|
|
source_range: [219; 219),
|
|
|
|
delete: [219; 219),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:12:19 +01:00
|
|
|
#[test]
|
|
|
|
fn test_no_non_self_method() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-01-07 19:12:19 +01:00
|
|
|
r"
|
|
|
|
struct A {}
|
|
|
|
impl A {
|
|
|
|
fn the_method() {}
|
|
|
|
}
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
|
|
|
@"[]"
|
2019-01-07 19:12:19 +01:00
|
|
|
);
|
|
|
|
}
|
2019-01-24 08:25:35 -05:00
|
|
|
|
2019-02-12 19:58:36 +02:00
|
|
|
#[test]
|
|
|
|
fn test_method_attr_filtering() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-02-12 19:58:36 +02:00
|
|
|
r"
|
|
|
|
struct A {}
|
|
|
|
impl A {
|
|
|
|
#[inline]
|
|
|
|
fn the_method(&self) {
|
|
|
|
let x = 1;
|
|
|
|
let y = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-10-10 13:03:20 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
2019-10-10 16:37:56 +03:00
|
|
|
label: "the_method()",
|
2019-10-10 13:03:20 +03:00
|
|
|
source_range: [249; 249),
|
|
|
|
delete: [249; 249),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-02-12 19:58:36 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-24 08:25:35 -05:00
|
|
|
#[test]
|
|
|
|
fn test_tuple_field_completion() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-01-24 08:25:35 -05:00
|
|
|
r"
|
|
|
|
fn foo() {
|
|
|
|
let b = (0, 3.14);
|
|
|
|
b.<|>
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-11-15 12:56:24 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "0",
|
|
|
|
source_range: [75; 75),
|
|
|
|
delete: [75; 75),
|
|
|
|
insert: "0",
|
|
|
|
kind: Field,
|
|
|
|
detail: "i32",
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "1",
|
|
|
|
source_range: [75; 75),
|
|
|
|
delete: [75; 75),
|
|
|
|
insert: "1",
|
|
|
|
kind: Field,
|
|
|
|
detail: "f64",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-01-24 08:25:35 -05:00
|
|
|
);
|
|
|
|
}
|
2019-04-05 22:59:55 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tuple_field_inference() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-10 13:47:20 +03:00
|
|
|
do_ref_completion(
|
2019-04-05 22:59:55 +02:00
|
|
|
r"
|
|
|
|
pub struct S;
|
|
|
|
impl S {
|
|
|
|
pub fn blah(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct T(S);
|
|
|
|
|
|
|
|
impl T {
|
|
|
|
fn foo(&self) {
|
|
|
|
// FIXME: This doesn't work without the trailing `a` as `0.` is a float
|
|
|
|
self.0.a<|>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
2019-04-10 13:47:20 +03:00
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-10-10 13:03:20 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
2019-10-10 16:37:56 +03:00
|
|
|
label: "blah()",
|
2019-10-10 13:03:20 +03:00
|
|
|
source_range: [299; 300),
|
|
|
|
delete: [299; 300),
|
|
|
|
insert: "blah()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "blah",
|
|
|
|
detail: "pub fn blah(&self)",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-04-11 16:22:10 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_completion_works_in_consts() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-04-11 16:22:10 +03:00
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
const X: u32 = {
|
|
|
|
A { the_field: 92 }.<|>
|
|
|
|
};
|
|
|
|
",
|
|
|
|
),
|
2019-05-24 01:46:23 +03:00
|
|
|
@r###"
|
2019-11-15 12:56:24 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [106; 106),
|
|
|
|
delete: [106; 106),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
2019-05-24 01:46:23 +03:00
|
|
|
"###
|
2019-04-05 22:59:55 +02:00
|
|
|
);
|
|
|
|
}
|
2019-08-03 01:15:43 +07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_completion_await_impls_future() {
|
2019-08-29 16:49:10 +03:00
|
|
|
assert_debug_snapshot!(
|
2019-08-03 02:40:59 +07:00
|
|
|
do_completion(
|
2019-08-03 01:53:51 +07:00
|
|
|
r###"
|
2019-08-03 17:07:20 +07:00
|
|
|
//- /main.rs
|
2019-08-03 01:15:43 +07:00
|
|
|
use std::future::*;
|
|
|
|
struct A {}
|
|
|
|
impl Future for A {}
|
|
|
|
fn foo(a: A) {
|
|
|
|
a.<|>
|
|
|
|
}
|
2019-08-03 17:07:20 +07:00
|
|
|
|
|
|
|
//- /std/lib.rs
|
|
|
|
pub mod future {
|
2020-01-14 11:13:07 +01:00
|
|
|
#[lang = "future_trait"]
|
2019-08-03 17:07:20 +07:00
|
|
|
pub trait Future {}
|
|
|
|
}
|
2019-08-03 02:40:59 +07:00
|
|
|
"###, CompletionKind::Keyword),
|
2019-08-03 01:15:43 +07:00
|
|
|
@r###"
|
2019-11-15 12:56:24 +03:00
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "await",
|
|
|
|
source_range: [74; 74),
|
|
|
|
delete: [74; 74),
|
|
|
|
insert: "await",
|
|
|
|
detail: "expr.await",
|
|
|
|
},
|
|
|
|
]
|
2019-08-03 01:15:43 +07:00
|
|
|
"###
|
|
|
|
)
|
|
|
|
}
|
2020-02-29 20:53:01 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_super_super_completion() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_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: [217; 217),
|
|
|
|
delete: [217; 217),
|
|
|
|
insert: "A",
|
|
|
|
kind: Const,
|
|
|
|
},
|
|
|
|
CompletionItem {
|
|
|
|
label: "b",
|
|
|
|
source_range: [217; 217),
|
|
|
|
delete: [217; 217),
|
|
|
|
insert: "b",
|
|
|
|
kind: Module,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
2020-03-07 15:27:03 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn works_in_simple_macro_1() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
macro_rules! m { ($e:expr) => { $e } }
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
m!(a.x<|>)
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [156; 157),
|
|
|
|
delete: [156; 157),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn works_in_simple_macro_recursive() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
macro_rules! m { ($e:expr) => { $e } }
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
m!(a.x<|>)
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [156; 157),
|
|
|
|
delete: [156; 157),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn works_in_simple_macro_2() {
|
|
|
|
// this doesn't work yet because the macro doesn't expand without the token -- maybe it can be fixed with better recovery
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
macro_rules! m { ($e:expr) => { $e } }
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
m!(a.<|>)
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
2020-03-15 11:17:13 +01:00
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [156; 156),
|
|
|
|
delete: [156; 156),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
2020-03-07 15:27:03 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn works_in_simple_macro_recursive_1() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
macro_rules! m { ($e:expr) => { $e } }
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
m!(m!(m!(a.x<|>)))
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
|
|
|
source_range: [162; 163),
|
|
|
|
delete: [162; 163),
|
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
2020-03-10 20:56:26 +01:00
|
|
|
|
2020-03-13 13:03:31 +01:00
|
|
|
#[test]
|
|
|
|
fn macro_expansion_resilient() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
macro_rules! dbg {
|
|
|
|
() => {};
|
|
|
|
($val:expr) => {
|
|
|
|
match $val { tmp => { tmp } }
|
|
|
|
};
|
|
|
|
// Trailing comma with single argument is ignored
|
|
|
|
($val:expr,) => { $crate::dbg!($val) };
|
|
|
|
($($val:expr),+ $(,)?) => {
|
|
|
|
($($crate::dbg!($val)),+,)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
struct A { the_field: u32 }
|
|
|
|
fn foo(a: A) {
|
|
|
|
dbg!(a.<|>)
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_field",
|
2020-03-14 20:24:18 +01:00
|
|
|
source_range: [552; 552),
|
|
|
|
delete: [552; 552),
|
2020-03-13 13:03:31 +01:00
|
|
|
insert: "the_field",
|
|
|
|
kind: Field,
|
|
|
|
detail: "u32",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-10 20:56:26 +01:00
|
|
|
#[test]
|
|
|
|
fn test_method_completion_3547() {
|
|
|
|
assert_debug_snapshot!(
|
|
|
|
do_ref_completion(
|
|
|
|
r"
|
|
|
|
struct HashSet<T> {}
|
|
|
|
impl<T> HashSet<T> {
|
|
|
|
pub fn the_method(&self) {}
|
|
|
|
}
|
|
|
|
fn foo() {
|
|
|
|
let s: HashSet<_>;
|
|
|
|
s.<|>
|
|
|
|
}
|
|
|
|
",
|
|
|
|
),
|
|
|
|
@r###"
|
|
|
|
[
|
|
|
|
CompletionItem {
|
|
|
|
label: "the_method()",
|
|
|
|
source_range: [201; 201),
|
|
|
|
delete: [201; 201),
|
|
|
|
insert: "the_method()$0",
|
|
|
|
kind: Method,
|
|
|
|
lookup: "the_method",
|
|
|
|
detail: "pub fn the_method(&self)",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
"###
|
|
|
|
);
|
|
|
|
}
|
2019-01-08 22:33:36 +03:00
|
|
|
}
|