rename syntax-mapping -> source-map

This commit is contained in:
Aleksey Kladov 2019-03-02 15:14:37 +03:00
parent 592b906604
commit eaf1df26e9
11 changed files with 32 additions and 32 deletions

View file

@ -23,7 +23,7 @@ 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_syntax_mapping(ctx.db);
let syntax_mapping = function.body_source_map(ctx.db);
let node_expr = syntax_mapping.node_expr(expr)?;
let match_expr_ty = infer_result[node_expr].clone();
let enum_def = match match_expr_ty {

View file

@ -9,7 +9,7 @@ use crate::{
HirDatabase, PersistentHirDatabase,
type_ref::TypeRef,
nameres::{ModuleScope, Namespace, lower::ImportId},
expr::{Body, BodySyntaxMapping},
expr::{Body, BodySourceMap},
ty::InferenceResult,
adt::{EnumVariantId, StructFieldId, VariantDef},
generics::GenericParams,
@ -483,8 +483,8 @@ impl Function {
self.signature(db).name.clone()
}
pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
db.body_syntax_mapping(*self)
pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
db.body_source_map(*self)
}
pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
@ -497,7 +497,7 @@ impl Function {
pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
let scopes = db.expr_scopes(*self);
let syntax_mapping = db.body_syntax_mapping(*self);
let syntax_mapping = db.body_source_map(*self);
ScopesWithSyntaxMapping { scopes, syntax_mapping }
}

View file

@ -108,8 +108,8 @@ pub trait HirDatabase: PersistentHirDatabase {
#[salsa::invoke(crate::expr::body_hir)]
fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>;
#[salsa::invoke(crate::expr::body_syntax_mapping)]
fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>;
#[salsa::invoke(crate::expr::body_source_map)]
fn body_source_map(&self, func: Function) -> Arc<crate::expr::BodySourceMap>;
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;

View file

@ -49,7 +49,7 @@ pub struct Body {
/// a structure that is agnostic to the actual positions of expressions in the
/// file, so that we don't recompute types whenever some whitespace is typed.
#[derive(Debug, Eq, PartialEq)]
pub struct BodySyntaxMapping {
pub struct BodySourceMap {
body: Arc<Body>,
expr_syntax_mapping: FxHashMap<SyntaxNodePtr, ExprId>,
expr_syntax_mapping_back: ArenaMap<ExprId, SyntaxNodePtr>,
@ -78,8 +78,8 @@ impl Body {
self.pats.iter()
}
pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
db.body_syntax_mapping(self.owner)
pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
db.body_source_map(self.owner)
}
}
@ -119,7 +119,7 @@ impl Index<PatId> for Body {
}
}
impl BodySyntaxMapping {
impl BodySourceMap {
pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> {
self.expr_syntax_mapping_back.get(expr).cloned()
}
@ -468,7 +468,7 @@ impl Pat {
// Queries
pub(crate) fn body_hir(db: &impl HirDatabase, func: Function) -> Arc<Body> {
Arc::clone(&body_syntax_mapping(db, func).body)
Arc::clone(&body_source_map(db, func).body)
}
struct ExprCollector {
@ -910,7 +910,7 @@ impl ExprCollector {
self.body_expr = Some(body);
}
fn into_body_syntax_mapping(self) -> BodySyntaxMapping {
fn into_body_source_map(self) -> BodySourceMap {
let body = Body {
owner: self.owner,
exprs: self.exprs,
@ -918,7 +918,7 @@ impl ExprCollector {
params: self.params,
body_expr: self.body_expr.expect("A body should have been collected"),
};
BodySyntaxMapping {
BodySourceMap {
body: Arc::new(body),
expr_syntax_mapping: self.expr_syntax_mapping,
expr_syntax_mapping_back: self.expr_syntax_mapping_back,
@ -928,18 +928,18 @@ impl ExprCollector {
}
}
pub(crate) fn body_syntax_mapping(db: &impl HirDatabase, func: Function) -> Arc<BodySyntaxMapping> {
pub(crate) fn body_source_map(db: &impl HirDatabase, func: Function) -> Arc<BodySourceMap> {
let mut collector = ExprCollector::new(func);
// TODO: consts, etc.
collector.collect_fn_body(&func.source(db).1);
Arc::new(collector.into_body_syntax_mapping())
Arc::new(collector.into_body_source_map())
}
#[cfg(test)]
pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySyntaxMapping {
pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySourceMap {
let mut collector = ExprCollector::new(function);
collector.collect_fn_body(node);
collector.into_body_syntax_mapping()
collector.into_body_source_map()
}

View file

@ -11,7 +11,7 @@ use ra_arena::{Arena, RawId, impl_arena_id};
use crate::{
Name, AsName, Function,
expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping},
expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySourceMap},
HirDatabase,
};
@ -109,7 +109,7 @@ impl ExprScopes {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScopesWithSyntaxMapping {
pub syntax_mapping: Arc<BodySyntaxMapping>,
pub syntax_mapping: Arc<BodySourceMap>,
pub scopes: Arc<ExprScopes>,
}

View file

@ -1045,11 +1045,11 @@ fn test() {
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
let func = source_binder::function_from_position(db, pos).unwrap();
let body_syntax_mapping = func.body_syntax_mapping(db);
let body_source_map = func.body_source_map(db);
let inference_result = func.infer(db);
let (_, syntax) = func.source(db);
let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap();
let expr = body_syntax_mapping.node_expr(node).unwrap();
let expr = body_source_map.node_expr(node).unwrap();
let ty = &inference_result[expr];
ty.to_string()
}
@ -1061,17 +1061,17 @@ fn infer(content: &str) -> String {
for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) {
let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
let inference_result = func.infer(&db);
let body_syntax_mapping = func.body_syntax_mapping(&db);
let body_source_map = func.body_source_map(&db);
let mut types = Vec::new();
for (pat, ty) in inference_result.type_of_pat.iter() {
let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) {
let syntax_ptr = match body_source_map.pat_syntax(pat) {
Some(sp) => sp,
None => continue,
};
types.push((syntax_ptr, ty));
}
for (expr, ty) in inference_result.type_of_expr.iter() {
let syntax_ptr = match body_syntax_mapping.expr_syntax(expr) {
let syntax_ptr = match body_source_map.expr_syntax(expr) {
Some(sp) => sp,
None => continue,
};

View file

@ -225,6 +225,6 @@ impl RootDatabase {
self.query(hir::db::LowerModuleQuery).sweep(sweep);
self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep);
self.query(hir::db::BodySyntaxMappingQuery).sweep(sweep);
self.query(hir::db::BodySourceMapQuery).sweep(sweep);
}
}

View file

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

View file

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

View file

@ -54,7 +54,7 @@ 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_syntax_mapping(db);
let syntax_mapping = 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))
@ -66,7 +66,7 @@ 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_syntax_mapping(db);
let syntax_mapping = 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))
@ -80,7 +80,7 @@ pub(crate) fn reference_definition(
tested_by!(goto_definition_works_for_named_fields);
let infer_result = function.infer(db);
let syntax_mapping = function.body_syntax_mapping(db);
let syntax_mapping = function.body_source_map(db);
let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast);

View file

@ -132,7 +132,7 @@ 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_syntax_mapping(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)) {
Some(infer[expr].to_string())
} else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) {