From dad1333b48c38bc7a5628fc0ff5304d003776a85 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 11 Jun 2020 11:04:09 +0200 Subject: New VFS --- crates/ra_ide/src/lib.rs | 17 ++++++++++------- crates/ra_ide/src/mock_analysis.rs | 17 +++++++---------- crates/ra_ide/src/parent_module.rs | 1 - crates/ra_ide/src/references/rename.rs | 5 ++--- crates/ra_ide/src/ssr.rs | 2 +- 5 files changed, 20 insertions(+), 22 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 47823718f..ecac5134e 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -47,7 +47,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; use ra_db::{ salsa::{self, ParallelDatabase}, - CheckCanceled, Env, FileLoader, SourceDatabase, + CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, }; use ra_ide_db::{ symbol_index::{self, FileSymbol}, @@ -78,7 +78,8 @@ pub use crate::{ pub use hir::Documentation; pub use ra_assists::{Assist, AssistConfig, AssistId, ResolvedAssist}; pub use ra_db::{ - Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, + Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, + SourceRootId, }; pub use ra_ide_db::{ change::AnalysisChange, @@ -212,11 +213,14 @@ impl Analysis { // `AnalysisHost` for creating a fully-featured analysis. pub fn from_single_file(text: String) -> (Analysis, FileId) { let mut host = AnalysisHost::default(); - let source_root = SourceRootId(0); + let file_id = FileId(0); + let mut file_set = FileSet::default(); + file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string())); + let source_root = SourceRoot::new_local(file_set); + let mut change = AnalysisChange::new(); - change.add_root(source_root, true); + change.set_roots(vec![source_root]); let mut crate_graph = CrateGraph::default(); - let file_id = FileId(0); // FIXME: cfg options // Default to enable test for single file. let mut cfg_options = CfgOptions::default(); @@ -228,9 +232,8 @@ impl Analysis { cfg_options, Env::default(), Default::default(), - Default::default(), ); - change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); + change.change_file(file_id, Some(Arc::new(text))); change.set_crate_graph(crate_graph); host.apply_change(change); (host.analysis(), file_id) diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 76910d09b..58fafecab 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -1,15 +1,12 @@ //! FIXME: write short doc here - -use std::str::FromStr; -use std::sync::Arc; +use std::{str::FromStr, sync::Arc}; use ra_cfg::CfgOptions; -use ra_db::{CrateName, Env}; +use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER}; use crate::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, - SourceRootId, }; #[derive(Debug)] @@ -159,9 +156,8 @@ impl MockAnalysis { } pub fn analysis_host(self) -> AnalysisHost { let mut host = AnalysisHost::default(); - let source_root = SourceRootId(0); let mut change = AnalysisChange::new(); - change.add_root(source_root, true); + let mut file_set = FileSet::default(); let mut crate_graph = CrateGraph::default(); let mut root_crate = None; for (i, data) in self.files.into_iter().enumerate() { @@ -179,7 +175,6 @@ impl MockAnalysis { cfg_options, env, Default::default(), - Default::default(), )); } else if path.ends_with("/lib.rs") { let base = &path[..path.len() - "/lib.rs".len()]; @@ -191,7 +186,6 @@ impl MockAnalysis { cfg_options, env, Default::default(), - Default::default(), ); if let Some(root_crate) = root_crate { crate_graph @@ -199,9 +193,12 @@ impl MockAnalysis { .unwrap(); } } - change.add_file(source_root, file_id, path.into(), Arc::new(data.content().to_owned())); + let path = VfsPath::new_virtual_path(path.to_string()); + file_set.insert(file_id, path); + change.change_file(file_id, Some(Arc::new(data.content().to_owned()))); } change.set_crate_graph(crate_graph); + change.set_roots(vec![SourceRoot::new_local(file_set)]); host.apply_change(change); host } diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index fa1535da5..bc7f65470 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs @@ -145,7 +145,6 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), - Default::default(), ); let mut change = AnalysisChange::new(); change.set_crate_graph(crate_graph); diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 99c2581b7..6edf565b5 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -1,7 +1,7 @@ //! FIXME: write short doc here use hir::{Module, ModuleDef, ModuleSource, Semantics}; -use ra_db::{RelativePathBuf, SourceDatabaseExt}; +use ra_db::SourceDatabaseExt; use ra_ide_db::{ defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, RootDatabase, @@ -109,9 +109,8 @@ fn rename_mod( let file_id = src.file_id.original_file(db); match src.value { ModuleSource::SourceFile(..) => { - let mod_path: RelativePathBuf = db.file_relative_path(file_id); // mod is defined in path/to/dir/mod.rs - let dst = if mod_path.file_stem() == Some("mod") { + let dst = if module.is_mod_rs(db) { format!("../{}/mod.rs", new_name) } else { format!("{}.rs", new_name) diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 03f18c617..6cb96608b 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -41,7 +41,7 @@ pub fn parse_search_replace( match_finder.add_rule(rule); for &root in db.local_roots().iter() { let sr = db.source_root(root); - for file_id in sr.walk() { + for file_id in sr.iter() { if let Some(edit) = match_finder.edits_for_file(file_id) { edits.push(SourceFileEdit { file_id, edit }); } -- cgit v1.2.3