Skip to content

Commit 0c12c4f

Browse files
bors[bot]matklad
andauthored
Merge #4976
4976: New VFS r=matklad a=matklad Still a draft, but mostly working already. Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 7aa6637 + dad1333 commit 0c12c4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1026
-999
lines changed

Cargo.lock

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/paths/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! relative paths.
33
use std::{
44
convert::{TryFrom, TryInto},
5-
io, ops,
5+
ops,
66
path::{Component, Path, PathBuf},
77
};
88

@@ -46,9 +46,6 @@ impl TryFrom<&str> for AbsPathBuf {
4646
}
4747

4848
impl AbsPathBuf {
49-
pub fn canonicalized(path: &Path) -> io::Result<AbsPathBuf> {
50-
path.canonicalize().map(|it| AbsPathBuf::try_from(it).unwrap())
51-
}
5249
pub fn as_path(&self) -> &AbsPath {
5350
AbsPath::new_unchecked(self.0.as_path())
5451
}

crates/ra_assists/src/tests.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
mod generated;
22

3-
use std::sync::Arc;
4-
53
use hir::Semantics;
64
use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
7-
use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
5+
use ra_ide_db::RootDatabase;
86
use ra_syntax::TextRange;
97
use test_utils::{
108
assert_eq_text, extract_offset, extract_range, extract_range_or_offset, RangeOrOffset,
@@ -13,11 +11,7 @@ use test_utils::{
1311
use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists};
1412

1513
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
16-
let (mut db, file_id) = RootDatabase::with_single_file(text);
17-
// FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`,
18-
// but it looks like this might need specialization? :(
19-
db.set_local_roots(Arc::new(vec![db.file_source_root(file_id)]));
20-
(db, file_id)
14+
RootDatabase::with_single_file(text)
2115
}
2216

2317
pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) {
@@ -72,8 +66,7 @@ enum ExpectedResult<'a> {
7266

7367
fn check(handler: Handler, before: &str, expected: ExpectedResult) {
7468
let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") {
75-
let (mut db, position) = RootDatabase::with_position(before);
76-
db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)]));
69+
let (db, position) = RootDatabase::with_position(before);
7770
(
7871
db.file_text(position.file_id).as_ref().to_owned(),
7972
position.file_id,

crates/ra_db/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ ra_cfg = { path = "../ra_cfg" }
1717
ra_prof = { path = "../ra_prof" }
1818
ra_tt = { path = "../ra_tt" }
1919
test_utils = { path = "../test_utils" }
20+
vfs = { path = "../vfs" }
21+
stdx = { path = "../stdx" }

crates/ra_db/src/fixture.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,16 @@
5757
//! fn insert_source_code_here() {}
5858
//! "
5959
//! ```
60-
61-
use std::str::FromStr;
62-
use std::sync::Arc;
60+
use std::{str::FromStr, sync::Arc};
6361

6462
use ra_cfg::CfgOptions;
6563
use rustc_hash::FxHashMap;
6664
use test_utils::{extract_offset, parse_fixture, parse_single_fixture, FixtureMeta, CURSOR_MARKER};
65+
use vfs::{file_set::FileSet, VfsPath};
6766

6867
use crate::{
69-
input::CrateName, CrateGraph, CrateId, Edition, Env, FileId, FilePosition, RelativePathBuf,
70-
SourceDatabaseExt, SourceRoot, SourceRootId,
68+
input::CrateName, CrateGraph, CrateId, Edition, Env, FileId, FilePosition, SourceDatabaseExt,
69+
SourceRoot, SourceRootId,
7170
};
7271

7372
pub const WORKSPACE: SourceRootId = SourceRootId(0);
@@ -105,10 +104,10 @@ impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {}
105104

106105
fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId {
107106
let file_id = FileId(0);
108-
let rel_path: RelativePathBuf = "/main.rs".into();
107+
let mut file_set = vfs::file_set::FileSet::default();
108+
file_set.insert(file_id, vfs::VfsPath::new_virtual_path("/main.rs".to_string()));
109109

110-
let mut source_root = SourceRoot::new_local();
111-
source_root.insert_file(rel_path.clone(), file_id);
110+
let source_root = SourceRoot::new_local(file_set);
112111

113112
let fixture = parse_single_fixture(ra_fixture);
114113

@@ -128,7 +127,6 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
128127
meta.cfg,
129128
meta.env,
130129
Default::default(),
131-
Default::default(),
132130
);
133131
crate_graph
134132
} else {
@@ -140,13 +138,11 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
140138
CfgOptions::default(),
141139
Env::default(),
142140
Default::default(),
143-
Default::default(),
144141
);
145142
crate_graph
146143
};
147144

148145
db.set_file_text(file_id, Arc::new(ra_fixture.to_string()));
149-
db.set_file_relative_path(file_id, rel_path);
150146
db.set_file_source_root(file_id, WORKSPACE);
151147
db.set_source_root(WORKSPACE, Arc::new(source_root));
152148
db.set_crate_graph(Arc::new(crate_graph));
@@ -162,7 +158,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
162158
let mut crate_deps = Vec::new();
163159
let mut default_crate_root: Option<FileId> = None;
164160

165-
let mut source_root = SourceRoot::new_local();
161+
let mut file_set = FileSet::default();
166162
let mut source_root_id = WORKSPACE;
167163
let mut source_root_prefix = "/".to_string();
168164
let mut file_id = FileId(0);
@@ -172,8 +168,8 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
172168
for entry in fixture.iter() {
173169
let meta = match ParsedMeta::from(&entry.meta) {
174170
ParsedMeta::Root { path } => {
175-
let source_root = std::mem::replace(&mut source_root, SourceRoot::new_local());
176-
db.set_source_root(source_root_id, Arc::new(source_root));
171+
let file_set = std::mem::replace(&mut file_set, FileSet::default());
172+
db.set_source_root(source_root_id, Arc::new(SourceRoot::new_local(file_set)));
177173
source_root_id.0 += 1;
178174
source_root_prefix = path;
179175
continue;
@@ -190,7 +186,6 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
190186
meta.cfg,
191187
meta.env,
192188
Default::default(),
193-
Default::default(),
194189
);
195190
let prev = crates.insert(krate.clone(), crate_id);
196191
assert!(prev.is_none());
@@ -212,9 +207,9 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
212207
};
213208

214209
db.set_file_text(file_id, Arc::new(text));
215-
db.set_file_relative_path(file_id, meta.path.clone().into());
216210
db.set_file_source_root(file_id, source_root_id);
217-
source_root.insert_file(meta.path.into(), file_id);
211+
let path = VfsPath::new_virtual_path(meta.path);
212+
file_set.insert(file_id, path.into());
218213

219214
file_id.0 += 1;
220215
}
@@ -228,7 +223,6 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
228223
CfgOptions::default(),
229224
Env::default(),
230225
Default::default(),
231-
Default::default(),
232226
);
233227
} else {
234228
for (from, to) in crate_deps {
@@ -238,7 +232,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
238232
}
239233
}
240234

241-
db.set_source_root(source_root_id, Arc::new(source_root));
235+
db.set_source_root(source_root_id, Arc::new(SourceRoot::new_local(file_set)));
242236
db.set_crate_graph(Arc::new(crate_graph));
243237

244238
file_position

0 commit comments

Comments
 (0)