Add prefix file_ to Semantics's to_module_defs()/to_module_def() methods

This commit is contained in:
Vincent Esche 2024-02-28 10:13:31 +01:00
parent 0ac05c0527
commit 6112ddfabb
12 changed files with 16 additions and 16 deletions

View File

@ -223,12 +223,12 @@ pub fn resolve_variant(&self, record_lit: ast::RecordExpr) -> Option<VariantDef>
self.imp.resolve_variant(record_lit).map(VariantDef::from)
}
pub fn to_module_def(&self, file: FileId) -> Option<Module> {
self.imp.to_module_def(file).next()
pub fn file_to_module_def(&self, file: FileId) -> Option<Module> {
self.imp.file_to_module_defs(file).next()
}
pub fn to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module> {
self.imp.to_module_def(file)
pub fn file_to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module> {
self.imp.file_to_module_defs(file)
}
pub fn to_struct_def(&self, s: &ast::Struct) -> Option<Struct> {
@ -1237,7 +1237,7 @@ pub fn to_def<T: ToDef>(&self, src: &T) -> Option<T::Def> {
T::to_def(self, src)
}
fn to_module_def(&self, file: FileId) -> impl Iterator<Item = Module> {
fn file_to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module> {
self.with_ctx(|ctx| ctx.file_to_def(file)).into_iter().map(Module::from)
}

View File

@ -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

View File

@ -116,7 +116,7 @@ pub(crate) fn new(
) -> Option<Field> {
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) => {

View File

@ -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::<ast::SourceFile>()?;
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());

View File

@ -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::<ast::SourceFile>()?;
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());

View File

@ -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,
};

View File

@ -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

View File

@ -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() {

View File

@ -48,7 +48,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
.flat_map(|module| NavigationTarget::from_module_to_decl(db, module))
.collect(),
None => 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(),
}

View File

@ -156,7 +156,7 @@ pub(crate) fn will_rename_file(
new_name_stem: &str,
) -> Option<SourceChange> {
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()?

View File

@ -178,7 +178,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
}
});
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));

View File

@ -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<Name, u32> = FxHashMap::default();
enum AttrOrDerive {