mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
Resolve invisible defs in fix_visibility
assist
This commit is contained in:
parent
dea49d0826
commit
e75afebeb2
2 changed files with 14 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
|||
use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution};
|
||||
use hir::{db::HirDatabase, HasSource, HasVisibility, ModuleDef, PathResolution, ScopeDef};
|
||||
use ide_db::base_db::FileId;
|
||||
use syntax::{
|
||||
ast::{self, HasVisibility as _},
|
||||
|
@ -18,7 +18,7 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
|
|||
// fn frobnicate() {}
|
||||
// }
|
||||
// fn main() {
|
||||
// m::frobnicate$0() {}
|
||||
// m::frobnicate$0();
|
||||
// }
|
||||
// ```
|
||||
// ->
|
||||
|
@ -27,7 +27,7 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
|
|||
// $0pub(crate) fn frobnicate() {}
|
||||
// }
|
||||
// fn main() {
|
||||
// m::frobnicate() {}
|
||||
// m::frobnicate();
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn fix_visibility(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||
|
@ -37,11 +37,15 @@ pub(crate) fn fix_visibility(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
|
|||
|
||||
fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||
let path: ast::Path = ctx.find_node_at_offset()?;
|
||||
let path_res = ctx.sema.resolve_path(&path)?;
|
||||
let def = match path_res {
|
||||
PathResolution::Def(def) => def,
|
||||
_ => return None,
|
||||
};
|
||||
let qualifier = path.qualifier()?;
|
||||
let name_ref = path.segment()?.name_ref()?;
|
||||
let qualifier_res = ctx.sema.resolve_path(&qualifier)?;
|
||||
let PathResolution::Def(ModuleDef::Module(module)) = qualifier_res else { return None; };
|
||||
let (_, def) = module
|
||||
.scope(ctx.db(), None)
|
||||
.into_iter()
|
||||
.find(|(name, _)| name.to_smol_str() == name_ref.text().as_str())?;
|
||||
let ScopeDef::ModuleDef(def) = def else { return None; };
|
||||
|
||||
let current_module = ctx.sema.scope(path.syntax())?.module();
|
||||
let target_module = def.module(ctx.db())?;
|
||||
|
|
|
@ -741,7 +741,7 @@ mod m {
|
|||
fn frobnicate() {}
|
||||
}
|
||||
fn main() {
|
||||
m::frobnicate$0() {}
|
||||
m::frobnicate$0();
|
||||
}
|
||||
"#####,
|
||||
r#####"
|
||||
|
@ -749,7 +749,7 @@ mod m {
|
|||
$0pub(crate) fn frobnicate() {}
|
||||
}
|
||||
fn main() {
|
||||
m::frobnicate() {}
|
||||
m::frobnicate();
|
||||
}
|
||||
"#####,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue