Address comments: fix docs, add completion test for Self.

This commit is contained in:
ice1000 2019-10-08 07:25:37 -04:00
parent 6bad638928
commit b043358be9
4 changed files with 32 additions and 5 deletions

View File

@ -465,7 +465,7 @@ pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
// ...and add generic params, if present
let p = self.generic_params(db);
let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
r.push_scope(Scope::AdtScope(From::from(self)))
r.push_scope(Scope::AdtScope(self.into()))
}
}

View File

@ -45,7 +45,7 @@ pub(crate) enum Scope {
GenericParams(Arc<GenericParams>),
/// Brings `Self` in `impl` block into scope
ImplBlockScope(ImplBlock),
/// Brings `Self` in enum definition into scope
/// Brings `Self` in enum, struct and union definitions into scope
AdtScope(Adt),
/// Local bindings
ExprScope(ExprScope),

View File

@ -559,9 +559,7 @@ fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option<VariantDef>) {
match resolver.resolve_path_in_type_ns_fully(self.db, &path) {
Some(TypeNs::Adt(Adt::Struct(it))) => it.into(),
Some(TypeNs::Adt(Adt::Union(it))) => it.into(),
Some(TypeNs::AdtSelfType(Adt::Struct(it))) => it.into(),
Some(TypeNs::AdtSelfType(Adt::Union(it))) => it.into(),
Some(TypeNs::AdtSelfType(Adt::Enum(it))) => it.into(),
Some(TypeNs::AdtSelfType(adt)) => adt.into(),
Some(TypeNs::EnumVariant(it)) => it.into(),
Some(TypeNs::TypeAlias(it)) => it.into(),

View File

@ -309,6 +309,35 @@ struct X<T> {
);
}
#[test]
fn completes_self_in_enum() {
assert_debug_snapshot!(
do_reference_completion(
r"
enum X {
Y(<|>)
}
"
),
@r###"[
CompletionItem {
label: "Self",
source_range: [48; 48),
delete: [48; 48),
insert: "Self",
kind: TypeParam,
},
CompletionItem {
label: "X",
source_range: [48; 48),
delete: [48; 48),
insert: "X",
kind: Enum,
},
]"###
);
}
#[test]
fn completes_module_items() {
assert_debug_snapshot!(