From d4a493078ad0e79a8b401af40274089d8235827f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Jun 2020 11:48:44 +0200 Subject: Simplify --- crates/ra_ide/src/mock_analysis.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide/src') 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 { pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { let mut position = None; let mut res = MockAnalysis::new(); - for entry in Fixture::parse(fixture) { + for mut entry in Fixture::parse(fixture) { if entry.text.contains(CURSOR_MARKER) { assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); - position = Some(res.add_file_fixture_with_position(entry)); + let (offset, text) = extract_offset(&entry.text); + entry.text = text; + let file_id = res.add_file_fixture(entry); + position = Some(FilePosition { file_id, offset }); } else { res.add_file_fixture(entry); } @@ -123,19 +126,12 @@ impl MockAnalysis { file_id } - fn add_file_fixture_with_position(&mut self, mut fixture: Fixture) -> FilePosition { - let (offset, text) = extract_offset(&fixture.text); - fixture.text = text; - let file_id = self.next_id(); - self.files.push(MockFileData::from(fixture)); - FilePosition { file_id, offset } - } - pub fn add_file(&mut self, path: &str, text: &str) -> FileId { let file_id = self.next_id(); self.files.push(MockFileData::new(path.to_string(), text.to_string())); file_id } + fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange { let (range, text) = extract_range(text); let file_id = self.next_id(); -- cgit v1.2.3 From 9d64525daa16eb25c15a97d7dd8e099f6ff102c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Jun 2020 11:50:53 +0200 Subject: Simplify --- crates/ra_ide/src/mock_analysis.rs | 6 ------ crates/ra_ide/src/syntax_highlighting/tests.rs | 11 +++-------- 2 files changed, 3 insertions(+), 14 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 5bad3911f..79b796544 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -126,12 +126,6 @@ impl MockAnalysis { file_id } - pub fn add_file(&mut self, path: &str, text: &str) -> FileId { - let file_id = self.next_id(); - self.files.push(MockFileData::new(path.to_string(), text.to_string())); - file_id - } - fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange { let (range, text) = extract_range(text); let file_id = self.next_id(); 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; use test_utils::{assert_eq_text, project_dir, read_text}; -use crate::{ - mock_analysis::{single_file, MockAnalysis}, - FileRange, TextRange, -}; +use crate::{mock_analysis::single_file, FileRange, TextRange}; #[test] fn test_highlighting() { @@ -127,12 +124,10 @@ fn accidentally_quadratic() { let file = project_dir().join("crates/ra_syntax/test_data/accidentally_quadratic"); let src = fs::read_to_string(file).unwrap(); - let mut mock = MockAnalysis::new(); - let file_id = mock.add_file("/main.rs", &src); - let host = mock.analysis_host(); + let (analysis, file_id) = single_file(&src); // let t = std::time::Instant::now(); - let _ = host.analysis().highlight(file_id).unwrap(); + let _ = analysis.highlight(file_id).unwrap(); // eprintln!("elapsed: {:?}", t.elapsed()); } -- cgit v1.2.3 From 04fe512f0d3567727cfb9ccab166c5344716711a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Jun 2020 11:51:45 +0200 Subject: Simplify --- crates/ra_ide/src/mock_analysis.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 79b796544..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 { } impl MockAnalysis { - pub fn new() -> MockAnalysis { - MockAnalysis::default() - } /// Creates `MockAnalysis` using a fixture data in the following format: /// /// ```not_rust @@ -93,7 +90,7 @@ impl MockAnalysis { /// struct Baz; /// ``` pub fn with_files(fixture: &str) -> MockAnalysis { - let mut res = MockAnalysis::new(); + let mut res = MockAnalysis::default(); for entry in Fixture::parse(fixture) { res.add_file_fixture(entry); } @@ -104,7 +101,7 @@ impl MockAnalysis { /// whose position is also returned. pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) { let mut position = None; - let mut res = MockAnalysis::new(); + let mut res = MockAnalysis::default(); for mut entry in Fixture::parse(fixture) { if entry.text.contains(CURSOR_MARKER) { assert!(position.is_none(), "only one marker (<|>) per fixture is allowed"); @@ -213,7 +210,7 @@ pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) { /// Creates analysis for a single file, returns range marked with a pair of <|>. pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) { - let mut mock = MockAnalysis::new(); + let mut mock = MockAnalysis::default(); let pos = mock.add_file_with_range("/main.rs", ra_fixture); (mock.analysis(), pos) } -- cgit v1.2.3