From b043358be936b7f139efd49b7d187d64e319830e Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 8 Oct 2019 07:25:37 -0400 Subject: [PATCH] Address comments: fix docs, add completion test for `Self`. --- crates/ra_hir/src/code_model.rs | 2 +- crates/ra_hir/src/resolve.rs | 2 +- crates/ra_hir/src/ty/infer.rs | 4 +-- .../src/completion/complete_scope.rs | 29 +++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index cd501d1f694..58db6832d1a 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -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())) } } diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index c46f7e157cf..3c797c0c3a8 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -45,7 +45,7 @@ pub(crate) enum Scope { GenericParams(Arc), /// 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), diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 9e5d42509c3..a69f04ff151 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -559,9 +559,7 @@ fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option) { 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(), diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 515a6285c10..38a6c3d37b6 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -309,6 +309,35 @@ struct X { ); } + #[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!(