From 209eb32796c6fd56d1b378690c807cf73ce54235 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Feb 2020 15:27:52 +0100 Subject: Classify name takes const patterns into account --- crates/ra_ide_db/src/defs.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_db/src/defs.rs') diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 484755158..3079d1197 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -68,7 +68,32 @@ impl NameDefinition { } } -pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option { +pub enum NameClass { + NameDefinition(NameDefinition), + /// `None` in `if let None = Some(82) {}` + ConstReference(NameDefinition), +} + +impl NameClass { + pub fn into_definition(self) -> Option { + match self { + NameClass::NameDefinition(it) => Some(it), + NameClass::ConstReference(_) => None, + } + } + + pub fn definition(self) -> NameDefinition { + match self { + NameClass::NameDefinition(it) | NameClass::ConstReference(it) => it, + } + } +} + +pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option { + classify_name_inner(sema, name).map(NameClass::NameDefinition) +} + +fn classify_name_inner(sema: &Semantics, name: &ast::Name) -> Option { let _p = profile("classify_name"); let parent = name.syntax().parent()?; -- cgit v1.2.3 From 5ebfcb9cb757ece936f631cf69136e1d38cb6afc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Feb 2020 16:36:14 +0100 Subject: Fix highlighting of const patterns --- crates/ra_ide_db/src/defs.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/ra_ide_db/src/defs.rs') diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 3079d1197..93f32ba85 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -90,6 +90,12 @@ impl NameClass { } pub fn classify_name(sema: &Semantics, name: &ast::Name) -> Option { + if let Some(bind_pat) = name.syntax().parent().and_then(ast::BindPat::cast) { + if let Some(def) = sema.resolve_bind_pat_to_const(&bind_pat) { + return Some(NameClass::ConstReference(NameDefinition::ModuleDef(def))); + } + } + classify_name_inner(sema, name).map(NameClass::NameDefinition) } -- cgit v1.2.3