aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-24 10:52:24 +0100
committerGitHub <[email protected]>2020-06-24 10:52:24 +0100
commit5d84e27ba961e03c3f394b9a6ef2a035dcc183be (patch)
tree0d3e1feeb92d40a080653f1e79233f18d161a8ef
parent7c28d060b5a5c4e7004282aa6827c3023c5b03c8 (diff)
parent04fe512f0d3567727cfb9ccab166c5344716711a (diff)
Merge #5022
5022: Simplify r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_ide/src/mock_analysis.rs29
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs11
2 files changed, 11 insertions, 29 deletions
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index e99c2b0a3..b7325bfc3 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -79,9 +79,6 @@ pub struct MockAnalysis {
79} 79}
80 80
81impl MockAnalysis { 81impl MockAnalysis {
82 pub fn new() -> MockAnalysis {
83 MockAnalysis::default()
84 }
85 /// Creates `MockAnalysis` using a fixture data in the following format: 82 /// Creates `MockAnalysis` using a fixture data in the following format:
86 /// 83 ///
87 /// ```not_rust 84 /// ```not_rust
@@ -93,7 +90,7 @@ impl MockAnalysis {
93 /// struct Baz; 90 /// struct Baz;
94 /// ``` 91 /// ```
95 pub fn with_files(fixture: &str) -> MockAnalysis { 92 pub fn with_files(fixture: &str) -> MockAnalysis {
96 let mut res = MockAnalysis::new(); 93 let mut res = MockAnalysis::default();
97 for entry in Fixture::parse(fixture) { 94 for entry in Fixture::parse(fixture) {
98 res.add_file_fixture(entry); 95 res.add_file_fixture(entry);
99 } 96 }
@@ -104,11 +101,14 @@ impl MockAnalysis {
104 /// whose position is also returned. 101 /// whose position is also returned.
105 pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { 102 pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) {
106 let mut position = None; 103 let mut position = None;
107 let mut res = MockAnalysis::new(); 104 let mut res = MockAnalysis::default();
108 for entry in Fixture::parse(fixture) { 105 for mut entry in Fixture::parse(fixture) {
109 if entry.text.contains(CURSOR_MARKER) { 106 if entry.text.contains(CURSOR_MARKER) {
110 assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); 107 assert!(position.is_none(), "only one marker (<|>) per fixture is allowed");
111 position = Some(res.add_file_fixture_with_position(entry)); 108 let (offset, text) = extract_offset(&entry.text);
109 entry.text = text;
110 let file_id = res.add_file_fixture(entry);
111 position = Some(FilePosition { file_id, offset });
112 } else { 112 } else {
113 res.add_file_fixture(entry); 113 res.add_file_fixture(entry);
114 } 114 }
@@ -123,19 +123,6 @@ impl MockAnalysis {
123 file_id 123 file_id
124 } 124 }
125 125
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 {
135 let file_id = self.next_id();
136 self.files.push(MockFileData::new(path.to_string(), text.to_string()));
137 file_id
138 }
139 fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange { 126 fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange {
140 let (range, text) = extract_range(text); 127 let (range, text) = extract_range(text);
141 let file_id = self.next_id(); 128 let file_id = self.next_id();
@@ -223,7 +210,7 @@ pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) {
223 210
224/// Creates analysis for a single file, returns range marked with a pair of <|>. 211/// Creates analysis for a single file, returns range marked with a pair of <|>.
225pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) { 212pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) {
226 let mut mock = MockAnalysis::new(); 213 let mut mock = MockAnalysis::default();
227 let pos = mock.add_file_with_range("/main.rs", ra_fixture); 214 let pos = mock.add_file_with_range("/main.rs", ra_fixture);
228 (mock.analysis(), pos) 215 (mock.analysis(), pos)
229} 216}
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index c8943816f..b7fad9719 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -2,10 +2,7 @@ use std::fs;
2 2
3use test_utils::{assert_eq_text, project_dir, read_text}; 3use test_utils::{assert_eq_text, project_dir, read_text};
4 4
5use crate::{ 5use crate::{mock_analysis::single_file, FileRange, TextRange};
6 mock_analysis::{single_file, MockAnalysis},
7 FileRange, TextRange,
8};
9 6
10#[test] 7#[test]
11fn test_highlighting() { 8fn test_highlighting() {
@@ -127,12 +124,10 @@ fn accidentally_quadratic() {
127 let file = project_dir().join("crates/ra_syntax/test_data/accidentally_quadratic"); 124 let file = project_dir().join("crates/ra_syntax/test_data/accidentally_quadratic");
128 let src = fs::read_to_string(file).unwrap(); 125 let src = fs::read_to_string(file).unwrap();
129 126
130 let mut mock = MockAnalysis::new(); 127 let (analysis, file_id) = single_file(&src);
131 let file_id = mock.add_file("/main.rs", &src);
132 let host = mock.analysis_host();
133 128
134 // let t = std::time::Instant::now(); 129 // let t = std::time::Instant::now();
135 let _ = host.analysis().highlight(file_id).unwrap(); 130 let _ = analysis.highlight(file_id).unwrap();
136 // eprintln!("elapsed: {:?}", t.elapsed()); 131 // eprintln!("elapsed: {:?}", t.elapsed());
137} 132}
138 133