mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-20 03:49:51 +00:00
Fix IDE layer not correctly resolving opt-in extern crates
This commit is contained in:
parent
727555fc04
commit
597d8e837a
3 changed files with 18 additions and 7 deletions
|
|
@ -506,14 +506,17 @@ impl ExternCrateDeclData {
|
||||||
let crate_id = if name == sym::self_.clone() {
|
let crate_id = if name == sym::self_.clone() {
|
||||||
Some(krate)
|
Some(krate)
|
||||||
} else {
|
} else {
|
||||||
db.crate_def_map(krate)
|
db.crate_graph()[krate].dependencies.iter().find_map(|dep| {
|
||||||
.extern_prelude()
|
if dep.name.symbol() == name.symbol() {
|
||||||
.find(|&(prelude_name, ..)| *prelude_name == name)
|
Some(dep.crate_id)
|
||||||
.map(|(_, (root, _))| root.krate())
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
Arc::new(Self {
|
Arc::new(Self {
|
||||||
name: extern_crate.name.clone(),
|
name,
|
||||||
visibility: item_tree[extern_crate.visibility].clone(),
|
visibility: item_tree[extern_crate.visibility].clone(),
|
||||||
alias: extern_crate.alias.clone(),
|
alias: extern_crate.alias.clone(),
|
||||||
crate_id,
|
crate_id,
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">std</span><span class="semicolon">;</span>
|
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">std</span><span class="semicolon">;</span>
|
||||||
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">alloc</span> <span class="keyword">as</span> <span class="module crate_root declaration">abc</span><span class="semicolon">;</span>
|
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">alloc</span> <span class="keyword">as</span> <span class="module crate_root declaration">abc</span><span class="semicolon">;</span>
|
||||||
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="unresolved_reference">unresolved</span> <span class="keyword">as</span> <span class="module crate_root declaration">definitely_unresolved</span><span class="semicolon">;</span>
|
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="unresolved_reference">unresolved</span> <span class="keyword">as</span> <span class="module crate_root declaration">definitely_unresolved</span><span class="semicolon">;</span>
|
||||||
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="unresolved_reference">test</span> <span class="keyword">as</span> <span class="module crate_root declaration">opt_in_crate</span><span class="semicolon">;</span>
|
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="unresolved_reference">unresolved</span> <span class="keyword">as</span> <span class="punctuation">_</span><span class="semicolon">;</span>
|
||||||
|
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">test</span> <span class="keyword">as</span> <span class="module crate_root declaration">opt_in_crate</span><span class="semicolon">;</span>
|
||||||
|
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">test</span> <span class="keyword">as</span> <span class="punctuation">_</span><span class="semicolon">;</span>
|
||||||
|
<span class="keyword">extern</span> <span class="keyword">crate</span> <span class="module crate_root default_library library">proc_macro</span><span class="semicolon">;</span>
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
@ -874,18 +874,23 @@ pub fn block_comments2() {}
|
||||||
fn test_extern_crate() {
|
fn test_extern_crate() {
|
||||||
check_highlighting(
|
check_highlighting(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std,alloc,test extern-prelude:std,alloc
|
//- /main.rs crate:main deps:std,alloc,test,proc_macro extern-prelude:std,alloc
|
||||||
extern crate self as this;
|
extern crate self as this;
|
||||||
extern crate std;
|
extern crate std;
|
||||||
extern crate alloc as abc;
|
extern crate alloc as abc;
|
||||||
extern crate unresolved as definitely_unresolved;
|
extern crate unresolved as definitely_unresolved;
|
||||||
|
extern crate unresolved as _;
|
||||||
extern crate test as opt_in_crate;
|
extern crate test as opt_in_crate;
|
||||||
|
extern crate test as _;
|
||||||
|
extern crate proc_macro;
|
||||||
//- /std/lib.rs crate:std
|
//- /std/lib.rs crate:std
|
||||||
pub struct S;
|
pub struct S;
|
||||||
//- /alloc/lib.rs crate:alloc
|
//- /alloc/lib.rs crate:alloc
|
||||||
pub struct A;
|
pub struct A;
|
||||||
//- /test/lib.rs crate:test
|
//- /test/lib.rs crate:test
|
||||||
pub struct T;
|
pub struct T;
|
||||||
|
//- /proc_macro/lib.rs crate:proc_macro
|
||||||
|
pub struct ProcMacro;
|
||||||
"#,
|
"#,
|
||||||
expect_file!["./test_data/highlight_extern_crate.html"],
|
expect_file!["./test_data/highlight_extern_crate.html"],
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue