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.
This commit is contained in:
parent
c936e4b86f
commit
68b4efd536
1 changed files with 36 additions and 12 deletions
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue