Skip to content

Commit

Permalink
Addressed MR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
obsgolem committed May 30, 2023
1 parent 5895fcb commit 35883a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions crates/ide-assists/src/handlers/remove_unused_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
.filter_map(|u| {
// Find any uses trees that are unused

let module = ctx.sema.scope(&u.syntax()).map(|s| s.module())?;
let scope = match search_scopes.entry(module) {
let use_module = ctx.sema.scope(&u.syntax()).map(|s| s.module())?;
let scope = match search_scopes.entry(use_module) {
Entry::Occupied(o) => o.into_mut(),
Entry::Vacant(v) => v.insert(SearchScope::module_and_children(ctx.db(), module)),
Entry::Vacant(v) => {
v.insert(SearchScope::module_and_children(ctx.db(), use_module))
}
};

// Gets the path associated with this use tree. If there isn't one, then ignore this use tree.
Expand Down Expand Up @@ -86,15 +88,13 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)

if u.star_token().is_some() {
// Check if any of the children of this module are used
let module = match def {
let def_mod = match def {
Definition::Module(module) => module,
_ => return None,
};

let modscope = ctx.sema.scope(u.syntax())?.module();

if !module
.scope(ctx.db(), Some(modscope))
if !def_mod
.scope(ctx.db(), Some(use_module))
.iter()
.filter_map(|(_, x)| match x {
hir::ScopeDef::ModuleDef(d) => Some(Definition::from(*d)),
Expand Down
14 changes: 7 additions & 7 deletions crates/ide-db/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl Definition {
}
}

pub fn usages<'a, 'b>(self, sema: &'a Semantics<'_, RootDatabase>) -> FindUsages<'a, 'b> {
pub fn usages<'a>(self, sema: &'a Semantics<'_, RootDatabase>) -> FindUsages<'a> {
FindUsages {
def: self,
assoc_item_container: self.as_assoc_item(sema.db).map(|a| a.container(sema.db)),
Expand All @@ -326,10 +326,10 @@ impl Definition {
}

#[derive(Clone)]
pub struct FindUsages<'a, 'b> {
pub struct FindUsages<'a> {
def: Definition,
sema: &'a Semantics<'a, RootDatabase>,
scope: Option<&'b SearchScope>,
scope: Option<&'a SearchScope>,
/// The container of our definition should it be an assoc item
assoc_item_container: Option<hir::AssocItemContainer>,
/// whether to search for the `Self` type of the definition
Expand All @@ -338,21 +338,21 @@ pub struct FindUsages<'a, 'b> {
search_self_mod: bool,
}

impl<'a, 'b> FindUsages<'a, 'b> {
impl<'a> FindUsages<'a> {
/// Enable searching for `Self` when the definition is a type or `self` for modules.
pub fn include_self_refs(mut self) -> FindUsages<'a, 'b> {
pub fn include_self_refs(mut self) -> FindUsages<'a> {
self.include_self_kw_refs = def_to_ty(self.sema, &self.def);
self.search_self_mod = true;
self
}

/// Limit the search to a given [`SearchScope`].
pub fn in_scope(self, scope: &'b SearchScope) -> FindUsages<'a, 'b> {
pub fn in_scope(self, scope: &'a SearchScope) -> FindUsages<'a> {
self.set_scope(Some(scope))
}

/// Limit the search to a given [`SearchScope`].
pub fn set_scope(mut self, scope: Option<&'b SearchScope>) -> FindUsages<'a, 'b> {
pub fn set_scope(mut self, scope: Option<&'a SearchScope>) -> FindUsages<'a> {
assert!(self.scope.is_none());
self.scope = scope;
self
Expand Down

0 comments on commit 35883a2

Please sign in to comment.