diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 1fb6570b6a4..6aa053b5ac6 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -223,12 +223,12 @@ pub fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option self.imp.resolve_variant(record_lit).map(VariantDef::from) } - pub fn to_module_def(&self, file: FileId) -> Option { - self.imp.to_module_def(file).next() + pub fn file_to_module_def(&self, file: FileId) -> Option { + self.imp.file_to_module_defs(file).next() } - pub fn to_module_defs(&self, file: FileId) -> impl Iterator { - self.imp.to_module_def(file) + pub fn file_to_module_defs(&self, file: FileId) -> impl Iterator { + self.imp.file_to_module_defs(file) } pub fn to_struct_def(&self, s: &ast::Struct) -> Option { @@ -1237,7 +1237,7 @@ pub fn to_def(&self, src: &T) -> Option { T::to_def(self, src) } - fn to_module_def(&self, file: FileId) -> impl Iterator { + fn file_to_module_defs(&self, file: FileId) -> impl Iterator { self.with_ctx(|ctx| ctx.file_to_def(file)).into_iter().map(Module::from) } diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index ef4ed90ce35..4733ea5a35b 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -118,7 +118,7 @@ pub(super) struct SourceToDefCtx<'a, 'b> { impl SourceToDefCtx<'_, '_> { pub(super) fn file_to_def(&self, file: FileId) -> SmallVec<[ModuleId; 1]> { - let _p = tracing::span!(tracing::Level::INFO, "SourceBinder::to_module_def"); + let _p = tracing::span!(tracing::Level::INFO, "SourceBinder::file_to_module_def"); let mut mods = SmallVec::new(); for &crate_id in self.db.relevant_crates(file).iter() { // FIXME: inner items diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 7a60287f923..e0bcd78c99b 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -116,7 +116,7 @@ pub(crate) fn new( ) -> Option { let db = ctx.sema.db; - let module = ctx.sema.to_module_def(ctx.file_id())?; + let module = ctx.sema.file_to_module_def(ctx.file_id())?; let (name, range, ty) = match f { Either::Left(f) => { diff --git a/crates/ide-assists/src/handlers/move_from_mod_rs.rs b/crates/ide-assists/src/handlers/move_from_mod_rs.rs index 917d0b3671e..a256f60c421 100644 --- a/crates/ide-assists/src/handlers/move_from_mod_rs.rs +++ b/crates/ide-assists/src/handlers/move_from_mod_rs.rs @@ -25,7 +25,7 @@ // ``` pub(crate) fn move_from_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let source_file = ctx.find_node_at_offset::()?; - let module = ctx.sema.to_module_def(ctx.file_id())?; + let module = ctx.sema.file_to_module_def(ctx.file_id())?; // Enable this assist if the user select all "meaningful" content in the source file let trimmed_selected_range = trimmed_text_range(&source_file, ctx.selection_trimmed()); let trimmed_file_range = trimmed_text_range(&source_file, source_file.syntax().text_range()); diff --git a/crates/ide-assists/src/handlers/move_to_mod_rs.rs b/crates/ide-assists/src/handlers/move_to_mod_rs.rs index b73270cd05f..a8a124eebb6 100644 --- a/crates/ide-assists/src/handlers/move_to_mod_rs.rs +++ b/crates/ide-assists/src/handlers/move_to_mod_rs.rs @@ -25,7 +25,7 @@ // ``` pub(crate) fn move_to_mod_rs(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { let source_file = ctx.find_node_at_offset::()?; - let module = ctx.sema.to_module_def(ctx.file_id())?; + let module = ctx.sema.file_to_module_def(ctx.file_id())?; // Enable this assist if the user select all "meaningful" content in the source file let trimmed_selected_range = trimmed_text_range(&source_file, ctx.selection_trimmed()); let trimmed_file_range = trimmed_text_range(&source_file, source_file.syntax().text_range()); diff --git a/crates/ide-db/src/helpers.rs b/crates/ide-db/src/helpers.rs index 0b5ad7060e0..4ac8a7c4c4a 100644 --- a/crates/ide-db/src/helpers.rs +++ b/crates/ide-db/src/helpers.rs @@ -64,7 +64,7 @@ pub fn visit_file_defs( cb: &mut dyn FnMut(Definition), ) { let db = sema.db; - let module = match sema.to_module_def(file_id) { + let module = match sema.file_to_module_def(file_id) { Some(it) => it, None => return, }; diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs index 09daefd084d..f92ba576d3a 100644 --- a/crates/ide-diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs @@ -200,7 +200,7 @@ fn get_default_constructor( } } - let krate = ctx.sema.to_module_def(d.file.original_file(ctx.sema.db))?.krate(); + let krate = ctx.sema.file_to_module_def(d.file.original_file(ctx.sema.db))?.krate(); let module = krate.root_module(); // Look for a ::new() associated function diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs index 9f4368b04e7..6c72dbb5edf 100644 --- a/crates/ide-diagnostics/src/lib.rs +++ b/crates/ide-diagnostics/src/lib.rs @@ -315,7 +315,7 @@ pub fn diagnostics( handlers::json_is_not_rust::json_in_items(&sema, &mut res, file_id, &node, config); } - let module = sema.to_module_def(file_id); + let module = sema.file_to_module_def(file_id); let ctx = DiagnosticsContext { config, sema, resolve }; if module.is_none() { diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index f67aea2d5b9..ce7a6779e27 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -48,7 +48,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec sema - .to_module_defs(position.file_id) + .file_to_module_defs(position.file_id) .flat_map(|module| NavigationTarget::from_module_to_decl(db, module)) .collect(), } diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs index f78153df38b..8c2ae327c7f 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -156,7 +156,7 @@ pub(crate) fn will_rename_file( new_name_stem: &str, ) -> Option { let sema = Semantics::new(db); - let module = sema.to_module_def(file_id)?; + let module = sema.file_to_module_def(file_id)?; let def = Definition::Module(module); let mut change = if is_raw_identifier(new_name_stem) { def.rename(&sema, &SmolStr::from_iter(["r#", new_name_stem])).ok()? diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index ae107a96040..5fe46444ff4 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -178,7 +178,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec { } }); - sema.to_module_defs(file_id) + sema.file_to_module_defs(file_id) .map(|it| runnable_mod_outline_definition(&sema, it)) .for_each(|it| add_opt(it, None)); diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index dfcbaf54d4f..d2bd3bab14e 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -223,7 +223,7 @@ fn traverse( krate: hir::Crate, range_to_highlight: TextRange, ) { - let is_unlinked = sema.to_module_def(file_id).is_none(); + let is_unlinked = sema.file_to_module_def(file_id).is_none(); let mut bindings_shadow_count: FxHashMap = FxHashMap::default(); enum AttrOrDerive {