mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Address comments: fix docs, add completion test for Self
.
This commit is contained in:
parent
6bad638928
commit
b043358be9
4 changed files with 32 additions and 5 deletions
|
@ -465,7 +465,7 @@ impl Enum {
|
||||||
// ...and add generic params, if present
|
// ...and add generic params, if present
|
||||||
let p = self.generic_params(db);
|
let p = self.generic_params(db);
|
||||||
let r = if !p.params.is_empty() { r.push_generic_params_scope(p) } else { r };
|
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()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub(crate) enum Scope {
|
||||||
GenericParams(Arc<GenericParams>),
|
GenericParams(Arc<GenericParams>),
|
||||||
/// Brings `Self` in `impl` block into scope
|
/// Brings `Self` in `impl` block into scope
|
||||||
ImplBlockScope(ImplBlock),
|
ImplBlockScope(ImplBlock),
|
||||||
/// Brings `Self` in enum definition into scope
|
/// Brings `Self` in enum, struct and union definitions into scope
|
||||||
AdtScope(Adt),
|
AdtScope(Adt),
|
||||||
/// Local bindings
|
/// Local bindings
|
||||||
ExprScope(ExprScope),
|
ExprScope(ExprScope),
|
||||||
|
|
|
@ -559,9 +559,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
match resolver.resolve_path_in_type_ns_fully(self.db, &path) {
|
match resolver.resolve_path_in_type_ns_fully(self.db, &path) {
|
||||||
Some(TypeNs::Adt(Adt::Struct(it))) => it.into(),
|
Some(TypeNs::Adt(Adt::Struct(it))) => it.into(),
|
||||||
Some(TypeNs::Adt(Adt::Union(it))) => it.into(),
|
Some(TypeNs::Adt(Adt::Union(it))) => it.into(),
|
||||||
Some(TypeNs::AdtSelfType(Adt::Struct(it))) => it.into(),
|
Some(TypeNs::AdtSelfType(adt)) => adt.into(),
|
||||||
Some(TypeNs::AdtSelfType(Adt::Union(it))) => it.into(),
|
|
||||||
Some(TypeNs::AdtSelfType(Adt::Enum(it))) => it.into(),
|
|
||||||
Some(TypeNs::EnumVariant(it)) => it.into(),
|
Some(TypeNs::EnumVariant(it)) => it.into(),
|
||||||
Some(TypeNs::TypeAlias(it)) => it.into(),
|
Some(TypeNs::TypeAlias(it)) => it.into(),
|
||||||
|
|
||||||
|
|
|
@ -309,6 +309,35 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[test]
|
||||||
fn completes_module_items() {
|
fn completes_module_items() {
|
||||||
assert_debug_snapshot!(
|
assert_debug_snapshot!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue