From b6ce7a6d344fa673addcd299cbb19b050625e04d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 10:26:24 +0300 Subject: make it compile --- crates/ra_analysis/src/db.rs | 3 +++ crates/ra_analysis/src/imp.rs | 9 +-------- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index b8d774eb5..9f39d3a59 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -61,7 +61,10 @@ salsa::database_storage! { pub(crate) struct RootDatabaseStorage for RootDatabase { impl ra_db::FilesDatabase { fn file_text() for ra_db::FileTextQuery; + fn file_relative_path() for ra_db::FileRelativePathQuery; fn file_source_root() for ra_db::FileSourceRootQuery; + fn source_root_files() for ra_db::SourceRootFilesQuery; + fn source_root_file_by_path() for ra_db::SourceRootFileByPathQuery; fn source_root() for ra_db::SourceRootQuery; fn libraries() for ra_db::LibrariesQuery; fn crate_graph() for ra_db::CrateGraphQuery; diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 0de0e2645..e2c20b0e3 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -51,9 +51,6 @@ impl AnalysisHostImpl { .set(file_id, Arc::new(text)) } if !(change.files_added.is_empty() && change.files_removed.is_empty()) { - let file_resolver = change - .file_resolver - .expect("change resolver when changing set of files"); let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE)); for (file_id, text) in change.files_added { self.db @@ -70,7 +67,6 @@ impl AnalysisHostImpl { .set(file_id, Arc::new(String::new())); source_root.files.remove(&file_id); } - source_root.file_resolver = file_resolver; self.db .query_mut(ra_db::SourceRootQuery) .set(WORKSPACE, Arc::new(source_root)) @@ -95,10 +91,7 @@ impl AnalysisHostImpl { .query_mut(ra_db::FileTextQuery) .set_constant(file_id, Arc::new(text)); } - let source_root = SourceRoot { - files, - file_resolver: library.file_resolver, - }; + let source_root = SourceRoot { files }; self.db .query_mut(ra_db::SourceRootQuery) .set(source_root_id, Arc::new(source_root)); -- cgit v1.2.3 From 85290bc1342560d5560f0b2151cff1c0c6dac155 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 12:20:54 +0300 Subject: switch analysis to vfs --- crates/ra_analysis/src/db.rs | 2 - crates/ra_analysis/src/imp.rs | 88 +++++++++++++++--------------- crates/ra_analysis/src/lib.rs | 96 +++++++++++++++++++++++++-------- crates/ra_analysis/src/mock_analysis.rs | 8 +-- 4 files changed, 121 insertions(+), 73 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 9f39d3a59..b79baf037 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -63,8 +63,6 @@ salsa::database_storage! { fn file_text() for ra_db::FileTextQuery; fn file_relative_path() for ra_db::FileRelativePathQuery; fn file_source_root() for ra_db::FileSourceRootQuery; - fn source_root_files() for ra_db::SourceRootFilesQuery; - fn source_root_file_by_path() for ra_db::SourceRootFileByPathQuery; fn source_root() for ra_db::SourceRootQuery; fn libraries() for ra_db::LibrariesQuery; fn crate_graph() for ra_db::CrateGraphQuery; diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index e2c20b0e3..51bcd5a73 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -12,7 +12,6 @@ use ra_syntax::{ }; use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase}; use rayon::prelude::*; -use rustc_hash::FxHashSet; use salsa::{Database, ParallelDatabase}; use hir::{ self, @@ -25,7 +24,7 @@ use crate::{ completion::{completions, CompletionItem}, db, symbol_index::{SymbolIndex, SymbolsDatabase}, - AnalysisChange, Cancelable, CrateId, Diagnostic, FileId, + AnalysisChange, RootChange, Cancelable, CrateId, Diagnostic, FileId, FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, ReferenceResolution, }; @@ -45,59 +44,22 @@ impl AnalysisHostImpl { log::info!("apply_change {:?}", change); // self.gc_syntax_trees(); + for (root_id, root_change) in change.roots_changed { + self.apply_root_change(root_id, root_change); + } for (file_id, text) in change.files_changed { self.db .query_mut(ra_db::FileTextQuery) .set(file_id, Arc::new(text)) } - if !(change.files_added.is_empty() && change.files_removed.is_empty()) { - let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE)); - for (file_id, text) in change.files_added { - self.db - .query_mut(ra_db::FileTextQuery) - .set(file_id, Arc::new(text)); - self.db - .query_mut(ra_db::FileSourceRootQuery) - .set(file_id, ra_db::WORKSPACE); - source_root.files.insert(file_id); - } - for file_id in change.files_removed { - self.db - .query_mut(ra_db::FileTextQuery) - .set(file_id, Arc::new(String::new())); - source_root.files.remove(&file_id); - } - self.db - .query_mut(ra_db::SourceRootQuery) - .set(WORKSPACE, Arc::new(source_root)) - } if !change.libraries_added.is_empty() { let mut libraries = Vec::clone(&self.db.libraries()); for library in change.libraries_added { - let source_root_id = SourceRootId(1 + libraries.len() as u32); - libraries.push(source_root_id); - let mut files = FxHashSet::default(); - for (file_id, text) in library.files { - files.insert(file_id); - log::debug!( - "library file: {:?} {:?}", - file_id, - library.file_resolver.debug_path(file_id) - ); - self.db - .query_mut(ra_db::FileSourceRootQuery) - .set_constant(file_id, source_root_id); - self.db - .query_mut(ra_db::FileTextQuery) - .set_constant(file_id, Arc::new(text)); - } - let source_root = SourceRoot { files }; + libraries.push(library.root_id); self.db .query_mut(ra_db::SourceRootQuery) - .set(source_root_id, Arc::new(source_root)); - self.db - .query_mut(crate::symbol_index::LibrarySymbolsQuery) - .set(source_root_id, Arc::new(library.symbol_index)); + .set(library.root_id, Default::default()); + self.apply_root_change(library.root_id, library.root_change); } self.db .query_mut(ra_db::LibrariesQuery) @@ -110,6 +72,34 @@ impl AnalysisHostImpl { } } + fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { + let mut source_root = SourceRoot::clone(&self.db.source_root(root_id)); + for add_file in root_change.added { + self.db + .query_mut(ra_db::FileTextQuery) + .set(add_file.file_id, add_file.text); + self.db + .query_mut(ra_db::FileRelativePathQuery) + .set(add_file.file_id, add_file.path.clone()); + self.db + .query_mut(ra_db::FileSourceRootQuery) + .set(add_file.file_id, root_id); + source_root.files.insert(add_file.path, add_file.file_id); + } + for remove_file in root_change.removed { + self.db + .query_mut(ra_db::FileTextQuery) + .set(remove_file.file_id, Default::default()); + self.db + .query_mut(ra_db::FileRelativePathQuery) + .set(remove_file.file_id, Default::default()); + source_root.files.remove(&remove_file.path); + } + self.db + .query_mut(ra_db::SourceRootQuery) + .set(root_id, Arc::new(source_root)); + } + #[allow(unused)] /// Ideally, we should call this function from time to time to collect heavy /// syntax trees. However, if we actually do that, everything is recomputed @@ -156,7 +146,13 @@ impl AnalysisImpl { .map(|&lib_id| self.db.library_symbols(lib_id)) .collect() } else { - let files = &self.db.source_root(WORKSPACE).files; + let files: Vec = self + .db + .source_root(WORKSPACE) + .files + .values() + .map(|&it| it) + .collect(); /// Need to wrap Snapshot to provide `Clone` impl for `map_with` struct Snap(salsa::Snapshot); diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 22fff71ab..bfc4e0f17 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -18,9 +18,9 @@ pub mod mock_analysis; use std::{fmt, sync::Arc}; +use rustc_hash::FxHashMap; use ra_syntax::{SourceFileNode, TextRange, TextUnit}; use ra_text_edit::AtomTextEdit; -use ra_db::FileResolverImp; use rayon::prelude::*; use relative_path::RelativePathBuf; @@ -39,28 +39,53 @@ pub use hir::FnSignatureInfo; pub use ra_db::{ Canceled, Cancelable, FilePosition, - CrateGraph, CrateId, FileId, FileResolver + CrateGraph, CrateId, SourceRootId, FileId, FileResolver, + WORKSPACE }; #[derive(Default)] pub struct AnalysisChange { - files_added: Vec<(FileId, String)>, + roots_changed: FxHashMap, files_changed: Vec<(FileId, String)>, - files_removed: Vec<(FileId)>, libraries_added: Vec, crate_graph: Option, - file_resolver: Option, +} + +#[derive(Default)] +struct RootChange { + added: Vec, + removed: Vec, +} + +#[derive(Debug)] +struct AddFile { + file_id: FileId, + path: RelativePathBuf, + text: Arc, +} + +#[derive(Debug)] +struct RemoveFile { + file_id: FileId, + path: RelativePathBuf, } impl fmt::Debug for AnalysisChange { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("AnalysisChange") - .field("files_added", &self.files_added.len()) + .field("roots_changed", &self.roots_changed) .field("files_changed", &self.files_changed.len()) - .field("files_removed", &self.files_removed.len()) .field("libraries_added", &self.libraries_added.len()) .field("crate_graph", &self.crate_graph) - .field("file_resolver", &self.file_resolver) + .finish() + } +} + +impl fmt::Debug for RootChange { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("AnalysisChange") + .field("added", &self.added.len()) + .field("removed", &self.removed.len()) .finish() } } @@ -69,14 +94,34 @@ impl AnalysisChange { pub fn new() -> AnalysisChange { AnalysisChange::default() } - pub fn add_file(&mut self, file_id: FileId, text: String) { - self.files_added.push((file_id, text)) + pub fn add_file( + &mut self, + root_id: SourceRootId, + file_id: FileId, + path: RelativePathBuf, + text: Arc, + ) { + let file = AddFile { + file_id, + path, + text, + }; + self.roots_changed + .entry(root_id) + .or_default() + .added + .push(file); } pub fn change_file(&mut self, file_id: FileId, new_text: String) { self.files_changed.push((file_id, new_text)) } - pub fn remove_file(&mut self, file_id: FileId) { - self.files_removed.push(file_id) + pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) { + let file = RemoveFile { file_id, path }; + self.roots_changed + .entry(root_id) + .or_default() + .removed + .push(file); } pub fn add_library(&mut self, data: LibraryData) { self.libraries_added.push(data) @@ -84,9 +129,6 @@ impl AnalysisChange { pub fn set_crate_graph(&mut self, graph: CrateGraph) { self.crate_graph = Some(graph); } - pub fn set_file_resolver(&mut self, file_resolver: Arc) { - self.file_resolver = Some(FileResolverImp::new(file_resolver)); - } } /// `AnalysisHost` stores the current state of the world. @@ -313,20 +355,32 @@ impl Analysis { #[derive(Debug)] pub struct LibraryData { - files: Vec<(FileId, String)>, - file_resolver: FileResolverImp, + root_id: SourceRootId, + root_change: RootChange, symbol_index: SymbolIndex, } impl LibraryData { - pub fn prepare(files: Vec<(FileId, String)>, file_resolver: Arc) -> LibraryData { - let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, text)| { + pub fn prepare( + root_id: SourceRootId, + files: Vec<(FileId, RelativePathBuf, Arc)>, + ) -> LibraryData { + let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, _, text)| { let file = SourceFileNode::parse(text); (*file_id, file) })); + let mut root_change = RootChange::default(); + root_change.added = files + .into_iter() + .map(|(file_id, path, text)| AddFile { + file_id, + path, + text, + }) + .collect(); LibraryData { - files, - file_resolver: FileResolverImp::new(file_resolver), + root_id, + root_change, symbol_index, } } diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs index 0d9a7a147..691af4a48 100644 --- a/crates/ra_analysis/src/mock_analysis.rs +++ b/crates/ra_analysis/src/mock_analysis.rs @@ -4,7 +4,7 @@ use relative_path::{RelativePathBuf}; use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; use ra_db::mock::FileMap; -use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition}; +use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, WORKSPACE}; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. @@ -82,10 +82,10 @@ impl MockAnalysis { for (path, contents) in self.files.into_iter() { assert!(path.starts_with('/')); let path = RelativePathBuf::from_path(&path[1..]).unwrap(); - let file_id = file_map.add(path); - change.add_file(file_id, contents); + let file_id = file_map.add(path.clone()); + change.add_file(WORKSPACE, file_id, path, Arc::new(contents)); } - change.set_file_resolver(Arc::new(file_map)); + // change.set_file_resolver(Arc::new(file_map)); host.apply_change(change); host } -- cgit v1.2.3 From 79596abcaf50019810f7fa01a264100472359f8a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 12:41:23 +0300 Subject: dead import --- crates/ra_analysis/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index bfc4e0f17..b806c974d 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -39,8 +39,7 @@ pub use hir::FnSignatureInfo; pub use ra_db::{ Canceled, Cancelable, FilePosition, - CrateGraph, CrateId, SourceRootId, FileId, FileResolver, - WORKSPACE + CrateGraph, CrateId, SourceRootId, FileId, WORKSPACE }; #[derive(Default)] -- cgit v1.2.3 From a5ef8ad05b7c1f7148c59814b55d641fd75aff75 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 15:04:15 +0300 Subject: swtich lsp server to vfs --- crates/ra_analysis/src/imp.rs | 9 ++++++--- crates/ra_analysis/src/lib.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 51bcd5a73..54f38b285 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -43,14 +43,17 @@ impl AnalysisHostImpl { pub fn apply_change(&mut self, change: AnalysisChange) { log::info!("apply_change {:?}", change); // self.gc_syntax_trees(); + for root_id in change.new_roots { + self.db + .query_mut(ra_db::SourceRootQuery) + .set(root_id, Default::default()); + } for (root_id, root_change) in change.roots_changed { self.apply_root_change(root_id, root_change); } for (file_id, text) in change.files_changed { - self.db - .query_mut(ra_db::FileTextQuery) - .set(file_id, Arc::new(text)) + self.db.query_mut(ra_db::FileTextQuery).set(file_id, text) } if !change.libraries_added.is_empty() { let mut libraries = Vec::clone(&self.db.libraries()); diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index b806c974d..8882feca3 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -44,8 +44,9 @@ pub use ra_db::{ #[derive(Default)] pub struct AnalysisChange { + new_roots: Vec, roots_changed: FxHashMap, - files_changed: Vec<(FileId, String)>, + files_changed: Vec<(FileId, Arc)>, libraries_added: Vec, crate_graph: Option, } @@ -93,6 +94,9 @@ impl AnalysisChange { pub fn new() -> AnalysisChange { AnalysisChange::default() } + pub fn add_root(&mut self, root_id: SourceRootId) { + self.new_roots.push(root_id); + } pub fn add_file( &mut self, root_id: SourceRootId, @@ -111,7 +115,7 @@ impl AnalysisChange { .added .push(file); } - pub fn change_file(&mut self, file_id: FileId, new_text: String) { + pub fn change_file(&mut self, file_id: FileId, new_text: Arc) { self.files_changed.push((file_id, new_text)) } pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) { -- cgit v1.2.3 From 7b6bafa631e6272946da568e9da7c3adc01ba625 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 15:40:42 +0300 Subject: fix syc --- crates/ra_analysis/src/lib.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 8882feca3..300dfc5dd 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -73,6 +73,7 @@ struct RemoveFile { impl fmt::Debug for AnalysisChange { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("AnalysisChange") + .field("new_roots", &self.new_roots) .field("roots_changed", &self.roots_changed) .field("files_changed", &self.files_changed.len()) .field("libraries_added", &self.libraries_added.len()) -- cgit v1.2.3 From e6465e7e2a7e136edd652d5f4c93b961dd652cbc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 16:13:16 +0300 Subject: index all local crates --- crates/ra_analysis/src/db.rs | 9 ++++---- crates/ra_analysis/src/imp.rs | 39 ++++++++++++++++----------------- crates/ra_analysis/src/lib.rs | 2 +- crates/ra_analysis/src/mock_analysis.rs | 6 +++-- 4 files changed, 29 insertions(+), 27 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index b79baf037..3d0f13f34 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -30,11 +30,11 @@ impl Default for RootDatabase { runtime: salsa::Runtime::default(), id_maps: Default::default(), }; - db.query_mut(ra_db::SourceRootQuery) - .set(ra_db::WORKSPACE, Default::default()); db.query_mut(ra_db::CrateGraphQuery) .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()); db } @@ -64,7 +64,8 @@ salsa::database_storage! { fn file_relative_path() for ra_db::FileRelativePathQuery; fn file_source_root() for ra_db::FileSourceRootQuery; 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; } impl ra_db::SyntaxDatabase { diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 54f38b285..46169d863 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -10,7 +10,7 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNodeRef, TextRange, TextUnit, }; -use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase}; +use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; use rayon::prelude::*; use salsa::{Database, ParallelDatabase}; use hir::{ @@ -56,7 +56,7 @@ impl AnalysisHostImpl { self.db.query_mut(ra_db::FileTextQuery).set(file_id, text) } if !change.libraries_added.is_empty() { - let mut libraries = Vec::clone(&self.db.libraries()); + let mut libraries = Vec::clone(&self.db.library_roots()); for library in change.libraries_added { libraries.push(library.root_id); self.db @@ -65,7 +65,7 @@ impl AnalysisHostImpl { self.apply_root_change(library.root_id, library.root_change); } self.db - .query_mut(ra_db::LibrariesQuery) + .query_mut(ra_db::LibraryRootsQuery) .set((), Arc::new(libraries)); } if let Some(crate_graph) = change.crate_graph { @@ -142,27 +142,26 @@ impl AnalysisImpl { self.db.file_lines(file_id) } pub fn world_symbols(&self, query: Query) -> Cancelable> { + /// Need to wrap Snapshot to provide `Clone` impl for `map_with` + struct Snap(salsa::Snapshot); + impl Clone for Snap { + fn clone(&self) -> Snap { + Snap(self.0.snapshot()) + } + } + let buf: Vec> = if query.libs { + let snap = Snap(self.db.snapshot()); self.db - .libraries() - .iter() - .map(|&lib_id| self.db.library_symbols(lib_id)) + .library_roots() + .par_iter() + .map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id)) .collect() } else { - let files: Vec = self - .db - .source_root(WORKSPACE) - .files - .values() - .map(|&it| it) - .collect(); - - /// Need to wrap Snapshot to provide `Clone` impl for `map_with` - struct Snap(salsa::Snapshot); - impl Clone for Snap { - fn clone(&self) -> Snap { - Snap(self.0.snapshot()) - } + let mut files = Vec::new(); + for &root in self.db.local_roots().iter() { + let sr = self.db.source_root(root); + files.extend(sr.files.values().map(|&it| it)) } let snap = Snap(self.db.snapshot()); diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 300dfc5dd..0db3c3479 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -39,7 +39,7 @@ pub use hir::FnSignatureInfo; pub use ra_db::{ Canceled, Cancelable, FilePosition, - CrateGraph, CrateId, SourceRootId, FileId, WORKSPACE + CrateGraph, CrateId, SourceRootId, FileId }; #[derive(Default)] diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs index 691af4a48..0c042e672 100644 --- a/crates/ra_analysis/src/mock_analysis.rs +++ b/crates/ra_analysis/src/mock_analysis.rs @@ -4,7 +4,7 @@ use relative_path::{RelativePathBuf}; use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; use ra_db::mock::FileMap; -use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, WORKSPACE}; +use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, SourceRootId}; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. @@ -78,12 +78,14 @@ impl MockAnalysis { pub fn analysis_host(self) -> AnalysisHost { let mut host = AnalysisHost::default(); let mut file_map = FileMap::default(); + let source_root = SourceRootId(0); let mut change = AnalysisChange::new(); + change.add_root(source_root); for (path, contents) in self.files.into_iter() { assert!(path.starts_with('/')); let path = RelativePathBuf::from_path(&path[1..]).unwrap(); let file_id = file_map.add(path.clone()); - change.add_file(WORKSPACE, file_id, path, Arc::new(contents)); + change.add_file(source_root, file_id, path, Arc::new(contents)); } // change.set_file_resolver(Arc::new(file_map)); host.apply_change(change); -- cgit v1.2.3 From 2fe41574a1695a6608d738f40ec51bc61fc7604a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 16:19:53 +0300 Subject: fix tests --- crates/ra_analysis/src/imp.rs | 15 ++++++++++++--- crates/ra_analysis/src/lib.rs | 6 +++--- crates/ra_analysis/src/mock_analysis.rs | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 46169d863..9e441ca79 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -43,10 +43,19 @@ impl AnalysisHostImpl { pub fn apply_change(&mut self, change: AnalysisChange) { log::info!("apply_change {:?}", change); // 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 + .query_mut(ra_db::SourceRootQuery) + .set(root_id, Default::default()); + if is_local { + local_roots.push(root_id); + } + } self.db - .query_mut(ra_db::SourceRootQuery) - .set(root_id, Default::default()); + .query_mut(ra_db::LocalRootsQuery) + .set((), Arc::new(local_roots)); } for (root_id, root_change) in change.roots_changed { diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 0db3c3479..a1d462528 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -44,7 +44,7 @@ pub use ra_db::{ #[derive(Default)] pub struct AnalysisChange { - new_roots: Vec, + new_roots: Vec<(SourceRootId, bool)>, roots_changed: FxHashMap, files_changed: Vec<(FileId, Arc)>, libraries_added: Vec, @@ -95,8 +95,8 @@ impl AnalysisChange { pub fn new() -> AnalysisChange { AnalysisChange::default() } - pub fn add_root(&mut self, root_id: SourceRootId) { - self.new_roots.push(root_id); + pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) { + self.new_roots.push((root_id, is_local)); } pub fn add_file( &mut self, diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs index 0c042e672..7cbdfb953 100644 --- a/crates/ra_analysis/src/mock_analysis.rs +++ b/crates/ra_analysis/src/mock_analysis.rs @@ -80,7 +80,7 @@ impl MockAnalysis { let mut file_map = FileMap::default(); let source_root = SourceRootId(0); let mut change = AnalysisChange::new(); - change.add_root(source_root); + change.add_root(source_root, true); for (path, contents) in self.files.into_iter() { assert!(path.starts_with('/')); let path = RelativePathBuf::from_path(&path[1..]).unwrap(); -- cgit v1.2.3 From 97812c192a2f650520a6b73f9e3d49919515947d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 20 Dec 2018 12:02:57 +0300 Subject: Restore library symbols --- crates/ra_analysis/src/imp.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 9e441ca79..2d00d23be 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -23,7 +23,7 @@ use hir::{ use crate::{ completion::{completions, CompletionItem}, db, - symbol_index::{SymbolIndex, SymbolsDatabase}, + symbol_index::{SymbolIndex, SymbolsDatabase, LibrarySymbolsQuery}, AnalysisChange, RootChange, Cancelable, CrateId, Diagnostic, FileId, FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, ReferenceResolution, @@ -71,6 +71,9 @@ impl AnalysisHostImpl { self.db .query_mut(ra_db::SourceRootQuery) .set(library.root_id, Default::default()); + self.db + .query_mut(LibrarySymbolsQuery) + .set(library.root_id, Arc::new(library.symbol_index)); self.apply_root_change(library.root_id, library.root_change); } self.db -- cgit v1.2.3 From 6782fe2a5b84315f66a227b035c6beae7834f0b0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 20 Dec 2018 12:05:29 +0300 Subject: Treat --- crates/ra_analysis/src/imp.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 2d00d23be..4ef2129c3 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -73,8 +73,8 @@ impl AnalysisHostImpl { .set(library.root_id, Default::default()); self.db .query_mut(LibrarySymbolsQuery) - .set(library.root_id, Arc::new(library.symbol_index)); - self.apply_root_change(library.root_id, library.root_change); + .set_constant(library.root_id, Arc::new(library.symbol_index)); + self.apply_root_change_constant(library.root_id, library.root_change); } self.db .query_mut(ra_db::LibraryRootsQuery) @@ -115,6 +115,34 @@ impl AnalysisHostImpl { .set(root_id, Arc::new(source_root)); } + fn apply_root_change_constant(&mut self, root_id: SourceRootId, root_change: RootChange) { + let mut source_root = SourceRoot::clone(&self.db.source_root(root_id)); + for add_file in root_change.added { + self.db + .query_mut(ra_db::FileTextQuery) + .set_constant(add_file.file_id, add_file.text); + self.db + .query_mut(ra_db::FileRelativePathQuery) + .set_constant(add_file.file_id, add_file.path.clone()); + self.db + .query_mut(ra_db::FileSourceRootQuery) + .set_constant(add_file.file_id, root_id); + source_root.files.insert(add_file.path, add_file.file_id); + } + for remove_file in root_change.removed { + self.db + .query_mut(ra_db::FileTextQuery) + .set_constant(remove_file.file_id, Default::default()); + self.db + .query_mut(ra_db::FileRelativePathQuery) + .set_constant(remove_file.file_id, Default::default()); + source_root.files.remove(&remove_file.path); + } + self.db + .query_mut(ra_db::SourceRootQuery) + .set_constant(root_id, Arc::new(source_root)); + } + #[allow(unused)] /// Ideally, we should call this function from time to time to collect heavy /// syntax trees. However, if we actually do that, everything is recomputed -- cgit v1.2.3 From a084412f0698d5f54d586f707930e141c88b0673 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 20 Dec 2018 12:06:23 +0300 Subject: set symbol index as const --- crates/ra_analysis/src/imp.rs | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 4ef2129c3..c4291885a 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -74,7 +74,7 @@ impl AnalysisHostImpl { self.db .query_mut(LibrarySymbolsQuery) .set_constant(library.root_id, Arc::new(library.symbol_index)); - self.apply_root_change_constant(library.root_id, library.root_change); + self.apply_root_change(library.root_id, library.root_change); } self.db .query_mut(ra_db::LibraryRootsQuery) @@ -115,34 +115,6 @@ impl AnalysisHostImpl { .set(root_id, Arc::new(source_root)); } - fn apply_root_change_constant(&mut self, root_id: SourceRootId, root_change: RootChange) { - let mut source_root = SourceRoot::clone(&self.db.source_root(root_id)); - for add_file in root_change.added { - self.db - .query_mut(ra_db::FileTextQuery) - .set_constant(add_file.file_id, add_file.text); - self.db - .query_mut(ra_db::FileRelativePathQuery) - .set_constant(add_file.file_id, add_file.path.clone()); - self.db - .query_mut(ra_db::FileSourceRootQuery) - .set_constant(add_file.file_id, root_id); - source_root.files.insert(add_file.path, add_file.file_id); - } - for remove_file in root_change.removed { - self.db - .query_mut(ra_db::FileTextQuery) - .set_constant(remove_file.file_id, Default::default()); - self.db - .query_mut(ra_db::FileRelativePathQuery) - .set_constant(remove_file.file_id, Default::default()); - source_root.files.remove(&remove_file.path); - } - self.db - .query_mut(ra_db::SourceRootQuery) - .set_constant(root_id, Arc::new(source_root)); - } - #[allow(unused)] /// Ideally, we should call this function from time to time to collect heavy /// syntax trees. However, if we actually do that, everything is recomputed -- cgit v1.2.3