aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-24 10:48:44 +0100
committerAleksey Kladov <[email protected]>2020-06-24 10:48:44 +0100
commitd4a493078ad0e79a8b401af40274089d8235827f (patch)
treecc03ea687aa084bba4e21c14477890bf4a0f9f12 /crates/ra_ide/src
parentc749fe223bf5a41709a4bc91d0f56dafc4201658 (diff)
Simplify
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/mock_analysis.rs16
1 files changed, 6 insertions, 10 deletions
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index e99c2b0a3..5bad3911f 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -105,10 +105,13 @@ impl MockAnalysis {
105 pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { 105 pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) {
106 let mut position = None; 106 let mut position = None;
107 let mut res = MockAnalysis::new(); 107 let mut res = MockAnalysis::new();
108 for entry in Fixture::parse(fixture) { 108 for mut entry in Fixture::parse(fixture) {
109 if entry.text.contains(CURSOR_MARKER) { 109 if entry.text.contains(CURSOR_MARKER) {
110 assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); 110 assert!(position.is_none(), "only one marker (<|>) per fixture is allowed");
111 position = Some(res.add_file_fixture_with_position(entry)); 111 let (offset, text) = extract_offset(&entry.text);
112 entry.text = text;
113 let file_id = res.add_file_fixture(entry);
114 position = Some(FilePosition { file_id, offset });
112 } else { 115 } else {
113 res.add_file_fixture(entry); 116 res.add_file_fixture(entry);
114 } 117 }
@@ -123,19 +126,12 @@ impl MockAnalysis {
123 file_id 126 file_id
124 } 127 }
125 128
126 fn add_file_fixture_with_position(&mut self, mut fixture: Fixture) -> FilePosition {
127 let (offset, text) = extract_offset(&fixture.text);
128 fixture.text = text;
129 let file_id = self.next_id();
130 self.files.push(MockFileData::from(fixture));
131 FilePosition { file_id, offset }
132 }
133
134 pub fn add_file(&mut self, path: &str, text: &str) -> FileId { 129 pub fn add_file(&mut self, path: &str, text: &str) -> FileId {
135 let file_id = self.next_id(); 130 let file_id = self.next_id();
136 self.files.push(MockFileData::new(path.to_string(), text.to_string())); 131 self.files.push(MockFileData::new(path.to_string(), text.to_string()));
137 file_id 132 file_id
138 } 133 }
134
139 fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange { 135 fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange {
140 let (range, text) = extract_range(text); 136 let (range, text) = extract_range(text);
141 let file_id = self.next_id(); 137 let file_id = self.next_id();