57
57
//! fn insert_source_code_here() {}
58
58
//! "
59
59
//! ```
60
-
61
- use std:: str:: FromStr ;
62
- use std:: sync:: Arc ;
60
+ use std:: { str:: FromStr , sync:: Arc } ;
63
61
64
62
use ra_cfg:: CfgOptions ;
65
63
use rustc_hash:: FxHashMap ;
66
64
use test_utils:: { extract_offset, parse_fixture, parse_single_fixture, FixtureMeta , CURSOR_MARKER } ;
65
+ use vfs:: { file_set:: FileSet , VfsPath } ;
67
66
68
67
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 ,
71
70
} ;
72
71
73
72
pub const WORKSPACE : SourceRootId = SourceRootId ( 0 ) ;
@@ -105,10 +104,10 @@ impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {}
105
104
106
105
fn with_single_file ( db : & mut dyn SourceDatabaseExt , ra_fixture : & str ) -> FileId {
107
106
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 ( ) ) ) ;
109
109
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) ;
112
111
113
112
let fixture = parse_single_fixture ( ra_fixture) ;
114
113
@@ -128,7 +127,6 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
128
127
meta. cfg ,
129
128
meta. env ,
130
129
Default :: default ( ) ,
131
- Default :: default ( ) ,
132
130
) ;
133
131
crate_graph
134
132
} else {
@@ -140,13 +138,11 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
140
138
CfgOptions :: default ( ) ,
141
139
Env :: default ( ) ,
142
140
Default :: default ( ) ,
143
- Default :: default ( ) ,
144
141
) ;
145
142
crate_graph
146
143
} ;
147
144
148
145
db. set_file_text ( file_id, Arc :: new ( ra_fixture. to_string ( ) ) ) ;
149
- db. set_file_relative_path ( file_id, rel_path) ;
150
146
db. set_file_source_root ( file_id, WORKSPACE ) ;
151
147
db. set_source_root ( WORKSPACE , Arc :: new ( source_root) ) ;
152
148
db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
@@ -162,7 +158,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
162
158
let mut crate_deps = Vec :: new ( ) ;
163
159
let mut default_crate_root: Option < FileId > = None ;
164
160
165
- let mut source_root = SourceRoot :: new_local ( ) ;
161
+ let mut file_set = FileSet :: default ( ) ;
166
162
let mut source_root_id = WORKSPACE ;
167
163
let mut source_root_prefix = "/" . to_string ( ) ;
168
164
let mut file_id = FileId ( 0 ) ;
@@ -172,8 +168,8 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
172
168
for entry in fixture. iter ( ) {
173
169
let meta = match ParsedMeta :: from ( & entry. meta ) {
174
170
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 ) ) ) ;
177
173
source_root_id. 0 += 1 ;
178
174
source_root_prefix = path;
179
175
continue ;
@@ -190,7 +186,6 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
190
186
meta. cfg ,
191
187
meta. env ,
192
188
Default :: default ( ) ,
193
- Default :: default ( ) ,
194
189
) ;
195
190
let prev = crates. insert ( krate. clone ( ) , crate_id) ;
196
191
assert ! ( prev. is_none( ) ) ;
@@ -212,9 +207,9 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
212
207
} ;
213
208
214
209
db. set_file_text ( file_id, Arc :: new ( text) ) ;
215
- db. set_file_relative_path ( file_id, meta. path . clone ( ) . into ( ) ) ;
216
210
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 ( ) ) ;
218
213
219
214
file_id. 0 += 1 ;
220
215
}
@@ -228,7 +223,6 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
228
223
CfgOptions :: default ( ) ,
229
224
Env :: default ( ) ,
230
225
Default :: default ( ) ,
231
- Default :: default ( ) ,
232
226
) ;
233
227
} else {
234
228
for ( from, to) in crate_deps {
@@ -238,7 +232,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
238
232
}
239
233
}
240
234
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 ) ) ) ;
242
236
db. set_crate_graph ( Arc :: new ( crate_graph) ) ;
243
237
244
238
file_position
0 commit comments