Merge #5022
5022: Simplify r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
5d84e27ba9
2 changed files with 11 additions and 29 deletions
|
@ -79,9 +79,6 @@ pub struct MockAnalysis {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MockAnalysis {
|
impl MockAnalysis {
|
||||||
pub fn new() -> MockAnalysis {
|
|
||||||
MockAnalysis::default()
|
|
||||||
}
|
|
||||||
/// Creates `MockAnalysis` using a fixture data in the following format:
|
/// Creates `MockAnalysis` using a fixture data in the following format:
|
||||||
///
|
///
|
||||||
/// ```not_rust
|
/// ```not_rust
|
||||||
|
@ -93,7 +90,7 @@ impl MockAnalysis {
|
||||||
/// struct Baz;
|
/// struct Baz;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn with_files(fixture: &str) -> MockAnalysis {
|
pub fn with_files(fixture: &str) -> MockAnalysis {
|
||||||
let mut res = MockAnalysis::new();
|
let mut res = MockAnalysis::default();
|
||||||
for entry in Fixture::parse(fixture) {
|
for entry in Fixture::parse(fixture) {
|
||||||
res.add_file_fixture(entry);
|
res.add_file_fixture(entry);
|
||||||
}
|
}
|
||||||
|
@ -104,11 +101,14 @@ impl MockAnalysis {
|
||||||
/// whose position is also returned.
|
/// whose position is also returned.
|
||||||
pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) {
|
pub fn with_files_and_position(fixture: &str) -> (MockAnalysis, FilePosition) {
|
||||||
let mut position = None;
|
let mut position = None;
|
||||||
let mut res = MockAnalysis::new();
|
let mut res = MockAnalysis::default();
|
||||||
for entry in Fixture::parse(fixture) {
|
for mut entry in Fixture::parse(fixture) {
|
||||||
if entry.text.contains(CURSOR_MARKER) {
|
if entry.text.contains(CURSOR_MARKER) {
|
||||||
assert!(position.is_none(), "only one marker (<|>) per fixture is allowed");
|
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 {
|
} else {
|
||||||
res.add_file_fixture(entry);
|
res.add_file_fixture(entry);
|
||||||
}
|
}
|
||||||
|
@ -123,19 +123,6 @@ impl MockAnalysis {
|
||||||
file_id
|
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 {
|
fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange {
|
||||||
let (range, text) = extract_range(text);
|
let (range, text) = extract_range(text);
|
||||||
let file_id = self.next_id();
|
let file_id = self.next_id();
|
||||||
|
@ -223,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 <|>.
|
/// Creates analysis for a single file, returns range marked with a pair of <|>.
|
||||||
pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) {
|
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);
|
let pos = mock.add_file_with_range("/main.rs", ra_fixture);
|
||||||
(mock.analysis(), pos)
|
(mock.analysis(), pos)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,7 @@ use std::fs;
|
||||||
|
|
||||||
use test_utils::{assert_eq_text, project_dir, read_text};
|
use test_utils::{assert_eq_text, project_dir, read_text};
|
||||||
|
|
||||||
use crate::{
|
use crate::{mock_analysis::single_file, FileRange, TextRange};
|
||||||
mock_analysis::{single_file, MockAnalysis},
|
|
||||||
FileRange, TextRange,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_highlighting() {
|
fn test_highlighting() {
|
||||||
|
@ -127,12 +124,10 @@ fn accidentally_quadratic() {
|
||||||
let file = project_dir().join("crates/ra_syntax/test_data/accidentally_quadratic");
|
let file = project_dir().join("crates/ra_syntax/test_data/accidentally_quadratic");
|
||||||
let src = fs::read_to_string(file).unwrap();
|
let src = fs::read_to_string(file).unwrap();
|
||||||
|
|
||||||
let mut mock = MockAnalysis::new();
|
let (analysis, file_id) = single_file(&src);
|
||||||
let file_id = mock.add_file("/main.rs", &src);
|
|
||||||
let host = mock.analysis_host();
|
|
||||||
|
|
||||||
// let t = std::time::Instant::now();
|
// let t = std::time::Instant::now();
|
||||||
let _ = host.analysis().highlight(file_id).unwrap();
|
let _ = analysis.highlight(file_id).unwrap();
|
||||||
// eprintln!("elapsed: {:?}", t.elapsed());
|
// eprintln!("elapsed: {:?}", t.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue