mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-24 21:53:56 +00:00
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
@ -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,11 +101,14 @@ 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();
|
||||
for entry in Fixture::parse(fixture) {
|
||||
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");
|
||||
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 +123,6 @@ 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();
|
||||
@ -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 <|>.
|
||||
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)
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user