From 27cadcd531c017aa7c78c6f7a36f2b7f2ce8a196 Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 13:05:28 +1100 Subject: HasSource::source -> HasSource::source_old To start migrating HasSource::source to return an Option. --- crates/ide_db/src/search.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index ff10f71c3..2df4894a1 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -121,9 +121,9 @@ impl Definition { if let Definition::Local(var) = self { let range = match var.parent(db) { - DefWithBody::Function(f) => f.source(db).value.syntax().text_range(), - DefWithBody::Const(c) => c.source(db).value.syntax().text_range(), - DefWithBody::Static(s) => s.source(db).value.syntax().text_range(), + DefWithBody::Function(f) => f.source_old(db).value.syntax().text_range(), + DefWithBody::Const(c) => c.source_old(db).value.syntax().text_range(), + DefWithBody::Static(s) => s.source_old(db).value.syntax().text_range(), }; let mut res = FxHashMap::default(); res.insert(file_id, Some(range)); @@ -132,17 +132,17 @@ impl Definition { if let Definition::LifetimeParam(param) = self { let range = match param.parent(db) { - hir::GenericDef::Function(it) => it.source(db).value.syntax().text_range(), + hir::GenericDef::Function(it) => it.source_old(db).value.syntax().text_range(), hir::GenericDef::Adt(it) => match it { - hir::Adt::Struct(it) => it.source(db).value.syntax().text_range(), - hir::Adt::Union(it) => it.source(db).value.syntax().text_range(), - hir::Adt::Enum(it) => it.source(db).value.syntax().text_range(), + hir::Adt::Struct(it) => it.source_old(db).value.syntax().text_range(), + hir::Adt::Union(it) => it.source_old(db).value.syntax().text_range(), + hir::Adt::Enum(it) => it.source_old(db).value.syntax().text_range(), }, - hir::GenericDef::Trait(it) => it.source(db).value.syntax().text_range(), - hir::GenericDef::TypeAlias(it) => it.source(db).value.syntax().text_range(), - hir::GenericDef::Impl(it) => it.source(db).value.syntax().text_range(), - hir::GenericDef::Variant(it) => it.source(db).value.syntax().text_range(), - hir::GenericDef::Const(it) => it.source(db).value.syntax().text_range(), + hir::GenericDef::Trait(it) => it.source_old(db).value.syntax().text_range(), + hir::GenericDef::TypeAlias(it) => it.source_old(db).value.syntax().text_range(), + hir::GenericDef::Impl(it) => it.source_old(db).value.syntax().text_range(), + hir::GenericDef::Variant(it) => it.source_old(db).value.syntax().text_range(), + hir::GenericDef::Const(it) => it.source_old(db).value.syntax().text_range(), }; let mut res = FxHashMap::default(); res.insert(file_id, Some(range)); -- cgit v1.2.3 From ea4708c444509449b86c50b7b1b23f9ff5af4e97 Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 13:50:50 +1100 Subject: Mark HasSource::source_old as deprecated but allow at all call sites --- crates/ide_db/src/search.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 2df4894a1..e69f9d141 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -120,6 +120,7 @@ impl Definition { let file_id = module_src.file_id.original_file(db); if let Definition::Local(var) = self { + #[allow(deprecated)] let range = match var.parent(db) { DefWithBody::Function(f) => f.source_old(db).value.syntax().text_range(), DefWithBody::Const(c) => c.source_old(db).value.syntax().text_range(), @@ -131,6 +132,7 @@ impl Definition { } if let Definition::LifetimeParam(param) = self { + #[allow(deprecated)] let range = match param.parent(db) { hir::GenericDef::Function(it) => it.source_old(db).value.syntax().text_range(), hir::GenericDef::Adt(it) => match it { -- cgit v1.2.3 From 68b4efd53601fd67fbba4a2aa25ac94ecff58e5e Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 15:33:06 +1100 Subject: Handle not finding range in Definition::search_scope The `LifetimeParam` and `Local` variants use `source()` to find their range. Now that `source()` returns an `Option` we need to handle the `None` case. --- crates/ide_db/src/search.rs | 48 +++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index e69f9d141..c4aff3932 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -122,9 +122,15 @@ impl Definition { if let Definition::Local(var) = self { #[allow(deprecated)] let range = match var.parent(db) { - DefWithBody::Function(f) => f.source_old(db).value.syntax().text_range(), - DefWithBody::Const(c) => c.source_old(db).value.syntax().text_range(), - DefWithBody::Static(s) => s.source_old(db).value.syntax().text_range(), + DefWithBody::Function(f) => { + f.source(db).and_then(|src| src.value.syntax().text_range()) + } + DefWithBody::Const(c) => { + c.source(db).and_then(|src| src.value.syntax().text_range()) + } + DefWithBody::Static(s) => { + s.source(db).and_then(|src| src.value.syntax().text_range()) + } }; let mut res = FxHashMap::default(); res.insert(file_id, Some(range)); @@ -134,17 +140,35 @@ impl Definition { if let Definition::LifetimeParam(param) = self { #[allow(deprecated)] let range = match param.parent(db) { - hir::GenericDef::Function(it) => it.source_old(db).value.syntax().text_range(), + hir::GenericDef::Function(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } hir::GenericDef::Adt(it) => match it { - hir::Adt::Struct(it) => it.source_old(db).value.syntax().text_range(), - hir::Adt::Union(it) => it.source_old(db).value.syntax().text_range(), - hir::Adt::Enum(it) => it.source_old(db).value.syntax().text_range(), + hir::Adt::Struct(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } + hir::Adt::Union(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } + hir::Adt::Enum(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } }, - hir::GenericDef::Trait(it) => it.source_old(db).value.syntax().text_range(), - hir::GenericDef::TypeAlias(it) => it.source_old(db).value.syntax().text_range(), - hir::GenericDef::Impl(it) => it.source_old(db).value.syntax().text_range(), - hir::GenericDef::Variant(it) => it.source_old(db).value.syntax().text_range(), - hir::GenericDef::Const(it) => it.source_old(db).value.syntax().text_range(), + hir::GenericDef::Trait(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } + hir::GenericDef::TypeAlias(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } + hir::GenericDef::Impl(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } + hir::GenericDef::Variant(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } + hir::GenericDef::Const(it) => { + it.source(db).and_then(|src| src.value.syntax().text_range()) + } }; let mut res = FxHashMap::default(); res.insert(file_id, Some(range)); -- cgit v1.2.3 From 71c9a884d1d9b27bf9da8ce7d328d74349db54a2 Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 15:41:04 +1100 Subject: Fix type error with .and_then --- crates/ide_db/src/search.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index c4aff3932..436c59d2c 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -120,20 +120,19 @@ impl Definition { let file_id = module_src.file_id.original_file(db); if let Definition::Local(var) = self { - #[allow(deprecated)] let range = match var.parent(db) { DefWithBody::Function(f) => { - f.source(db).and_then(|src| src.value.syntax().text_range()) + f.source(db).and_then(|src| Some(src.value.syntax().text_range())) } DefWithBody::Const(c) => { - c.source(db).and_then(|src| src.value.syntax().text_range()) + c.source(db).and_then(|src| Some(src.value.syntax().text_range())) } DefWithBody::Static(s) => { - s.source(db).and_then(|src| src.value.syntax().text_range()) + s.source(db).and_then(|src| Some(src.value.syntax().text_range())) } }; let mut res = FxHashMap::default(); - res.insert(file_id, Some(range)); + res.insert(file_id, range); return SearchScope::new(res); } @@ -141,37 +140,37 @@ impl Definition { #[allow(deprecated)] let range = match param.parent(db) { hir::GenericDef::Function(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } hir::GenericDef::Adt(it) => match it { hir::Adt::Struct(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } hir::Adt::Union(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } hir::Adt::Enum(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } }, hir::GenericDef::Trait(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } hir::GenericDef::TypeAlias(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } hir::GenericDef::Impl(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } hir::GenericDef::Variant(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } hir::GenericDef::Const(it) => { - it.source(db).and_then(|src| src.value.syntax().text_range()) + it.source(db).and_then(|src| Some(src.value.syntax().text_range())) } }; let mut res = FxHashMap::default(); - res.insert(file_id, Some(range)); + res.insert(file_id, range); return SearchScope::new(res); } -- cgit v1.2.3