aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-14 14:26:42 +0100
committerGitHub <[email protected]>2019-10-14 14:26:42 +0100
commit8e3864fd580fb93e8ce92e4b4e6ac51050e54047 (patch)
tree7cc9565b1e81ec069297167e935d062b7dc4bc06 /crates/ra_hir/src
parente182825170e346abb84240b84458b49b73783dca (diff)
parentabf2179c0b606730acadc61451739baecfa33a5d (diff)
Merge #2008
2008: Prepare SourceDatabase API for lazy file loading r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/from_source.rs10
-rw-r--r--crates/ra_hir/src/ids.rs35
-rw-r--r--crates/ra_hir/src/mock.rs23
-rw-r--r--crates/ra_hir/src/nameres/tests/incremental.rs2
4 files changed, 27 insertions, 43 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index a012f33f7..f80d8eb5f 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -189,14 +189,14 @@ impl Module {
189 ModuleSource::SourceFile(_) => None, 189 ModuleSource::SourceFile(_) => None,
190 }; 190 };
191 191
192 let source_root_id = db.file_source_root(src.file_id.original_file(db)); 192 db.relevant_crates(src.file_id.original_file(db))
193 db.source_root_crates(source_root_id).iter().map(|&crate_id| Crate { crate_id }).find_map( 193 .iter()
194 |krate| { 194 .map(|&crate_id| Crate { crate_id })
195 .find_map(|krate| {
195 let def_map = db.crate_def_map(krate); 196 let def_map = db.crate_def_map(krate);
196 let module_id = def_map.find_module_by_source(src.file_id, decl_id)?; 197 let module_id = def_map.find_module_by_source(src.file_id, decl_id)?;
197 Some(Module { krate, module_id }) 198 Some(Module { krate, module_id })
198 }, 199 })
199 )
200 } 200 }
201} 201}
202 202
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 85b022744..499dcafea 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -85,11 +85,7 @@ impl HirFileId {
85 // Note: 85 // Note:
86 // The final goal we would like to make all parse_macro success, 86 // The final goal we would like to make all parse_macro success,
87 // such that the following log will not call anyway. 87 // such that the following log will not call anyway.
88 log::warn!( 88 log::warn!("fail on macro_parse: (reason: {})", err,);
89 "fail on macro_parse: (reason: {}) {}",
90 err,
91 macro_call_id.debug_dump(db)
92 );
93 }) 89 })
94 .ok()?; 90 .ok()?;
95 match macro_file.macro_file_kind { 91 match macro_file.macro_file_kind {
@@ -367,35 +363,6 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
367 } 363 }
368} 364}
369 365
370impl MacroCallId {
371 pub fn debug_dump(self, db: &impl AstDatabase) -> String {
372 let loc = self.loc(db);
373 let node = loc.ast_id.to_node(db);
374 let syntax_str = {
375 let mut res = String::new();
376 node.syntax().text().for_each_chunk(|chunk| {
377 if !res.is_empty() {
378 res.push(' ')
379 }
380 res.push_str(chunk)
381 });
382 res
383 };
384
385 // dump the file name
386 let file_id: HirFileId = self.loc(db).ast_id.file_id();
387 let original = file_id.original_file(db);
388 let macro_rules = db.macro_def(loc.def);
389
390 format!(
391 "macro call [file: {:?}] : {}\nhas rules: {}",
392 db.file_relative_path(original),
393 syntax_str,
394 macro_rules.is_some()
395 )
396 }
397}
398
399/// This exists just for Chalk, because Chalk just has a single `StructId` where 366/// This exists just for Chalk, because Chalk just has a single `StructId` where
400/// we have different kinds of ADTs, primitive types and special type 367/// we have different kinds of ADTs, primitive types and special type
401/// constructors like tuples and function pointers. 368/// constructors like tuples and function pointers.
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 827424983..0b278deb3 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -5,10 +5,10 @@ use std::{panic, sync::Arc};
5use parking_lot::Mutex; 5use parking_lot::Mutex;
6use ra_cfg::CfgOptions; 6use ra_cfg::CfgOptions;
7use ra_db::{ 7use ra_db::{
8 salsa, CrateGraph, CrateId, Edition, FileId, FilePosition, SourceDatabase, SourceRoot, 8 salsa, CrateGraph, CrateId, Edition, FileId, FileLoader, FileLoaderDelegate, FilePosition,
9 SourceRootId, 9 SourceDatabase, SourceDatabaseExt, SourceRoot, SourceRootId,
10}; 10};
11use relative_path::RelativePathBuf; 11use relative_path::{RelativePath, RelativePathBuf};
12use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
13use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; 13use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER};
14 14
@@ -17,6 +17,7 @@ use crate::{db, debug::HirDebugHelper, diagnostics::DiagnosticSink};
17pub const WORKSPACE: SourceRootId = SourceRootId(0); 17pub const WORKSPACE: SourceRootId = SourceRootId(0);
18 18
19#[salsa::database( 19#[salsa::database(
20 ra_db::SourceDatabaseExtStorage,
20 ra_db::SourceDatabaseStorage, 21 ra_db::SourceDatabaseStorage,
21 db::InternDatabaseStorage, 22 db::InternDatabaseStorage,
22 db::AstDatabaseStorage, 23 db::AstDatabaseStorage,
@@ -34,6 +35,22 @@ pub struct MockDatabase {
34 35
35impl panic::RefUnwindSafe for MockDatabase {} 36impl panic::RefUnwindSafe for MockDatabase {}
36 37
38impl FileLoader for MockDatabase {
39 fn file_text(&self, file_id: FileId) -> Arc<String> {
40 FileLoaderDelegate(self).file_text(file_id)
41 }
42 fn resolve_relative_path(
43 &self,
44 anchor: FileId,
45 relative_path: &RelativePath,
46 ) -> Option<FileId> {
47 FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path)
48 }
49 fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {
50 FileLoaderDelegate(self).relevant_crates(file_id)
51 }
52}
53
37impl HirDebugHelper for MockDatabase { 54impl HirDebugHelper for MockDatabase {
38 fn crate_name(&self, krate: CrateId) -> Option<String> { 55 fn crate_name(&self, krate: CrateId) -> Option<String> {
39 self.crate_names.get(&krate).cloned() 56 self.crate_names.get(&krate).cloned()
diff --git a/crates/ra_hir/src/nameres/tests/incremental.rs b/crates/ra_hir/src/nameres/tests/incremental.rs
index c41862a0b..af9c39760 100644
--- a/crates/ra_hir/src/nameres/tests/incremental.rs
+++ b/crates/ra_hir/src/nameres/tests/incremental.rs
@@ -2,7 +2,7 @@ use super::*;
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_db::SourceDatabase; 5use ra_db::{SourceDatabase, SourceDatabaseExt};
6 6
7fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) { 7fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) {
8 let (mut db, pos) = MockDatabase::with_position(initial); 8 let (mut db, pos) = MockDatabase::with_position(initial);