rename syntax_mapping as well

This commit is contained in:
Aleksey Kladov 2019-03-02 16:56:09 +03:00
parent 80bb7d86ec
commit 03b2ab8e1f
6 changed files with 18 additions and 19 deletions

View File

@ -23,8 +23,8 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As
let function =
source_binder::function_from_child_node(ctx.db, ctx.frange.file_id, expr.syntax())?;
let infer_result = function.infer(ctx.db);
let syntax_mapping = function.body_source_map(ctx.db);
let node_expr = syntax_mapping.node_expr(expr)?;
let source_map = function.body_source_map(ctx.db);
let node_expr = source_map.node_expr(expr)?;
let match_expr_ty = infer_result[node_expr].clone();
let enum_def = match match_expr_ty {
Ty::Adt { def_id: AdtDef::Enum(e), .. } => e,

View File

@ -78,7 +78,7 @@ pub fn pats(&self) -> impl Iterator<Item = (PatId, &Pat)> {
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
}
}

View File

@ -9,8 +9,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
_ => return,
};
let infer_result = function.infer(ctx.db);
let syntax_mapping = function.body_source_map(ctx.db);
let expr = match syntax_mapping.node_expr(receiver) {
let source_map = function.body_source_map(ctx.db);
let expr = match source_map.node_expr(receiver) {
Some(expr) => expr,
None => return,
};

View File

@ -9,8 +9,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon
_ => return,
};
let infer_result = function.infer(ctx.db);
let syntax_mapping = function.body_source_map(ctx.db);
let expr = match syntax_mapping.node_expr(struct_lit.into()) {
let source_map = function.body_source_map(ctx.db);
let expr = match source_map.node_expr(struct_lit.into()) {
Some(expr) => expr,
None => return,
};

View File

@ -54,10 +54,10 @@ pub(crate) fn reference_definition(
if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) {
tested_by!(goto_definition_works_for_methods);
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();
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));
};
@ -66,10 +66,10 @@ pub(crate) fn reference_definition(
if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) {
tested_by!(goto_definition_works_for_fields);
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();
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));
};
@ -80,11 +80,11 @@ pub(crate) fn reference_definition(
tested_by!(goto_definition_works_for_named_fields);
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);
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();
if let hir::Ty::Adt { def_id, .. } = ty {
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::LocalBinding(pat)) => {
let body = resolver.body().expect("no body for local binding");
let syntax_mapping = body.syntax_mapping(db);
let ptr =
syntax_mapping.pat_syntax(pat).expect("pattern not found in syntax mapping");
let source_map = body.source_map(db);
let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping");
let name =
path.as_ident().cloned().expect("local binding from a multi-segment path");
let nav = NavigationTarget::from_scope_entry(file_id, name, ptr);

View File

@ -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 function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?;
let infer = function.infer(db);
let syntax_mapping = function.body_source_map(db);
if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
let source_map = function.body_source_map(db);
if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) {
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())
} else {
None