aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-11 10:30:06 +0100
committerAleksey Kladov <[email protected]>2020-06-11 10:30:06 +0100
commitd8a5d39c2d05fb59b6c243935111714e18334599 (patch)
tree9fed314df9599ba26df698c1d38a4d727f21481d /crates/ra_hir_expand/src
parentf632727b2ab985a9c5ceca781d033a08ee3822ea (diff)
Make relevant_crates return a Set
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r--crates/ra_hir_expand/src/builtin_derive.rs7
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs5
-rw-r--r--crates/ra_hir_expand/src/lib.rs5
-rw-r--r--crates/ra_hir_expand/src/test_db.rs3
4 files changed, 12 insertions, 8 deletions
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
11use crate::db::AstDatabase; 11use crate::db::AstDatabase;
12use crate::{name, quote, LazyMacroId, MacroCallId, MacroDefId, MacroDefKind}; 12use crate::{guess_crate, name, quote, LazyMacroId, MacroCallId, MacroDefId, MacroDefKind};
13 13
14macro_rules! register_builtin { 14macro_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
8use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; 8use crate::{guess_crate, quote, EagerMacroId, LazyMacroId, MacroCallId};
9use either::Either; 9use either::Either;
10use mbe::parse_to_token_tree; 10use mbe::parse_to_token_tree;
11use ra_db::FileId; 11use ra_db::FileId;
@@ -335,8 +335,7 @@ fn include_expand(
335fn get_env_inner(db: &dyn AstDatabase, arg_id: EagerMacroId, key: &str) -> Option<String> { 335fn 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
429fn 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
8use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate}; 8use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate};
9use 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}