fix tests

This commit is contained in:
Aleksey Kladov 2018-12-19 16:19:53 +03:00
parent e6465e7e2a
commit 2fe41574a1
5 changed files with 26 additions and 13 deletions

View file

@ -43,10 +43,19 @@ impl AnalysisHostImpl {
pub fn apply_change(&mut self, change: AnalysisChange) { pub fn apply_change(&mut self, change: AnalysisChange) {
log::info!("apply_change {:?}", change); log::info!("apply_change {:?}", change);
// self.gc_syntax_trees(); // self.gc_syntax_trees();
for root_id in change.new_roots { if !change.new_roots.is_empty() {
let mut local_roots = Vec::clone(&self.db.local_roots());
for (root_id, is_local) in change.new_roots {
self.db self.db
.query_mut(ra_db::SourceRootQuery) .query_mut(ra_db::SourceRootQuery)
.set(root_id, Default::default()); .set(root_id, Default::default());
if is_local {
local_roots.push(root_id);
}
}
self.db
.query_mut(ra_db::LocalRootsQuery)
.set((), Arc::new(local_roots));
} }
for (root_id, root_change) in change.roots_changed { for (root_id, root_change) in change.roots_changed {

View file

@ -44,7 +44,7 @@ pub use ra_db::{
#[derive(Default)] #[derive(Default)]
pub struct AnalysisChange { pub struct AnalysisChange {
new_roots: Vec<SourceRootId>, new_roots: Vec<(SourceRootId, bool)>,
roots_changed: FxHashMap<SourceRootId, RootChange>, roots_changed: FxHashMap<SourceRootId, RootChange>,
files_changed: Vec<(FileId, Arc<String>)>, files_changed: Vec<(FileId, Arc<String>)>,
libraries_added: Vec<LibraryData>, libraries_added: Vec<LibraryData>,
@ -95,8 +95,8 @@ impl AnalysisChange {
pub fn new() -> AnalysisChange { pub fn new() -> AnalysisChange {
AnalysisChange::default() AnalysisChange::default()
} }
pub fn add_root(&mut self, root_id: SourceRootId) { pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) {
self.new_roots.push(root_id); self.new_roots.push((root_id, is_local));
} }
pub fn add_file( pub fn add_file(
&mut self, &mut self,

View file

@ -80,7 +80,7 @@ impl MockAnalysis {
let mut file_map = FileMap::default(); let mut file_map = FileMap::default();
let source_root = SourceRootId(0); let source_root = SourceRootId(0);
let mut change = AnalysisChange::new(); let mut change = AnalysisChange::new();
change.add_root(source_root); change.add_root(source_root, true);
for (path, contents) in self.files.into_iter() { for (path, contents) in self.files.into_iter() {
assert!(path.starts_with('/')); assert!(path.starts_with('/'));
let path = RelativePathBuf::from_path(&path[1..]).unwrap(); let path = RelativePathBuf::from_path(&path[1..]).unwrap();

View file

@ -2,12 +2,14 @@ use std::sync::Arc;
use parking_lot::Mutex; use parking_lot::Mutex;
use salsa::{self, Database}; use salsa::{self, Database};
use ra_db::{LocationIntener, BaseDatabase, FilePosition, FileId, WORKSPACE, CrateGraph, SourceRoot}; use ra_db::{LocationIntener, BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
use crate::{db, DefId, DefLoc}; use crate::{db, DefId, DefLoc};
const WORKSPACE: SourceRootId = SourceRootId(0);
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct MockDatabase { pub(crate) struct MockDatabase {
events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
@ -106,11 +108,11 @@ impl Default for MockDatabase {
runtime: salsa::Runtime::default(), runtime: salsa::Runtime::default(),
id_maps: Default::default(), id_maps: Default::default(),
}; };
db.query_mut(ra_db::SourceRootQuery)
.set(ra_db::WORKSPACE, Default::default());
db.query_mut(ra_db::CrateGraphQuery) db.query_mut(ra_db::CrateGraphQuery)
.set((), Default::default()); .set((), Default::default());
db.query_mut(ra_db::LibrariesQuery) db.query_mut(ra_db::LocalRootsQuery)
.set((), Default::default());
db.query_mut(ra_db::LibraryRootsQuery)
.set((), Default::default()); .set((), Default::default());
db db
} }
@ -163,7 +165,8 @@ salsa::database_storage! {
fn file_relative_path() for ra_db::FileRelativePathQuery; fn file_relative_path() for ra_db::FileRelativePathQuery;
fn file_source_root() for ra_db::FileSourceRootQuery; fn file_source_root() for ra_db::FileSourceRootQuery;
fn source_root() for ra_db::SourceRootQuery; fn source_root() for ra_db::SourceRootQuery;
fn libraries() for ra_db::LibrariesQuery; fn local_roots() for ra_db::LocalRootsQuery;
fn library_roots() for ra_db::LibraryRootsQuery;
fn crate_graph() for ra_db::CrateGraphQuery; fn crate_graph() for ra_db::CrateGraphQuery;
} }
impl ra_db::SyntaxDatabase { impl ra_db::SyntaxDatabase {

View file

@ -48,7 +48,8 @@ impl ServerWorldState {
let roots_to_scan = roots.len(); let roots_to_scan = roots.len();
let (mut vfs, roots) = Vfs::new(roots); let (mut vfs, roots) = Vfs::new(roots);
for r in roots { for r in roots {
change.add_root(SourceRootId(r.0)); let is_local = vfs.root2path(r).starts_with(&root);
change.add_root(SourceRootId(r.0), is_local);
} }
let mut crate_graph = CrateGraph::default(); let mut crate_graph = CrateGraph::default();