diff options
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_derive.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/test_db.rs | 3 |
5 files changed, 13 insertions, 8 deletions
diff --git a/crates/ra_hir_expand/Cargo.toml b/crates/ra_hir_expand/Cargo.toml index 2cd522766..e5c9f3e99 100644 --- a/crates/ra_hir_expand/Cargo.toml +++ b/crates/ra_hir_expand/Cargo.toml | |||
@@ -10,6 +10,7 @@ doctest = false | |||
10 | [dependencies] | 10 | [dependencies] |
11 | log = "0.4.8" | 11 | log = "0.4.8" |
12 | either = "1.5.3" | 12 | either = "1.5.3" |
13 | rustc-hash = "1.0.0" | ||
13 | 14 | ||
14 | ra_arena = { path = "../ra_arena" } | 15 | ra_arena = { path = "../ra_arena" } |
15 | ra_db = { path = "../ra_db" } | 16 | ra_db = { path = "../ra_db" } |
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index 1dc9cac66..967d1f3a1 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs | |||
@@ -9,7 +9,7 @@ use ra_syntax::{ | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::db::AstDatabase; | 11 | use crate::db::AstDatabase; |
12 | use crate::{name, quote, LazyMacroId, MacroCallId, MacroDefId, MacroDefKind}; | 12 | use crate::{guess_crate, name, quote, LazyMacroId, MacroCallId, MacroDefId, MacroDefKind}; |
13 | 13 | ||
14 | macro_rules! register_builtin { | 14 | macro_rules! register_builtin { |
15 | ( $($trait:ident => $expand:ident),* ) => { | 15 | ( $($trait:ident => $expand:ident),* ) => { |
@@ -160,8 +160,7 @@ fn find_builtin_crate(db: &dyn AstDatabase, id: LazyMacroId) -> tt::TokenTree { | |||
160 | let m: MacroCallId = id.into(); | 160 | let m: MacroCallId = id.into(); |
161 | let file_id = m.as_file().original_file(db); | 161 | let file_id = m.as_file().original_file(db); |
162 | let cg = db.crate_graph(); | 162 | let cg = db.crate_graph(); |
163 | let krates = db.relevant_crates(file_id); | 163 | let krate = match guess_crate(db, file_id) { |
164 | let krate = match krates.get(0) { | ||
165 | Some(krate) => krate, | 164 | Some(krate) => krate, |
166 | None => { | 165 | None => { |
167 | let tt = quote! { core }; | 166 | let tt = quote! { core }; |
@@ -172,7 +171,7 @@ fn find_builtin_crate(db: &dyn AstDatabase, id: LazyMacroId) -> tt::TokenTree { | |||
172 | // XXX | 171 | // XXX |
173 | // All crates except core itself should have a dependency on core, | 172 | // All crates except core itself should have a dependency on core, |
174 | // We detect `core` by seeing whether it doesn't have such a dependency. | 173 | // We detect `core` by seeing whether it doesn't have such a dependency. |
175 | let tt = if cg[*krate].dependencies.iter().any(|dep| dep.name == "core") { | 174 | let tt = if cg[krate].dependencies.iter().any(|dep| dep.name == "core") { |
176 | quote! { core } | 175 | quote! { core } |
177 | } else { | 176 | } else { |
178 | quote! { crate } | 177 | quote! { crate } |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 7579546d2..93da3f149 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -5,7 +5,7 @@ use crate::{ | |||
5 | name, AstId, CrateId, MacroDefId, MacroDefKind, TextSize, | 5 | name, AstId, CrateId, MacroDefId, MacroDefKind, TextSize, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; | 8 | use crate::{guess_crate, quote, EagerMacroId, LazyMacroId, MacroCallId}; |
9 | use either::Either; | 9 | use either::Either; |
10 | use mbe::parse_to_token_tree; | 10 | use mbe::parse_to_token_tree; |
11 | use ra_db::FileId; | 11 | use ra_db::FileId; |
@@ -335,8 +335,7 @@ fn include_expand( | |||
335 | fn get_env_inner(db: &dyn AstDatabase, arg_id: EagerMacroId, key: &str) -> Option<String> { | 335 | fn get_env_inner(db: &dyn AstDatabase, arg_id: EagerMacroId, key: &str) -> Option<String> { |
336 | let call_id: MacroCallId = arg_id.into(); | 336 | let call_id: MacroCallId = arg_id.into(); |
337 | let original_file = call_id.as_file().original_file(db); | 337 | let original_file = call_id.as_file().original_file(db); |
338 | 338 | let krate = guess_crate(db, original_file)?; | |
339 | let krate = *db.relevant_crates(original_file).get(0)?; | ||
340 | db.crate_graph()[krate].env.get(key) | 339 | db.crate_graph()[krate].env.get(key) |
341 | } | 340 | } |
342 | 341 | ||
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index f440c073b..dc4d7f000 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -424,3 +424,8 @@ impl<N: AstNode> InFile<N> { | |||
424 | self.with_value(self.value.syntax()) | 424 | self.with_value(self.value.syntax()) |
425 | } | 425 | } |
426 | } | 426 | } |
427 | |||
428 | // FIXME: this is obviously wrong, there shouldn't be any guesing here | ||
429 | fn guess_crate(db: &dyn db::AstDatabase, file_id: FileId) -> Option<CrateId> { | ||
430 | db.relevant_crates(file_id).iter().next().copied() | ||
431 | } | ||
diff --git a/crates/ra_hir_expand/src/test_db.rs b/crates/ra_hir_expand/src/test_db.rs index fdf225f55..09fc18c36 100644 --- a/crates/ra_hir_expand/src/test_db.rs +++ b/crates/ra_hir_expand/src/test_db.rs | |||
@@ -6,6 +6,7 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate}; | 8 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate}; |
9 | use rustc_hash::FxHashSet; | ||
9 | 10 | ||
10 | #[salsa::database( | 11 | #[salsa::database( |
11 | ra_db::SourceDatabaseExtStorage, | 12 | ra_db::SourceDatabaseExtStorage, |
@@ -44,7 +45,7 @@ impl FileLoader for TestDB { | |||
44 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { | 45 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
45 | FileLoaderDelegate(self).resolve_path(anchor, path) | 46 | FileLoaderDelegate(self).resolve_path(anchor, path) |
46 | } | 47 | } |
47 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 48 | fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { |
48 | FileLoaderDelegate(self).relevant_crates(file_id) | 49 | FileLoaderDelegate(self).relevant_crates(file_id) |
49 | } | 50 | } |
50 | } | 51 | } |