simplify
This commit is contained in:
parent
b0d8f9ff5d
commit
58fe5598e7
2 changed files with 12 additions and 17 deletions
|
@ -89,12 +89,6 @@ fn module_from_source(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn function_from_position(db: &impl HirDatabase, position: FilePosition) -> Option<Function> {
|
|
||||||
let file = db.parse(position.file_id);
|
|
||||||
let fn_def = find_node_at_offset::<ast::FnDef>(file.syntax(), position.offset)?;
|
|
||||||
function_from_source(db, position.file_id, fn_def)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn function_from_source(
|
fn function_from_source(
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
|
|
|
@ -8,7 +8,6 @@ use ra_syntax::{algo, ast::{self, AstNode}, SyntaxKind::*};
|
||||||
use test_utils::covers;
|
use test_utils::covers;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
source_binder,
|
|
||||||
mock::MockDatabase,
|
mock::MockDatabase,
|
||||||
ty::display::HirDisplay,
|
ty::display::HirDisplay,
|
||||||
ty::InferenceResult,
|
ty::InferenceResult,
|
||||||
|
@ -2303,13 +2302,10 @@ fn test() -> u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
|
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
|
||||||
let func = source_binder::function_from_position(db, pos).unwrap();
|
let file = db.parse(pos.file_id);
|
||||||
let body_source_map = func.body_source_map(db);
|
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
|
||||||
let inference_result = func.infer(db);
|
let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset));
|
||||||
let (_, syntax) = func.source(db);
|
let ty = analyzer.type_of(db, expr).unwrap();
|
||||||
let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap();
|
|
||||||
let expr = body_source_map.node_expr(node).unwrap();
|
|
||||||
let ty = &inference_result[expr];
|
|
||||||
ty.display(db).to_string()
|
ty.display(db).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2390,10 +2386,12 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
let func = source_binder::function_from_position(&db, pos).unwrap();
|
|
||||||
{
|
{
|
||||||
|
let file = db.parse(pos.file_id);
|
||||||
|
let node =
|
||||||
|
algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
func.infer(&db);
|
SourceAnalyzer::new(&db, pos.file_id, node, None);
|
||||||
});
|
});
|
||||||
assert!(format!("{:?}", events).contains("infer"))
|
assert!(format!("{:?}", events).contains("infer"))
|
||||||
}
|
}
|
||||||
|
@ -2410,8 +2408,11 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||||
db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text));
|
db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text));
|
||||||
|
|
||||||
{
|
{
|
||||||
|
let file = db.parse(pos.file_id);
|
||||||
|
let node =
|
||||||
|
algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent();
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
func.infer(&db);
|
SourceAnalyzer::new(&db, pos.file_id, node, None);
|
||||||
});
|
});
|
||||||
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue