mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
rename syntax_mapping as well
This commit is contained in:
parent
80bb7d86ec
commit
03b2ab8e1f
6 changed files with 18 additions and 19 deletions
|
@ -23,8 +23,8 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As
|
||||||
let function =
|
let function =
|
||||||
source_binder::function_from_child_node(ctx.db, ctx.frange.file_id, expr.syntax())?;
|
source_binder::function_from_child_node(ctx.db, ctx.frange.file_id, expr.syntax())?;
|
||||||
let infer_result = function.infer(ctx.db);
|
let infer_result = function.infer(ctx.db);
|
||||||
let syntax_mapping = function.body_source_map(ctx.db);
|
let source_map = function.body_source_map(ctx.db);
|
||||||
let node_expr = syntax_mapping.node_expr(expr)?;
|
let node_expr = source_map.node_expr(expr)?;
|
||||||
let match_expr_ty = infer_result[node_expr].clone();
|
let match_expr_ty = infer_result[node_expr].clone();
|
||||||
let enum_def = match match_expr_ty {
|
let enum_def = match match_expr_ty {
|
||||||
Ty::Adt { def_id: AdtDef::Enum(e), .. } => e,
|
Ty::Adt { def_id: AdtDef::Enum(e), .. } => e,
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl Body {
|
||||||
self.pats.iter()
|
self.pats.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
pub fn source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
||||||
db.body_with_source_map(self.owner).1
|
db.body_with_source_map(self.owner).1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
let infer_result = function.infer(ctx.db);
|
let infer_result = function.infer(ctx.db);
|
||||||
let syntax_mapping = function.body_source_map(ctx.db);
|
let source_map = function.body_source_map(ctx.db);
|
||||||
let expr = match syntax_mapping.node_expr(receiver) {
|
let expr = match source_map.node_expr(receiver) {
|
||||||
Some(expr) => expr,
|
Some(expr) => expr,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,8 +9,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
let infer_result = function.infer(ctx.db);
|
let infer_result = function.infer(ctx.db);
|
||||||
let syntax_mapping = function.body_source_map(ctx.db);
|
let source_map = function.body_source_map(ctx.db);
|
||||||
let expr = match syntax_mapping.node_expr(struct_lit.into()) {
|
let expr = match source_map.node_expr(struct_lit.into()) {
|
||||||
Some(expr) => expr,
|
Some(expr) => expr,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,10 +54,10 @@ pub(crate) fn reference_definition(
|
||||||
if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) {
|
if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) {
|
||||||
tested_by!(goto_definition_works_for_methods);
|
tested_by!(goto_definition_works_for_methods);
|
||||||
let infer_result = function.infer(db);
|
let infer_result = function.infer(db);
|
||||||
let syntax_mapping = function.body_source_map(db);
|
let source_map = function.body_source_map(db);
|
||||||
let expr = ast::Expr::cast(method_call.syntax()).unwrap();
|
let expr = ast::Expr::cast(method_call.syntax()).unwrap();
|
||||||
if let Some(func) =
|
if let Some(func) =
|
||||||
syntax_mapping.node_expr(expr).and_then(|it| infer_result.method_resolution(it))
|
source_map.node_expr(expr).and_then(|it| infer_result.method_resolution(it))
|
||||||
{
|
{
|
||||||
return Exact(NavigationTarget::from_function(db, func));
|
return Exact(NavigationTarget::from_function(db, func));
|
||||||
};
|
};
|
||||||
|
@ -66,10 +66,10 @@ pub(crate) fn reference_definition(
|
||||||
if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) {
|
if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) {
|
||||||
tested_by!(goto_definition_works_for_fields);
|
tested_by!(goto_definition_works_for_fields);
|
||||||
let infer_result = function.infer(db);
|
let infer_result = function.infer(db);
|
||||||
let syntax_mapping = function.body_source_map(db);
|
let source_map = function.body_source_map(db);
|
||||||
let expr = ast::Expr::cast(field_expr.syntax()).unwrap();
|
let expr = ast::Expr::cast(field_expr.syntax()).unwrap();
|
||||||
if let Some(field) =
|
if let Some(field) =
|
||||||
syntax_mapping.node_expr(expr).and_then(|it| infer_result.field_resolution(it))
|
source_map.node_expr(expr).and_then(|it| infer_result.field_resolution(it))
|
||||||
{
|
{
|
||||||
return Exact(NavigationTarget::from_field(db, field));
|
return Exact(NavigationTarget::from_field(db, field));
|
||||||
};
|
};
|
||||||
|
@ -80,11 +80,11 @@ pub(crate) fn reference_definition(
|
||||||
tested_by!(goto_definition_works_for_named_fields);
|
tested_by!(goto_definition_works_for_named_fields);
|
||||||
|
|
||||||
let infer_result = function.infer(db);
|
let infer_result = function.infer(db);
|
||||||
let syntax_mapping = function.body_source_map(db);
|
let source_map = function.body_source_map(db);
|
||||||
|
|
||||||
let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast);
|
let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast);
|
||||||
|
|
||||||
if let Some(expr) = struct_lit.and_then(|lit| syntax_mapping.node_expr(lit.into())) {
|
if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) {
|
||||||
let ty = infer_result[expr].clone();
|
let ty = infer_result[expr].clone();
|
||||||
if let hir::Ty::Adt { def_id, .. } = ty {
|
if let hir::Ty::Adt { def_id, .. } = ty {
|
||||||
if let hir::AdtDef::Struct(s) = def_id {
|
if let hir::AdtDef::Struct(s) = def_id {
|
||||||
|
@ -109,9 +109,8 @@ pub(crate) fn reference_definition(
|
||||||
Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)),
|
Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)),
|
||||||
Some(Resolution::LocalBinding(pat)) => {
|
Some(Resolution::LocalBinding(pat)) => {
|
||||||
let body = resolver.body().expect("no body for local binding");
|
let body = resolver.body().expect("no body for local binding");
|
||||||
let syntax_mapping = body.syntax_mapping(db);
|
let source_map = body.source_map(db);
|
||||||
let ptr =
|
let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping");
|
||||||
syntax_mapping.pat_syntax(pat).expect("pattern not found in syntax mapping");
|
|
||||||
let name =
|
let name =
|
||||||
path.as_ident().cloned().expect("local binding from a multi-segment path");
|
path.as_ident().cloned().expect("local binding from a multi-segment path");
|
||||||
let nav = NavigationTarget::from_scope_entry(file_id, name, ptr);
|
let nav = NavigationTarget::from_scope_entry(file_id, name, ptr);
|
||||||
|
|
|
@ -132,10 +132,10 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
|
||||||
let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?;
|
let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?;
|
||||||
let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?;
|
let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?;
|
||||||
let infer = function.infer(db);
|
let infer = function.infer(db);
|
||||||
let syntax_mapping = function.body_source_map(db);
|
let source_map = function.body_source_map(db);
|
||||||
if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
|
if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) {
|
||||||
Some(infer[expr].to_string())
|
Some(infer[expr].to_string())
|
||||||
} else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) {
|
} else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) {
|
||||||
Some(infer[pat].to_string())
|
Some(infer[pat].to_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue