mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Merge #2008
2008: Prepare SourceDatabase API for lazy file loading r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
8e3864fd58
14 changed files with 123 additions and 90 deletions
|
@ -189,14 +189,14 @@ impl Module {
|
|||
ModuleSource::SourceFile(_) => None,
|
||||
};
|
||||
|
||||
let source_root_id = db.file_source_root(src.file_id.original_file(db));
|
||||
db.source_root_crates(source_root_id).iter().map(|&crate_id| Crate { crate_id }).find_map(
|
||||
|krate| {
|
||||
db.relevant_crates(src.file_id.original_file(db))
|
||||
.iter()
|
||||
.map(|&crate_id| Crate { crate_id })
|
||||
.find_map(|krate| {
|
||||
let def_map = db.crate_def_map(krate);
|
||||
let module_id = def_map.find_module_by_source(src.file_id, decl_id)?;
|
||||
Some(Module { krate, module_id })
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,11 +85,7 @@ impl HirFileId {
|
|||
// Note:
|
||||
// The final goal we would like to make all parse_macro success,
|
||||
// such that the following log will not call anyway.
|
||||
log::warn!(
|
||||
"fail on macro_parse: (reason: {}) {}",
|
||||
err,
|
||||
macro_call_id.debug_dump(db)
|
||||
);
|
||||
log::warn!("fail on macro_parse: (reason: {})", err,);
|
||||
})
|
||||
.ok()?;
|
||||
match macro_file.macro_file_kind {
|
||||
|
@ -367,35 +363,6 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
|
|||
}
|
||||
}
|
||||
|
||||
impl MacroCallId {
|
||||
pub fn debug_dump(self, db: &impl AstDatabase) -> String {
|
||||
let loc = self.loc(db);
|
||||
let node = loc.ast_id.to_node(db);
|
||||
let syntax_str = {
|
||||
let mut res = String::new();
|
||||
node.syntax().text().for_each_chunk(|chunk| {
|
||||
if !res.is_empty() {
|
||||
res.push(' ')
|
||||
}
|
||||
res.push_str(chunk)
|
||||
});
|
||||
res
|
||||
};
|
||||
|
||||
// dump the file name
|
||||
let file_id: HirFileId = self.loc(db).ast_id.file_id();
|
||||
let original = file_id.original_file(db);
|
||||
let macro_rules = db.macro_def(loc.def);
|
||||
|
||||
format!(
|
||||
"macro call [file: {:?}] : {}\nhas rules: {}",
|
||||
db.file_relative_path(original),
|
||||
syntax_str,
|
||||
macro_rules.is_some()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// This exists just for Chalk, because Chalk just has a single `StructId` where
|
||||
/// we have different kinds of ADTs, primitive types and special type
|
||||
/// constructors like tuples and function pointers.
|
||||
|
|
|
@ -5,10 +5,10 @@ use std::{panic, sync::Arc};
|
|||
use parking_lot::Mutex;
|
||||
use ra_cfg::CfgOptions;
|
||||
use ra_db::{
|
||||
salsa, CrateGraph, CrateId, Edition, FileId, FilePosition, SourceDatabase, SourceRoot,
|
||||
SourceRootId,
|
||||
salsa, CrateGraph, CrateId, Edition, FileId, FileLoader, FileLoaderDelegate, FilePosition,
|
||||
SourceDatabase, SourceDatabaseExt, SourceRoot, SourceRootId,
|
||||
};
|
||||
use relative_path::RelativePathBuf;
|
||||
use relative_path::{RelativePath, RelativePathBuf};
|
||||
use rustc_hash::FxHashMap;
|
||||
use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER};
|
||||
|
||||
|
@ -17,6 +17,7 @@ use crate::{db, debug::HirDebugHelper, diagnostics::DiagnosticSink};
|
|||
pub const WORKSPACE: SourceRootId = SourceRootId(0);
|
||||
|
||||
#[salsa::database(
|
||||
ra_db::SourceDatabaseExtStorage,
|
||||
ra_db::SourceDatabaseStorage,
|
||||
db::InternDatabaseStorage,
|
||||
db::AstDatabaseStorage,
|
||||
|
@ -34,6 +35,22 @@ pub struct MockDatabase {
|
|||
|
||||
impl panic::RefUnwindSafe for MockDatabase {}
|
||||
|
||||
impl FileLoader for MockDatabase {
|
||||
fn file_text(&self, file_id: FileId) -> Arc<String> {
|
||||
FileLoaderDelegate(self).file_text(file_id)
|
||||
}
|
||||
fn resolve_relative_path(
|
||||
&self,
|
||||
anchor: FileId,
|
||||
relative_path: &RelativePath,
|
||||
) -> Option<FileId> {
|
||||
FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path)
|
||||
}
|
||||
fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> {
|
||||
FileLoaderDelegate(self).relevant_crates(file_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl HirDebugHelper for MockDatabase {
|
||||
fn crate_name(&self, krate: CrateId) -> Option<String> {
|
||||
self.crate_names.get(&krate).cloned()
|
||||
|
|
|
@ -2,7 +2,7 @@ use super::*;
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_db::SourceDatabase;
|
||||
use ra_db::{SourceDatabase, SourceDatabaseExt};
|
||||
|
||||
fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) {
|
||||
let (mut db, pos) = MockDatabase::with_position(initial);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue