aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db/src/defs.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-28 15:56:07 +0000
committerGitHub <[email protected]>2020-02-28 15:56:07 +0000
commitc692e07b4ff648fea742c53c0dbad57d6f652068 (patch)
treed186df8fb298272eaa4ce14d2fccc854413bc566 /crates/ra_ide_db/src/defs.rs
parent93f632ca4e7bb7fd54830e456d629a4948a92337 (diff)
parent56ce34c6a7ec0b4426d4cb25e10512c7efaf6f06 (diff)
Merge #3367
3367: Fix highlighting of const patterns r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_db/src/defs.rs')
-rw-r--r--crates/ra_ide_db/src/defs.rs33
1 files changed, 32 insertions, 1 deletions
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index 484755158..93f32ba85 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -68,7 +68,38 @@ impl NameDefinition {
68 } 68 }
69} 69}
70 70
71pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<NameDefinition> { 71pub enum NameClass {
72 NameDefinition(NameDefinition),
73 /// `None` in `if let None = Some(82) {}`
74 ConstReference(NameDefinition),
75}
76
77impl NameClass {
78 pub fn into_definition(self) -> Option<NameDefinition> {
79 match self {
80 NameClass::NameDefinition(it) => Some(it),
81 NameClass::ConstReference(_) => None,
82 }
83 }
84
85 pub fn definition(self) -> NameDefinition {
86 match self {
87 NameClass::NameDefinition(it) | NameClass::ConstReference(it) => it,
88 }
89 }
90}
91
92pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<NameClass> {
93 if let Some(bind_pat) = name.syntax().parent().and_then(ast::BindPat::cast) {
94 if let Some(def) = sema.resolve_bind_pat_to_const(&bind_pat) {
95 return Some(NameClass::ConstReference(NameDefinition::ModuleDef(def)));
96 }
97 }
98
99 classify_name_inner(sema, name).map(NameClass::NameDefinition)
100}
101
102fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<NameDefinition> {
72 let _p = profile("classify_name"); 103 let _p = profile("classify_name");
73 let parent = name.syntax().parent()?; 104 let parent = name.syntax().parent()?;
74 105