mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Better factoring
This commit is contained in:
parent
d21c84abd4
commit
d34e725f09
2 changed files with 18 additions and 9 deletions
|
@ -8,8 +8,10 @@ use std::{
|
||||||
use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId, ModuleId};
|
use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId, ModuleId};
|
||||||
use hir_expand::{db::AstDatabase, diagnostics::DiagnosticSink};
|
use hir_expand::{db::AstDatabase, diagnostics::DiagnosticSink};
|
||||||
use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast};
|
use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast};
|
||||||
use rustc_hash::FxHashSet;
|
use ra_syntax::TextRange;
|
||||||
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
|
use test_utils::extract_annotations;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, diagnostics::Diagnostic, expr::ExprValidator,
|
db::HirDatabase, diagnostics::Diagnostic, expr::ExprValidator,
|
||||||
|
@ -155,17 +157,27 @@ impl TestDB {
|
||||||
(buf, count)
|
(buf, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_files(&self) -> Vec<FileId> {
|
pub fn extract_annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> {
|
||||||
let mut res = Vec::new();
|
let mut files = Vec::new();
|
||||||
let crate_graph = self.crate_graph();
|
let crate_graph = self.crate_graph();
|
||||||
for krate in crate_graph.iter() {
|
for krate in crate_graph.iter() {
|
||||||
let crate_def_map = self.crate_def_map(krate);
|
let crate_def_map = self.crate_def_map(krate);
|
||||||
for (module_id, _) in crate_def_map.modules.iter() {
|
for (module_id, _) in crate_def_map.modules.iter() {
|
||||||
let file_id = crate_def_map[module_id].origin.file_id();
|
let file_id = crate_def_map[module_id].origin.file_id();
|
||||||
res.extend(file_id)
|
files.extend(file_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res
|
files
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|file_id| {
|
||||||
|
let text = self.file_text(file_id);
|
||||||
|
let annotations = extract_annotations(&text);
|
||||||
|
if annotations.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some((file_id, annotations))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ use ra_syntax::{
|
||||||
SyntaxNode,
|
SyntaxNode,
|
||||||
};
|
};
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
use test_utils::extract_annotations;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty,
|
db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty,
|
||||||
|
@ -49,9 +48,7 @@ fn check_types_source_code(ra_fixture: &str) {
|
||||||
fn check_types_impl(ra_fixture: &str, display_source: bool) {
|
fn check_types_impl(ra_fixture: &str, display_source: bool) {
|
||||||
let db = TestDB::with_files(ra_fixture);
|
let db = TestDB::with_files(ra_fixture);
|
||||||
let mut checked_one = false;
|
let mut checked_one = false;
|
||||||
for file_id in db.all_files() {
|
for (file_id, annotations) in db.extract_annotations() {
|
||||||
let text = db.parse(file_id).syntax_node().to_string();
|
|
||||||
let annotations = extract_annotations(&text);
|
|
||||||
for (range, expected) in annotations {
|
for (range, expected) in annotations {
|
||||||
let ty = type_at_range(&db, FileRange { file_id, range });
|
let ty = type_at_range(&db, FileRange { file_id, range });
|
||||||
let actual = if display_source {
|
let actual = if display_source {
|
||||||
|
|
Loading…
Reference in a new issue