diff options
author | Aleksey Kladov <[email protected]> | 2020-06-11 10:04:09 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-23 16:51:06 +0100 |
commit | dad1333b48c38bc7a5628fc0ff5304d003776a85 (patch) | |
tree | 29be52a980b4cae72f46a48c48135a15e31641e0 /crates/ra_ide | |
parent | 7aa66371ee3e8b31217513204c8b4f683584419d (diff) |
New VFS
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 17 | ||||
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 17 | ||||
-rw-r--r-- | crates/ra_ide/src/parent_module.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/ssr.rs | 2 |
5 files changed, 20 insertions, 22 deletions
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; | |||
47 | use ra_cfg::CfgOptions; | 47 | use ra_cfg::CfgOptions; |
48 | use ra_db::{ | 48 | use ra_db::{ |
49 | salsa::{self, ParallelDatabase}, | 49 | salsa::{self, ParallelDatabase}, |
50 | CheckCanceled, Env, FileLoader, SourceDatabase, | 50 | CheckCanceled, Env, FileLoader, FileSet, SourceDatabase, VfsPath, |
51 | }; | 51 | }; |
52 | use ra_ide_db::{ | 52 | use ra_ide_db::{ |
53 | symbol_index::{self, FileSymbol}, | 53 | symbol_index::{self, FileSymbol}, |
@@ -78,7 +78,8 @@ pub use crate::{ | |||
78 | pub use hir::Documentation; | 78 | pub use hir::Documentation; |
79 | pub use ra_assists::{Assist, AssistConfig, AssistId, ResolvedAssist}; | 79 | pub use ra_assists::{Assist, AssistConfig, AssistId, ResolvedAssist}; |
80 | pub use ra_db::{ | 80 | pub use ra_db::{ |
81 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, | 81 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, |
82 | SourceRootId, | ||
82 | }; | 83 | }; |
83 | pub use ra_ide_db::{ | 84 | pub use ra_ide_db::{ |
84 | change::AnalysisChange, | 85 | change::AnalysisChange, |
@@ -212,11 +213,14 @@ impl Analysis { | |||
212 | // `AnalysisHost` for creating a fully-featured analysis. | 213 | // `AnalysisHost` for creating a fully-featured analysis. |
213 | pub fn from_single_file(text: String) -> (Analysis, FileId) { | 214 | pub fn from_single_file(text: String) -> (Analysis, FileId) { |
214 | let mut host = AnalysisHost::default(); | 215 | let mut host = AnalysisHost::default(); |
215 | let source_root = SourceRootId(0); | 216 | let file_id = FileId(0); |
217 | let mut file_set = FileSet::default(); | ||
218 | file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string())); | ||
219 | let source_root = SourceRoot::new_local(file_set); | ||
220 | |||
216 | let mut change = AnalysisChange::new(); | 221 | let mut change = AnalysisChange::new(); |
217 | change.add_root(source_root, true); | 222 | change.set_roots(vec![source_root]); |
218 | let mut crate_graph = CrateGraph::default(); | 223 | let mut crate_graph = CrateGraph::default(); |
219 | let file_id = FileId(0); | ||
220 | // FIXME: cfg options | 224 | // FIXME: cfg options |
221 | // Default to enable test for single file. | 225 | // Default to enable test for single file. |
222 | let mut cfg_options = CfgOptions::default(); | 226 | let mut cfg_options = CfgOptions::default(); |
@@ -228,9 +232,8 @@ impl Analysis { | |||
228 | cfg_options, | 232 | cfg_options, |
229 | Env::default(), | 233 | Env::default(), |
230 | Default::default(), | 234 | Default::default(), |
231 | Default::default(), | ||
232 | ); | 235 | ); |
233 | change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); | 236 | change.change_file(file_id, Some(Arc::new(text))); |
234 | change.set_crate_graph(crate_graph); | 237 | change.set_crate_graph(crate_graph); |
235 | host.apply_change(change); | 238 | host.apply_change(change); |
236 | (host.analysis(), file_id) | 239 | (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 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | use std::{str::FromStr, sync::Arc}; | |
3 | use std::str::FromStr; | ||
4 | use std::sync::Arc; | ||
5 | 3 | ||
6 | use ra_cfg::CfgOptions; | 4 | use ra_cfg::CfgOptions; |
7 | use ra_db::{CrateName, Env}; | 5 | use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; |
8 | use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER}; | 6 | use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER}; |
9 | 7 | ||
10 | use crate::{ | 8 | use crate::{ |
11 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, | 9 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, |
12 | SourceRootId, | ||
13 | }; | 10 | }; |
14 | 11 | ||
15 | #[derive(Debug)] | 12 | #[derive(Debug)] |
@@ -159,9 +156,8 @@ impl MockAnalysis { | |||
159 | } | 156 | } |
160 | pub fn analysis_host(self) -> AnalysisHost { | 157 | pub fn analysis_host(self) -> AnalysisHost { |
161 | let mut host = AnalysisHost::default(); | 158 | let mut host = AnalysisHost::default(); |
162 | let source_root = SourceRootId(0); | ||
163 | let mut change = AnalysisChange::new(); | 159 | let mut change = AnalysisChange::new(); |
164 | change.add_root(source_root, true); | 160 | let mut file_set = FileSet::default(); |
165 | let mut crate_graph = CrateGraph::default(); | 161 | let mut crate_graph = CrateGraph::default(); |
166 | let mut root_crate = None; | 162 | let mut root_crate = None; |
167 | for (i, data) in self.files.into_iter().enumerate() { | 163 | for (i, data) in self.files.into_iter().enumerate() { |
@@ -179,7 +175,6 @@ impl MockAnalysis { | |||
179 | cfg_options, | 175 | cfg_options, |
180 | env, | 176 | env, |
181 | Default::default(), | 177 | Default::default(), |
182 | Default::default(), | ||
183 | )); | 178 | )); |
184 | } else if path.ends_with("/lib.rs") { | 179 | } else if path.ends_with("/lib.rs") { |
185 | let base = &path[..path.len() - "/lib.rs".len()]; | 180 | let base = &path[..path.len() - "/lib.rs".len()]; |
@@ -191,7 +186,6 @@ impl MockAnalysis { | |||
191 | cfg_options, | 186 | cfg_options, |
192 | env, | 187 | env, |
193 | Default::default(), | 188 | Default::default(), |
194 | Default::default(), | ||
195 | ); | 189 | ); |
196 | if let Some(root_crate) = root_crate { | 190 | if let Some(root_crate) = root_crate { |
197 | crate_graph | 191 | crate_graph |
@@ -199,9 +193,12 @@ impl MockAnalysis { | |||
199 | .unwrap(); | 193 | .unwrap(); |
200 | } | 194 | } |
201 | } | 195 | } |
202 | change.add_file(source_root, file_id, path.into(), Arc::new(data.content().to_owned())); | 196 | let path = VfsPath::new_virtual_path(path.to_string()); |
197 | file_set.insert(file_id, path); | ||
198 | change.change_file(file_id, Some(Arc::new(data.content().to_owned()))); | ||
203 | } | 199 | } |
204 | change.set_crate_graph(crate_graph); | 200 | change.set_crate_graph(crate_graph); |
201 | change.set_roots(vec![SourceRoot::new_local(file_set)]); | ||
205 | host.apply_change(change); | 202 | host.apply_change(change); |
206 | host | 203 | host |
207 | } | 204 | } |
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 { | |||
145 | CfgOptions::default(), | 145 | CfgOptions::default(), |
146 | Env::default(), | 146 | Env::default(), |
147 | Default::default(), | 147 | Default::default(), |
148 | Default::default(), | ||
149 | ); | 148 | ); |
150 | let mut change = AnalysisChange::new(); | 149 | let mut change = AnalysisChange::new(); |
151 | change.set_crate_graph(crate_graph); | 150 | 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 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{Module, ModuleDef, ModuleSource, Semantics}; | 3 | use hir::{Module, ModuleDef, ModuleSource, Semantics}; |
4 | use ra_db::{RelativePathBuf, SourceDatabaseExt}; | 4 | use ra_db::SourceDatabaseExt; |
5 | use ra_ide_db::{ | 5 | use ra_ide_db::{ |
6 | defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, | 6 | defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass}, |
7 | RootDatabase, | 7 | RootDatabase, |
@@ -109,9 +109,8 @@ fn rename_mod( | |||
109 | let file_id = src.file_id.original_file(db); | 109 | let file_id = src.file_id.original_file(db); |
110 | match src.value { | 110 | match src.value { |
111 | ModuleSource::SourceFile(..) => { | 111 | ModuleSource::SourceFile(..) => { |
112 | let mod_path: RelativePathBuf = db.file_relative_path(file_id); | ||
113 | // mod is defined in path/to/dir/mod.rs | 112 | // mod is defined in path/to/dir/mod.rs |
114 | let dst = if mod_path.file_stem() == Some("mod") { | 113 | let dst = if module.is_mod_rs(db) { |
115 | format!("../{}/mod.rs", new_name) | 114 | format!("../{}/mod.rs", new_name) |
116 | } else { | 115 | } else { |
117 | format!("{}.rs", new_name) | 116 | 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( | |||
41 | match_finder.add_rule(rule); | 41 | match_finder.add_rule(rule); |
42 | for &root in db.local_roots().iter() { | 42 | for &root in db.local_roots().iter() { |
43 | let sr = db.source_root(root); | 43 | let sr = db.source_root(root); |
44 | for file_id in sr.walk() { | 44 | for file_id in sr.iter() { |
45 | if let Some(edit) = match_finder.edits_for_file(file_id) { | 45 | if let Some(edit) = match_finder.edits_for_file(file_id) { |
46 | edits.push(SourceFileEdit { file_id, edit }); | 46 | edits.push(SourceFileEdit { file_id, edit }); |
47 | } | 47 | } |