diff options
Diffstat (limited to 'crates/base_db/src')
-rw-r--r-- | crates/base_db/src/fixture.rs | 68 | ||||
-rw-r--r-- | crates/base_db/src/input.rs | 1 |
2 files changed, 7 insertions, 62 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 8d4641355..0132565e4 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs | |||
@@ -1,62 +1,4 @@ | |||
1 | //! Fixtures are strings containing rust source code with optional metadata. | 1 | //! A set of high-level utility fixture methods to use in tests. |
2 | //! A fixture without metadata is parsed into a single source file. | ||
3 | //! Use this to test functionality local to one file. | ||
4 | //! | ||
5 | //! Simple Example: | ||
6 | //! ``` | ||
7 | //! r#" | ||
8 | //! fn main() { | ||
9 | //! println!("Hello World") | ||
10 | //! } | ||
11 | //! "# | ||
12 | //! ``` | ||
13 | //! | ||
14 | //! Metadata can be added to a fixture after a `//-` comment. | ||
15 | //! The basic form is specifying filenames, | ||
16 | //! which is also how to define multiple files in a single test fixture | ||
17 | //! | ||
18 | //! Example using two files in the same crate: | ||
19 | //! ``` | ||
20 | //! " | ||
21 | //! //- /main.rs | ||
22 | //! mod foo; | ||
23 | //! fn main() { | ||
24 | //! foo::bar(); | ||
25 | //! } | ||
26 | //! | ||
27 | //! //- /foo.rs | ||
28 | //! pub fn bar() {} | ||
29 | //! " | ||
30 | //! ``` | ||
31 | //! | ||
32 | //! Example using two crates with one file each, with one crate depending on the other: | ||
33 | //! ``` | ||
34 | //! r#" | ||
35 | //! //- /main.rs crate:a deps:b | ||
36 | //! fn main() { | ||
37 | //! b::foo(); | ||
38 | //! } | ||
39 | //! //- /lib.rs crate:b | ||
40 | //! pub fn b() { | ||
41 | //! println!("Hello World") | ||
42 | //! } | ||
43 | //! "# | ||
44 | //! ``` | ||
45 | //! | ||
46 | //! Metadata allows specifying all settings and variables | ||
47 | //! that are available in a real rust project: | ||
48 | //! - crate names via `crate:cratename` | ||
49 | //! - dependencies via `deps:dep1,dep2` | ||
50 | //! - configuration settings via `cfg:dbg=false,opt_level=2` | ||
51 | //! - environment variables via `env:PATH=/bin,RUST_LOG=debug` | ||
52 | //! | ||
53 | //! Example using all available metadata: | ||
54 | //! ``` | ||
55 | //! " | ||
56 | //! //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | ||
57 | //! fn insert_source_code_here() {} | ||
58 | //! " | ||
59 | //! ``` | ||
60 | use std::{mem, str::FromStr, sync::Arc}; | 2 | use std::{mem, str::FromStr, sync::Arc}; |
61 | 3 | ||
62 | use cfg::CfgOptions; | 4 | use cfg::CfgOptions; |
@@ -93,7 +35,7 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
93 | fn with_position(ra_fixture: &str) -> (Self, FilePosition) { | 35 | fn with_position(ra_fixture: &str) -> (Self, FilePosition) { |
94 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); | 36 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); |
95 | let offset = match range_or_offset { | 37 | let offset = match range_or_offset { |
96 | RangeOrOffset::Range(_) => panic!(), | 38 | RangeOrOffset::Range(_) => panic!("Expected a cursor position, got a range instead"), |
97 | RangeOrOffset::Offset(it) => it, | 39 | RangeOrOffset::Offset(it) => it, |
98 | }; | 40 | }; |
99 | (db, FilePosition { file_id, offset }) | 41 | (db, FilePosition { file_id, offset }) |
@@ -103,7 +45,7 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
103 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); | 45 | let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); |
104 | let range = match range_or_offset { | 46 | let range = match range_or_offset { |
105 | RangeOrOffset::Range(it) => it, | 47 | RangeOrOffset::Range(it) => it, |
106 | RangeOrOffset::Offset(_) => panic!(), | 48 | RangeOrOffset::Offset(_) => panic!("Expected a cursor range, got a position instead"), |
107 | }; | 49 | }; |
108 | (db, FileRange { file_id, range }) | 50 | (db, FileRange { file_id, range }) |
109 | } | 51 | } |
@@ -112,7 +54,9 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
112 | let fixture = ChangeFixture::parse(ra_fixture); | 54 | let fixture = ChangeFixture::parse(ra_fixture); |
113 | let mut db = Self::default(); | 55 | let mut db = Self::default(); |
114 | fixture.change.apply(&mut db); | 56 | fixture.change.apply(&mut db); |
115 | let (file_id, range_or_offset) = fixture.file_position.unwrap(); | 57 | let (file_id, range_or_offset) = fixture |
58 | .file_position | ||
59 | .expect("Could not find file position in fixture. Did you forget to add an `$0`?"); | ||
116 | (db, file_id, range_or_offset) | 60 | (db, file_id, range_or_offset) |
117 | } | 61 | } |
118 | 62 | ||
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 07628935f..0ef77ef5d 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs | |||
@@ -239,6 +239,7 @@ impl CrateGraph { | |||
239 | name: CrateName, | 239 | name: CrateName, |
240 | to: CrateId, | 240 | to: CrateId, |
241 | ) -> Result<(), CyclicDependenciesError> { | 241 | ) -> Result<(), CyclicDependenciesError> { |
242 | let _p = profile::span("add_dep"); | ||
242 | if self.dfs_find(from, to, &mut FxHashSet::default()) { | 243 | if self.dfs_find(from, to, &mut FxHashSet::default()) { |
243 | return Err(CyclicDependenciesError { | 244 | return Err(CyclicDependenciesError { |
244 | from: (from, self[from].display_name.clone()), | 245 | from: (from, self[from].display_name.clone()), |