mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
fix module attr path
This commit is contained in:
parent
b19da133ee
commit
6a4cf48bff
3 changed files with 40 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
use ra_db::FileId;
|
||||
use ra_syntax::ast;
|
||||
use ra_syntax::{ast, SmolStr};
|
||||
use rustc_hash::FxHashMap;
|
||||
use test_utils::tested_by;
|
||||
|
||||
|
@ -98,6 +98,7 @@ where
|
|||
self.def_map.modules[module_id].definition = Some(file_id);
|
||||
ModCollector {
|
||||
def_collector: &mut *self,
|
||||
attr_path: None,
|
||||
module_id,
|
||||
file_id: file_id.into(),
|
||||
raw_items: &raw_items,
|
||||
|
@ -474,6 +475,7 @@ where
|
|||
ModCollector {
|
||||
def_collector: &mut *self,
|
||||
file_id,
|
||||
attr_path: None,
|
||||
module_id,
|
||||
raw_items: &raw_items,
|
||||
parent_module: None,
|
||||
|
@ -497,6 +499,7 @@ struct ModCollector<'a, D> {
|
|||
def_collector: D,
|
||||
module_id: CrateModuleId,
|
||||
file_id: HirFileId,
|
||||
attr_path: Option<&'a SmolStr>,
|
||||
raw_items: &'a raw::RawItems,
|
||||
parent_module: Option<ParentModule<'a>>,
|
||||
}
|
||||
|
@ -551,6 +554,7 @@ where
|
|||
ModCollector {
|
||||
def_collector: &mut *self.def_collector,
|
||||
module_id,
|
||||
attr_path: attr_path.as_ref(),
|
||||
file_id: self.file_id,
|
||||
raw_items: self.raw_items,
|
||||
parent_module: Some(parent_module),
|
||||
|
@ -567,6 +571,7 @@ where
|
|||
match resolve_submodule(
|
||||
self.def_collector.db,
|
||||
self.file_id,
|
||||
self.attr_path,
|
||||
name,
|
||||
is_root,
|
||||
attr_path.as_ref(),
|
||||
|
@ -578,6 +583,7 @@ where
|
|||
ModCollector {
|
||||
def_collector: &mut *self.def_collector,
|
||||
module_id,
|
||||
attr_path: attr_path.as_ref(),
|
||||
file_id: file_id.into(),
|
||||
raw_items: &raw_items,
|
||||
parent_module: None,
|
||||
|
|
|
@ -23,6 +23,7 @@ impl<'a> ParentModule<'a> {
|
|||
pub(super) fn resolve_submodule(
|
||||
db: &impl DefDatabase,
|
||||
file_id: HirFileId,
|
||||
mod_attr_path: Option<&SmolStr>,
|
||||
name: &Name,
|
||||
is_root: bool,
|
||||
attr_path: Option<&SmolStr>,
|
||||
|
@ -80,7 +81,7 @@ pub(super) fn resolve_submodule(
|
|||
ResolutionMode::OutOfLine(OutOfLineMode::WithAttributePath(path))
|
||||
}
|
||||
(None, None) => {
|
||||
let is_dir_owner = is_root || mod_name == "mod";
|
||||
let is_dir_owner = is_root || mod_name == "mod" || mod_attr_path.is_some();
|
||||
if is_dir_owner {
|
||||
let file_mod = dir_path.join(format!("{}.rs", name));
|
||||
let dir_mod = dir_path.join(format!("{}/mod.rs", name));
|
||||
|
|
|
@ -706,3 +706,34 @@ fn unresolved_module_diagnostics() {
|
|||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_resolution_decl_inside_module_in_non_crate_root_2() {
|
||||
let map = def_map_with_crate_graph(
|
||||
r###"
|
||||
//- /main.rs
|
||||
#[path="module/m2.rs"]
|
||||
mod module;
|
||||
|
||||
//- /module/m2.rs
|
||||
pub mod submod;
|
||||
|
||||
//- /module/submod.rs
|
||||
pub struct Baz;
|
||||
"###,
|
||||
crate_graph! {
|
||||
"main": ("/main.rs", []),
|
||||
},
|
||||
);
|
||||
|
||||
assert_snapshot!(map, @r###"
|
||||
⋮crate
|
||||
⋮module: t
|
||||
⋮
|
||||
⋮crate::module
|
||||
⋮submod: t
|
||||
⋮
|
||||
⋮crate::module::submod
|
||||
⋮Baz: t v
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue