Skip to content

Commit 09348b2

Browse files
committed
Get rid of MockAnalysis
1 parent eeb27f9 commit 09348b2

19 files changed

+288
-420
lines changed

crates/base_db/src/fixture.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static {
117117
impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {}
118118

119119
pub struct ChangeFixture {
120-
file_position: Option<(FileId, RangeOrOffset)>,
121-
files: Vec<FileId>,
122-
change: Change,
120+
pub file_position: Option<(FileId, RangeOrOffset)>,
121+
pub files: Vec<FileId>,
122+
pub change: Change,
123123
}
124124

125125
impl ChangeFixture {
126-
fn parse(ra_fixture: &str) -> ChangeFixture {
126+
pub fn parse(ra_fixture: &str) -> ChangeFixture {
127127
let fixture = Fixture::parse(ra_fixture);
128128
let mut change = Change::new();
129129

@@ -132,6 +132,7 @@ impl ChangeFixture {
132132
let mut crates = FxHashMap::default();
133133
let mut crate_deps = Vec::new();
134134
let mut default_crate_root: Option<FileId> = None;
135+
let mut default_cfg = CfgOptions::default();
135136

136137
let mut file_set = FileSet::default();
137138
let source_root_prefix = "/".to_string();
@@ -171,6 +172,7 @@ impl ChangeFixture {
171172
} else if meta.path == "/main.rs" || meta.path == "/lib.rs" {
172173
assert!(default_crate_root.is_none());
173174
default_crate_root = Some(file_id);
175+
default_cfg = meta.cfg;
174176
}
175177

176178
change.change_file(file_id, Some(Arc::new(text)));
@@ -185,8 +187,8 @@ impl ChangeFixture {
185187
crate_graph.add_crate_root(
186188
crate_root,
187189
Edition::Edition2018,
188-
None,
189-
CfgOptions::default(),
190+
Some("test".to_string()),
191+
default_cfg,
190192
Env::default(),
191193
Default::default(),
192194
);

crates/ide/src/call_hierarchy.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ fn caller() {
181181
call<|>ee();
182182
}
183183
"#,
184-
"callee FN FileId(1) 0..14 3..9",
185-
&["caller FN FileId(1) 15..44 18..24 : [33..39]"],
184+
"callee FN FileId(0) 0..14 3..9",
185+
&["caller FN FileId(0) 15..44 18..24 : [33..39]"],
186186
&[],
187187
);
188188
}
@@ -197,8 +197,8 @@ fn caller() {
197197
callee();
198198
}
199199
"#,
200-
"callee FN FileId(1) 0..14 3..9",
201-
&["caller FN FileId(1) 15..44 18..24 : [33..39]"],
200+
"callee FN FileId(0) 0..14 3..9",
201+
&["caller FN FileId(0) 15..44 18..24 : [33..39]"],
202202
&[],
203203
);
204204
}
@@ -214,8 +214,8 @@ fn caller() {
214214
callee();
215215
}
216216
"#,
217-
"callee FN FileId(1) 0..14 3..9",
218-
&["caller FN FileId(1) 15..58 18..24 : [33..39, 47..53]"],
217+
"callee FN FileId(0) 0..14 3..9",
218+
&["caller FN FileId(0) 15..58 18..24 : [33..39, 47..53]"],
219219
&[],
220220
);
221221
}
@@ -234,10 +234,10 @@ fn caller2() {
234234
callee();
235235
}
236236
"#,
237-
"callee FN FileId(1) 0..14 3..9",
237+
"callee FN FileId(0) 0..14 3..9",
238238
&[
239-
"caller1 FN FileId(1) 15..45 18..25 : [34..40]",
240-
"caller2 FN FileId(1) 47..77 50..57 : [66..72]",
239+
"caller1 FN FileId(0) 15..45 18..25 : [34..40]",
240+
"caller2 FN FileId(0) 47..77 50..57 : [66..72]",
241241
],
242242
&[],
243243
);
@@ -263,10 +263,10 @@ mod tests {
263263
}
264264
}
265265
"#,
266-
"callee FN FileId(1) 0..14 3..9",
266+
"callee FN FileId(0) 0..14 3..9",
267267
&[
268-
"caller1 FN FileId(1) 15..45 18..25 : [34..40]",
269-
"test_caller FN FileId(1) 95..149 110..121 : [134..140]",
268+
"caller1 FN FileId(0) 15..45 18..25 : [34..40]",
269+
"test_caller FN FileId(0) 95..149 110..121 : [134..140]",
270270
],
271271
&[],
272272
);
@@ -287,8 +287,8 @@ fn caller() {
287287
//- /foo/mod.rs
288288
pub fn callee() {}
289289
"#,
290-
"callee FN FileId(2) 0..18 7..13",
291-
&["caller FN FileId(1) 27..56 30..36 : [45..51]"],
290+
"callee FN FileId(1) 0..18 7..13",
291+
&["caller FN FileId(0) 27..56 30..36 : [45..51]"],
292292
&[],
293293
);
294294
}
@@ -304,9 +304,9 @@ fn call<|>er() {
304304
callee();
305305
}
306306
"#,
307-
"caller FN FileId(1) 15..58 18..24",
307+
"caller FN FileId(0) 15..58 18..24",
308308
&[],
309-
&["callee FN FileId(1) 0..14 3..9 : [33..39, 47..53]"],
309+
&["callee FN FileId(0) 0..14 3..9 : [33..39, 47..53]"],
310310
);
311311
}
312312

@@ -325,9 +325,9 @@ fn call<|>er() {
325325
//- /foo/mod.rs
326326
pub fn callee() {}
327327
"#,
328-
"caller FN FileId(1) 27..56 30..36",
328+
"caller FN FileId(0) 27..56 30..36",
329329
&[],
330-
&["callee FN FileId(2) 0..18 7..13 : [45..51]"],
330+
&["callee FN FileId(1) 0..18 7..13 : [45..51]"],
331331
);
332332
}
333333

@@ -348,9 +348,9 @@ fn caller3() {
348348
349349
}
350350
"#,
351-
"caller2 FN FileId(1) 33..64 36..43",
352-
&["caller1 FN FileId(1) 0..31 3..10 : [19..26]"],
353-
&["caller3 FN FileId(1) 66..83 69..76 : [52..59]"],
351+
"caller2 FN FileId(0) 33..64 36..43",
352+
&["caller1 FN FileId(0) 0..31 3..10 : [19..26]"],
353+
&["caller3 FN FileId(0) 66..83 69..76 : [52..59]"],
354354
);
355355
}
356356

@@ -368,9 +368,9 @@ fn main() {
368368
a<|>()
369369
}
370370
"#,
371-
"a FN FileId(1) 0..18 3..4",
372-
&["main FN FileId(1) 31..52 34..38 : [47..48]"],
373-
&["b FN FileId(1) 20..29 23..24 : [13..14]"],
371+
"a FN FileId(0) 0..18 3..4",
372+
&["main FN FileId(0) 31..52 34..38 : [47..48]"],
373+
&["b FN FileId(0) 20..29 23..24 : [13..14]"],
374374
);
375375

376376
check_hierarchy(
@@ -385,8 +385,8 @@ fn main() {
385385
a()
386386
}
387387
"#,
388-
"b FN FileId(1) 20..29 23..24",
389-
&["a FN FileId(1) 0..18 3..4 : [13..14]"],
388+
"b FN FileId(0) 20..29 23..24",
389+
&["a FN FileId(0) 0..18 3..4 : [13..14]"],
390390
&[],
391391
);
392392
}

crates/ide/src/completion/complete_keyword.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ Some multi-line comment<|>
495495
fn test_completion_await_impls_future() {
496496
check(
497497
r#"
498-
//- /main.rs
498+
//- /main.rs crate:main deps:std
499499
use std::future::*;
500500
struct A {}
501501
impl Future for A {}
502502
fn foo(a: A) { a.<|> }
503503
504-
//- /std/lib.rs
504+
//- /std/lib.rs crate:std
505505
pub mod future {
506506
#[lang = "future_trait"]
507507
pub trait Future {}
@@ -514,14 +514,14 @@ pub mod future {
514514

515515
check(
516516
r#"
517-
//- /main.rs
517+
//- /main.rs crate:main deps:std
518518
use std::future::*;
519519
fn foo() {
520520
let a = async {};
521521
a.<|>
522522
}
523523
524-
//- /std/lib.rs
524+
//- /std/lib.rs crate:std
525525
pub mod future {
526526
#[lang = "future_trait"]
527527
pub trait Future {

crates/ide/src/completion/complete_mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,15 @@ mod tests {
300300
// "#,
301301
// expect![[r#"
302302
// md bar;
303-
// "#]],
303+
// "#]],foo
304304
// );
305305
// }
306306

307307
#[test]
308308
fn already_declared_bin_module_completion_omitted() {
309309
check(
310310
r#"
311-
//- /src/bin.rs
311+
//- /src/bin.rs crate:main
312312
fn main() {}
313313
//- /src/bin/foo.rs
314314
mod <|>

crates/ide/src/completion/complete_qualified_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ fn foo() { let _ = U::<|> }
422422
fn completes_use_paths_across_crates() {
423423
check(
424424
r#"
425-
//- /main.rs
425+
//- /main.rs crate:main deps:foo
426426
use foo::<|>;
427427
428-
//- /foo/lib.rs
428+
//- /foo/lib.rs crate:foo
429429
pub mod bar { pub struct S; }
430430
"#,
431431
expect![[r#"

crates/ide/src/completion/complete_unqualified_path.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ fn quux() { <|> }
271271
fn completes_extern_prelude() {
272272
check(
273273
r#"
274-
//- /lib.rs
274+
//- /lib.rs crate:main deps:other_crate
275275
use <|>;
276276
277-
//- /other_crate/lib.rs
277+
//- /other_crate/lib.rs crate:other_crate
278278
// nothing here
279279
"#,
280280
expect![[r#"
@@ -350,10 +350,10 @@ fn foo() {
350350
fn completes_prelude() {
351351
check(
352352
r#"
353-
//- /main.rs
353+
//- /main.rs crate:main deps:std
354354
fn foo() { let x: <|> }
355355
356-
//- /std/lib.rs
356+
//- /std/lib.rs crate:std
357357
#[prelude_import]
358358
use prelude::*;
359359
@@ -371,16 +371,16 @@ mod prelude { struct Option; }
371371
fn completes_std_prelude_if_core_is_defined() {
372372
check(
373373
r#"
374-
//- /main.rs
374+
//- /main.rs crate:main deps:core,std
375375
fn foo() { let x: <|> }
376376
377-
//- /core/lib.rs
377+
//- /core/lib.rs crate:core
378378
#[prelude_import]
379379
use prelude::*;
380380
381381
mod prelude { struct Option; }
382382
383-
//- /std/lib.rs
383+
//- /std/lib.rs crate:std deps:core
384384
#[prelude_import]
385385
use prelude::*;
386386

crates/ide/src/completion/presentation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,9 @@ fn foo(xs: Vec<i128>)
11721172
check_edit(
11731173
"frobnicate!",
11741174
r#"
1175-
//- /main.rs
1175+
//- /main.rs crate:main deps:foo
11761176
use foo::<|>;
1177-
//- /foo/lib.rs
1177+
//- /foo/lib.rs crate:foo
11781178
#[macro_export]
11791179
macro_rules frobnicate { () => () }
11801180
"#,

0 commit comments

Comments
 (0)