diff options
-rw-r--r-- | crates/ide/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ide/src/mock_analysis.rs | 24 |
2 files changed, 14 insertions, 13 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 6d5fd1a55..bab3ec1ff 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -15,7 +15,8 @@ macro_rules! eprintln { | |||
15 | ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; | 15 | ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; |
16 | } | 16 | } |
17 | 17 | ||
18 | pub mod mock_analysis; | 18 | #[cfg(test)] |
19 | mod mock_analysis; | ||
19 | 20 | ||
20 | mod markup; | 21 | mod markup; |
21 | mod prime_caches; | 22 | mod prime_caches; |
diff --git a/crates/ide/src/mock_analysis.rs b/crates/ide/src/mock_analysis.rs index 235796dbc..327cdf91e 100644 --- a/crates/ide/src/mock_analysis.rs +++ b/crates/ide/src/mock_analysis.rs | |||
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis | 14 | /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis |
15 | /// from a set of in-memory files. | 15 | /// from a set of in-memory files. |
16 | #[derive(Debug, Default)] | 16 | #[derive(Debug, Default)] |
17 | pub struct MockAnalysis { | 17 | pub(crate) struct MockAnalysis { |
18 | files: Vec<Fixture>, | 18 | files: Vec<Fixture>, |
19 | } | 19 | } |
20 | 20 | ||
@@ -29,7 +29,7 @@ impl MockAnalysis { | |||
29 | /// //- /foo.rs | 29 | /// //- /foo.rs |
30 | /// struct Baz; | 30 | /// struct Baz; |
31 | /// ``` | 31 | /// ``` |
32 | pub fn with_files(ra_fixture: &str) -> MockAnalysis { | 32 | pub(crate) fn with_files(ra_fixture: &str) -> MockAnalysis { |
33 | let (res, pos) = MockAnalysis::with_fixture(ra_fixture); | 33 | let (res, pos) = MockAnalysis::with_fixture(ra_fixture); |
34 | assert!(pos.is_none()); | 34 | assert!(pos.is_none()); |
35 | res | 35 | res |
@@ -37,7 +37,7 @@ impl MockAnalysis { | |||
37 | 37 | ||
38 | /// Same as `with_files`, but requires that a single file contains a `<|>` marker, | 38 | /// Same as `with_files`, but requires that a single file contains a `<|>` marker, |
39 | /// whose position is also returned. | 39 | /// whose position is also returned. |
40 | pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { | 40 | pub(crate) fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { |
41 | let (res, position) = MockAnalysis::with_fixture(fixture); | 41 | let (res, position) = MockAnalysis::with_fixture(fixture); |
42 | let (file_id, range_or_offset) = position.expect("expected a marker (<|>)"); | 42 | let (file_id, range_or_offset) = position.expect("expected a marker (<|>)"); |
43 | let offset = match range_or_offset { | 43 | let offset = match range_or_offset { |
@@ -70,12 +70,12 @@ impl MockAnalysis { | |||
70 | file_id | 70 | file_id |
71 | } | 71 | } |
72 | 72 | ||
73 | pub fn id_of(&self, path: &str) -> FileId { | 73 | pub(crate) fn id_of(&self, path: &str) -> FileId { |
74 | let (file_id, _) = | 74 | let (file_id, _) = |
75 | self.files().find(|(_, data)| path == data.path).expect("no file in this mock"); | 75 | self.files().find(|(_, data)| path == data.path).expect("no file in this mock"); |
76 | file_id | 76 | file_id |
77 | } | 77 | } |
78 | pub fn annotations(&self) -> Vec<(FileRange, String)> { | 78 | pub(crate) fn annotations(&self) -> Vec<(FileRange, String)> { |
79 | self.files() | 79 | self.files() |
80 | .flat_map(|(file_id, fixture)| { | 80 | .flat_map(|(file_id, fixture)| { |
81 | let annotations = extract_annotations(&fixture.text); | 81 | let annotations = extract_annotations(&fixture.text); |
@@ -85,15 +85,15 @@ impl MockAnalysis { | |||
85 | }) | 85 | }) |
86 | .collect() | 86 | .collect() |
87 | } | 87 | } |
88 | pub fn files(&self) -> impl Iterator<Item = (FileId, &Fixture)> + '_ { | 88 | pub(crate) fn files(&self) -> impl Iterator<Item = (FileId, &Fixture)> + '_ { |
89 | self.files.iter().enumerate().map(|(idx, fixture)| (FileId(idx as u32 + 1), fixture)) | 89 | self.files.iter().enumerate().map(|(idx, fixture)| (FileId(idx as u32 + 1), fixture)) |
90 | } | 90 | } |
91 | pub fn annotation(&self) -> (FileRange, String) { | 91 | pub(crate) fn annotation(&self) -> (FileRange, String) { |
92 | let mut all = self.annotations(); | 92 | let mut all = self.annotations(); |
93 | assert_eq!(all.len(), 1); | 93 | assert_eq!(all.len(), 1); |
94 | all.pop().unwrap() | 94 | all.pop().unwrap() |
95 | } | 95 | } |
96 | pub fn analysis_host(self) -> AnalysisHost { | 96 | pub(crate) fn analysis_host(self) -> AnalysisHost { |
97 | let mut host = AnalysisHost::default(); | 97 | let mut host = AnalysisHost::default(); |
98 | let mut change = AnalysisChange::new(); | 98 | let mut change = AnalysisChange::new(); |
99 | let mut file_set = FileSet::default(); | 99 | let mut file_set = FileSet::default(); |
@@ -146,26 +146,26 @@ impl MockAnalysis { | |||
146 | host.apply_change(change); | 146 | host.apply_change(change); |
147 | host | 147 | host |
148 | } | 148 | } |
149 | pub fn analysis(self) -> Analysis { | 149 | pub(crate) fn analysis(self) -> Analysis { |
150 | self.analysis_host().analysis() | 150 | self.analysis_host().analysis() |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. | 154 | /// Creates analysis from a multi-file fixture, returns positions marked with <|>. |
155 | pub fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) { | 155 | pub(crate) fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) { |
156 | let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture); | 156 | let (mock, position) = MockAnalysis::with_files_and_position(ra_fixture); |
157 | (mock.analysis(), position) | 157 | (mock.analysis(), position) |
158 | } | 158 | } |
159 | 159 | ||
160 | /// Creates analysis for a single file. | 160 | /// Creates analysis for a single file. |
161 | pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) { | 161 | pub(crate) fn single_file(ra_fixture: &str) -> (Analysis, FileId) { |
162 | let mock = MockAnalysis::with_files(ra_fixture); | 162 | let mock = MockAnalysis::with_files(ra_fixture); |
163 | let file_id = mock.id_of("/main.rs"); | 163 | let file_id = mock.id_of("/main.rs"); |
164 | (mock.analysis(), file_id) | 164 | (mock.analysis(), file_id) |
165 | } | 165 | } |
166 | 166 | ||
167 | /// Creates analysis for a single file, returns range marked with a pair of <|>. | 167 | /// Creates analysis for a single file, returns range marked with a pair of <|>. |
168 | pub fn analysis_and_range(ra_fixture: &str) -> (Analysis, FileRange) { | 168 | pub(crate) fn analysis_and_range(ra_fixture: &str) -> (Analysis, FileRange) { |
169 | let (res, position) = MockAnalysis::with_fixture(ra_fixture); | 169 | let (res, position) = MockAnalysis::with_fixture(ra_fixture); |
170 | let (file_id, range_or_offset) = position.expect("expected a marker (<|>)"); | 170 | let (file_id, range_or_offset) = position.expect("expected a marker (<|>)"); |
171 | let range = match range_or_offset { | 171 | let range = match range_or_offset { |