diff options
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/attr.rs | 12 | ||||
-rw-r--r-- | crates/hir_def/src/find_path.rs | 30 |
2 files changed, 36 insertions, 6 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index d9294d93a..0171d8a92 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -484,10 +484,10 @@ impl AttrsWithOwner { | |||
484 | let mut buf = String::new(); | 484 | let mut buf = String::new(); |
485 | let mut mapping = Vec::new(); | 485 | let mut mapping = Vec::new(); |
486 | for (doc, idx) in docs { | 486 | for (doc, idx) in docs { |
487 | // str::lines doesn't yield anything for the empty string | ||
488 | if !doc.is_empty() { | 487 | if !doc.is_empty() { |
489 | for line in doc.split('\n') { | 488 | let mut base_offset = 0; |
490 | let line = line.trim_end(); | 489 | for raw_line in doc.split('\n') { |
490 | let line = raw_line.trim_end(); | ||
491 | let line_len = line.len(); | 491 | let line_len = line.len(); |
492 | let (offset, line) = match line.char_indices().nth(indent) { | 492 | let (offset, line) = match line.char_indices().nth(indent) { |
493 | Some((offset, _)) => (offset, &line[offset..]), | 493 | Some((offset, _)) => (offset, &line[offset..]), |
@@ -498,9 +498,13 @@ impl AttrsWithOwner { | |||
498 | mapping.push(( | 498 | mapping.push(( |
499 | TextRange::new(buf_offset.try_into().ok()?, buf.len().try_into().ok()?), | 499 | TextRange::new(buf_offset.try_into().ok()?, buf.len().try_into().ok()?), |
500 | idx, | 500 | idx, |
501 | TextRange::new(offset.try_into().ok()?, line_len.try_into().ok()?), | 501 | TextRange::at( |
502 | (base_offset + offset).try_into().ok()?, | ||
503 | line_len.try_into().ok()?, | ||
504 | ), | ||
502 | )); | 505 | )); |
503 | buf.push('\n'); | 506 | buf.push('\n'); |
507 | base_offset += raw_line.len() + 1; | ||
504 | } | 508 | } |
505 | } else { | 509 | } else { |
506 | buf.push('\n'); | 510 | buf.push('\n'); |
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs index dc3f2908f..c06a37294 100644 --- a/crates/hir_def/src/find_path.rs +++ b/crates/hir_def/src/find_path.rs | |||
@@ -130,7 +130,8 @@ fn find_path_inner( | |||
130 | } | 130 | } |
131 | 131 | ||
132 | // - if the item is the crate root of a dependency crate, return the name from the extern prelude | 132 | // - if the item is the crate root of a dependency crate, return the name from the extern prelude |
133 | for (name, def_id) in root.def_map(db).extern_prelude() { | 133 | let root_def_map = root.def_map(db); |
134 | for (name, def_id) in root_def_map.extern_prelude() { | ||
134 | if item == ItemInNs::Types(*def_id) { | 135 | if item == ItemInNs::Types(*def_id) { |
135 | let name = scope_name.unwrap_or_else(|| name.clone()); | 136 | let name = scope_name.unwrap_or_else(|| name.clone()); |
136 | return Some(ModPath::from_segments(PathKind::Plain, vec![name])); | 137 | return Some(ModPath::from_segments(PathKind::Plain, vec![name])); |
@@ -138,7 +139,8 @@ fn find_path_inner( | |||
138 | } | 139 | } |
139 | 140 | ||
140 | // - if the item is in the prelude, return the name from there | 141 | // - if the item is in the prelude, return the name from there |
141 | if let Some(prelude_module) = def_map.prelude() { | 142 | if let Some(prelude_module) = root_def_map.prelude() { |
143 | // Preludes in block DefMaps are ignored, only the crate DefMap is searched | ||
142 | let prelude_def_map = prelude_module.def_map(db); | 144 | let prelude_def_map = prelude_module.def_map(db); |
143 | let prelude_scope: &crate::item_scope::ItemScope = | 145 | let prelude_scope: &crate::item_scope::ItemScope = |
144 | &prelude_def_map[prelude_module.local_id].scope; | 146 | &prelude_def_map[prelude_module.local_id].scope; |
@@ -1057,4 +1059,28 @@ fn f() { | |||
1057 | "dep", | 1059 | "dep", |
1058 | ); | 1060 | ); |
1059 | } | 1061 | } |
1062 | |||
1063 | #[test] | ||
1064 | fn prelude_with_inner_items() { | ||
1065 | check_found_path( | ||
1066 | r#" | ||
1067 | //- /main.rs crate:main deps:std | ||
1068 | fn f() { | ||
1069 | fn inner() {} | ||
1070 | $0 | ||
1071 | } | ||
1072 | //- /std.rs crate:std | ||
1073 | pub mod prelude { | ||
1074 | pub enum Option { None } | ||
1075 | pub use Option::*; | ||
1076 | } | ||
1077 | #[prelude_import] | ||
1078 | pub use prelude::*; | ||
1079 | "#, | ||
1080 | "None", | ||
1081 | "None", | ||
1082 | "None", | ||
1083 | "None", | ||
1084 | ); | ||
1085 | } | ||
1060 | } | 1086 | } |