mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Fixed request comments
This commit is contained in:
parent
22b863c534
commit
9c75f30272
2 changed files with 72 additions and 66 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use ra_db::FileId;
|
use ra_db::FileId;
|
||||||
use ra_syntax::{ast, SmolStr};
|
use ra_syntax::{ast, SmolStr};
|
||||||
|
@ -650,7 +652,7 @@ fn resolve_submodule(
|
||||||
let mut candidates = ArrayVec::<[_; 3]>::new();
|
let mut candidates = ArrayVec::<[_; 3]>::new();
|
||||||
let file_attr_mod = attr_path.map(|file_path| {
|
let file_attr_mod = attr_path.map(|file_path| {
|
||||||
let file_path = normalize_attribute_path(file_path);
|
let file_path = normalize_attribute_path(file_path);
|
||||||
let file_attr_mod = dir_path.join(file_path).normalize();
|
let file_attr_mod = dir_path.join(file_path.as_ref()).normalize();
|
||||||
candidates.push(file_attr_mod.clone());
|
candidates.push(file_attr_mod.clone());
|
||||||
|
|
||||||
file_attr_mod
|
file_attr_mod
|
||||||
|
@ -676,14 +678,18 @@ fn resolve_submodule(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_attribute_path(file_path: &SmolStr) -> String {
|
fn normalize_attribute_path(file_path: &SmolStr) -> Cow<str> {
|
||||||
let current_dir = "./";
|
let current_dir = "./";
|
||||||
|
let windows_path_separator = r#"\"#;
|
||||||
let separator = |path: &str| path.replace("\\", "/");
|
let current_dir_normalize = if file_path.starts_with(current_dir) {
|
||||||
if file_path.starts_with(current_dir) {
|
&file_path[current_dir.len()..]
|
||||||
separator(&file_path[current_dir.len()..])
|
|
||||||
} else {
|
} else {
|
||||||
separator(file_path.as_str())
|
file_path.as_str()
|
||||||
|
};
|
||||||
|
if current_dir_normalize.contains(windows_path_separator) {
|
||||||
|
Cow::Owned(current_dir_normalize.replace(windows_path_separator, "/"))
|
||||||
|
} else {
|
||||||
|
Cow::Borrowed(current_dir_normalize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,15 +80,15 @@ fn module_resolution_works_for_raw_modules() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_decl_path() {
|
fn module_resolution_decl_path() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /library.rs
|
//- /library.rs
|
||||||
#[path = \"bar/baz/foo.rs\"]
|
#[path = "bar/baz/foo.rs"]
|
||||||
mod foo;
|
mod foo;
|
||||||
use self::foo::Bar;
|
use self::foo::Bar;
|
||||||
|
|
||||||
//- /bar/baz/foo.rs
|
//- /bar/baz/foo.rs
|
||||||
pub struct Bar;
|
pub struct Bar;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"library": ("/library.rs", []),
|
"library": ("/library.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -107,19 +107,19 @@ fn module_resolution_decl_path() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_module_with_path_in_mod_rs() {
|
fn module_resolution_module_with_path_in_mod_rs() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo/mod.rs
|
//- /foo/mod.rs
|
||||||
#[path = \"baz.rs\"]
|
#[path = "baz.rs"]
|
||||||
pub mod bar;
|
pub mod bar;
|
||||||
|
|
||||||
use self::bar::Baz;
|
use self::bar::Baz;
|
||||||
|
|
||||||
//- /foo/baz.rs
|
//- /foo/baz.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -141,19 +141,19 @@ fn module_resolution_module_with_path_in_mod_rs() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_module_with_path_non_crate_root() {
|
fn module_resolution_module_with_path_non_crate_root() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
#[path = \"baz.rs\"]
|
#[path = "baz.rs"]
|
||||||
pub mod bar;
|
pub mod bar;
|
||||||
|
|
||||||
use self::bar::Baz;
|
use self::bar::Baz;
|
||||||
|
|
||||||
//- /baz.rs
|
//- /baz.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -175,15 +175,15 @@ fn module_resolution_module_with_path_non_crate_root() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_module_decl_path_super() {
|
fn module_resolution_module_decl_path_super() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"bar/baz/module.rs\"]
|
#[path = "bar/baz/module.rs"]
|
||||||
mod foo;
|
mod foo;
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
|
|
||||||
//- /bar/baz/module.rs
|
//- /bar/baz/module.rs
|
||||||
use super::Baz;
|
use super::Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -202,14 +202,14 @@ fn module_resolution_module_decl_path_super() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_explicit_path_mod_rs() {
|
fn module_resolution_explicit_path_mod_rs() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"module/mod.rs\"]
|
#[path = "module/mod.rs"]
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /module/mod.rs
|
//- /module/mod.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -227,17 +227,17 @@ fn module_resolution_explicit_path_mod_rs() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_relative_path() {
|
fn module_resolution_relative_path() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
#[path = \"./sub.rs\"]
|
#[path = "./sub.rs"]
|
||||||
pub mod foo_bar;
|
pub mod foo_bar;
|
||||||
|
|
||||||
//- /sub.rs
|
//- /sub.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -258,17 +258,17 @@ fn module_resolution_relative_path() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_relative_path_2() {
|
fn module_resolution_relative_path_2() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo/mod.rs
|
//- /foo/mod.rs
|
||||||
#[path=\"../sub.rs\"]
|
#[path="../sub.rs"]
|
||||||
pub mod foo_bar;
|
pub mod foo_bar;
|
||||||
|
|
||||||
//- /sub.rs
|
//- /sub.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -289,14 +289,14 @@ fn module_resolution_relative_path_2() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_explicit_path_mod_rs_2() {
|
fn module_resolution_explicit_path_mod_rs_2() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"module/bar/mod.rs\"]
|
#[path = "module/bar/mod.rs"]
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /module/bar/mod.rs
|
//- /module/bar/mod.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -314,14 +314,14 @@ fn module_resolution_explicit_path_mod_rs_2() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_explicit_path_mod_rs_with_win_separator() {
|
fn module_resolution_explicit_path_mod_rs_with_win_separator() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"module\\bar\\mod.rs\"]
|
#[path = "module\bar\mod.rs"]
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /module/bar/mod.rs
|
//- /module/bar/mod.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -341,16 +341,16 @@ fn module_resolution_explicit_path_mod_rs_with_win_separator() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module() {
|
fn module_resolution_decl_inside_inline_module() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"models\"]
|
#[path = "models"]
|
||||||
mod foo {
|
mod foo {
|
||||||
mod bar;
|
mod bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /models/bar.rs
|
//- /models/bar.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -373,16 +373,16 @@ fn module_resolution_decl_inside_inline_module() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_2() {
|
fn module_resolution_decl_inside_inline_module_2() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"models/db\"]
|
#[path = "models/db"]
|
||||||
mod foo {
|
mod foo {
|
||||||
mod bar;
|
mod bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /models/db/bar.rs
|
//- /models/db/bar.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -405,17 +405,17 @@ fn module_resolution_decl_inside_inline_module_2() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_3() {
|
fn module_resolution_decl_inside_inline_module_3() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"models/db\"]
|
#[path = "models/db"]
|
||||||
mod foo {
|
mod foo {
|
||||||
#[path = \"users.rs\"]
|
#[path = "users.rs"]
|
||||||
mod bar;
|
mod bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /models/db/users.rs
|
//- /models/db/users.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -438,17 +438,17 @@ fn module_resolution_decl_inside_inline_module_3() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_empty_path() {
|
fn module_resolution_decl_inside_inline_module_empty_path() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"\"]
|
#[path = ""]
|
||||||
mod foo {
|
mod foo {
|
||||||
#[path = \"users.rs\"]
|
#[path = "users.rs"]
|
||||||
mod bar;
|
mod bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /users.rs
|
//- /users.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -469,14 +469,14 @@ fn module_resolution_decl_inside_inline_module_empty_path() {
|
||||||
#[test]
|
#[test]
|
||||||
fn module_resolution_decl_empty_path() {
|
fn module_resolution_decl_empty_path() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"\"]
|
#[path = ""]
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -496,16 +496,16 @@ fn module_resolution_decl_empty_path() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_relative_path() {
|
fn module_resolution_decl_inside_inline_module_relative_path() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[path = \"./models\"]
|
#[path = "./models"]
|
||||||
mod foo {
|
mod foo {
|
||||||
mod bar;
|
mod bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /models/bar.rs
|
//- /models/bar.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -528,17 +528,17 @@ fn module_resolution_decl_inside_inline_module_relative_path() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_in_crate_root() {
|
fn module_resolution_decl_inside_inline_module_in_crate_root() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo {
|
mod foo {
|
||||||
#[path = \"baz.rs\"]
|
#[path = "baz.rs"]
|
||||||
mod bar;
|
mod bar;
|
||||||
}
|
}
|
||||||
use self::foo::bar::Baz;
|
use self::foo::bar::Baz;
|
||||||
|
|
||||||
//- /foo/baz.rs
|
//- /foo/baz.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -562,20 +562,20 @@ fn module_resolution_decl_inside_inline_module_in_crate_root() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_in_mod_rs() {
|
fn module_resolution_decl_inside_inline_module_in_mod_rs() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo/mod.rs
|
//- /foo/mod.rs
|
||||||
mod bar {
|
mod bar {
|
||||||
#[path = \"qwe.rs\"]
|
#[path = "qwe.rs"]
|
||||||
pub mod baz;
|
pub mod baz;
|
||||||
}
|
}
|
||||||
use self::bar::baz::Baz;
|
use self::bar::baz::Baz;
|
||||||
|
|
||||||
//- /foo/bar/qwe.rs
|
//- /foo/bar/qwe.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -602,20 +602,20 @@ fn module_resolution_decl_inside_inline_module_in_mod_rs() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_in_non_crate_root() {
|
fn module_resolution_decl_inside_inline_module_in_non_crate_root() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
mod bar {
|
mod bar {
|
||||||
#[path = \"qwe.rs\"]
|
#[path = "qwe.rs"]
|
||||||
pub mod baz;
|
pub mod baz;
|
||||||
}
|
}
|
||||||
use self::bar::baz::Baz;
|
use self::bar::baz::Baz;
|
||||||
|
|
||||||
//- /foo/bar/qwe.rs
|
//- /foo/bar/qwe.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
@ -642,12 +642,12 @@ fn module_resolution_decl_inside_inline_module_in_non_crate_root() {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() {
|
fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
"
|
r###"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
#[path = \"bar\"]
|
#[path = "bar"]
|
||||||
mod bar {
|
mod bar {
|
||||||
pub mod baz;
|
pub mod baz;
|
||||||
}
|
}
|
||||||
|
@ -655,7 +655,7 @@ fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() {
|
||||||
|
|
||||||
//- /bar/baz.rs
|
//- /bar/baz.rs
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
",
|
"###,
|
||||||
crate_graph! {
|
crate_graph! {
|
||||||
"main": ("/main.rs", []),
|
"main": ("/main.rs", []),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue