mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Rewrite goto definition tests
This commit is contained in:
parent
d34e725f09
commit
4484908a86
5 changed files with 484 additions and 611 deletions
|
@ -80,7 +80,7 @@ pub struct FilePosition {
|
||||||
pub offset: TextSize,
|
pub offset: TextSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub struct FileRange {
|
pub struct FileRange {
|
||||||
pub file_id: FileId,
|
pub file_id: FileId,
|
||||||
pub range: TextRange,
|
pub range: TextRange,
|
||||||
|
|
|
@ -64,6 +64,7 @@ impl NavigationTarget {
|
||||||
self.file_id
|
self.file_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: inconsistent
|
||||||
pub fn file_range(&self) -> FileRange {
|
pub fn file_range(&self) -> FileRange {
|
||||||
FileRange { file_id: self.file_id, range: self.full_range }
|
FileRange { file_id: self.file_id, range: self.full_range }
|
||||||
}
|
}
|
||||||
|
@ -283,11 +284,13 @@ impl ToNav for hir::ImplDef {
|
||||||
} else {
|
} else {
|
||||||
original_range(db, src.as_ref().map(|it| it.syntax()))
|
original_range(db, src.as_ref().map(|it| it.syntax()))
|
||||||
};
|
};
|
||||||
|
let focus_range =
|
||||||
|
src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range);
|
||||||
|
|
||||||
NavigationTarget::from_syntax(
|
NavigationTarget::from_syntax(
|
||||||
frange.file_id,
|
frange.file_id,
|
||||||
"impl".into(),
|
"impl".into(),
|
||||||
None,
|
focus_range,
|
||||||
frange.range,
|
frange.range,
|
||||||
src.value.syntax().kind(),
|
src.value.syntax().kind(),
|
||||||
)
|
)
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3,11 +3,15 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use ra_cfg::CfgOptions;
|
use ra_cfg::CfgOptions;
|
||||||
use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath};
|
use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath};
|
||||||
use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER};
|
use test_utils::{
|
||||||
|
extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange,
|
Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange,
|
||||||
};
|
};
|
||||||
|
use ra_syntax::TextRange;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
|
/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
|
||||||
/// from a set of in-memory files.
|
/// from a set of in-memory files.
|
||||||
|
@ -77,6 +81,28 @@ impl MockAnalysis {
|
||||||
.expect("no file in this mock");
|
.expect("no file in this mock");
|
||||||
FileId(idx as u32 + 1)
|
FileId(idx as u32 + 1)
|
||||||
}
|
}
|
||||||
|
pub fn annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> {
|
||||||
|
self.files
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(idx, fixture)| {
|
||||||
|
let file_id = FileId(idx as u32 + 1);
|
||||||
|
let annotations = extract_annotations(&fixture.text);
|
||||||
|
if annotations.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some((file_id, annotations))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
pub fn annotation(&self) -> (FileRange, String) {
|
||||||
|
let all = self.annotations();
|
||||||
|
assert_eq!(all.len(), 1);
|
||||||
|
let (file_id, mut for_file) = all.into_iter().next().unwrap();
|
||||||
|
assert_eq!(for_file.len(), 1);
|
||||||
|
let (range, data) = for_file.pop().unwrap();
|
||||||
|
(FileRange { file_id, range}, data)
|
||||||
|
}
|
||||||
pub fn analysis_host(self) -> AnalysisHost {
|
pub fn analysis_host(self) -> AnalysisHost {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
|
|
|
@ -177,6 +177,9 @@ There are many benefits to this:
|
||||||
* less stuff printed during printf-debugging
|
* less stuff printed during printf-debugging
|
||||||
* less time to run test
|
* less time to run test
|
||||||
|
|
||||||
|
It also makes sense to format snippets more compactly (for example, by placing enum defitions like `enum E { Foo, Bar }` on a single line),
|
||||||
|
as long as they are still readable.
|
||||||
|
|
||||||
## Order of Imports
|
## Order of Imports
|
||||||
|
|
||||||
We separate import groups with blank lines
|
We separate import groups with blank lines
|
||||||
|
|
Loading…
Reference in a new issue