rename syntax-mapping -> source-map
This commit is contained in:
parent
592b906604
commit
eaf1df26e9
@ -23,7 +23,7 @@ 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_syntax_mapping(ctx.db);
|
let syntax_mapping = function.body_source_map(ctx.db);
|
||||||
let node_expr = syntax_mapping.node_expr(expr)?;
|
let node_expr = syntax_mapping.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 {
|
||||||
|
@ -9,7 +9,7 @@ use crate::{
|
|||||||
HirDatabase, PersistentHirDatabase,
|
HirDatabase, PersistentHirDatabase,
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
nameres::{ModuleScope, Namespace, lower::ImportId},
|
nameres::{ModuleScope, Namespace, lower::ImportId},
|
||||||
expr::{Body, BodySyntaxMapping},
|
expr::{Body, BodySourceMap},
|
||||||
ty::InferenceResult,
|
ty::InferenceResult,
|
||||||
adt::{EnumVariantId, StructFieldId, VariantDef},
|
adt::{EnumVariantId, StructFieldId, VariantDef},
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
@ -483,8 +483,8 @@ impl Function {
|
|||||||
self.signature(db).name.clone()
|
self.signature(db).name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
|
pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
||||||
db.body_syntax_mapping(*self)
|
db.body_source_map(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
|
pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
|
||||||
@ -497,7 +497,7 @@ impl Function {
|
|||||||
|
|
||||||
pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
|
pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
|
||||||
let scopes = db.expr_scopes(*self);
|
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 }
|
ScopesWithSyntaxMapping { scopes, syntax_mapping }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ pub trait HirDatabase: PersistentHirDatabase {
|
|||||||
#[salsa::invoke(crate::expr::body_hir)]
|
#[salsa::invoke(crate::expr::body_hir)]
|
||||||
fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>;
|
fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::expr::body_syntax_mapping)]
|
#[salsa::invoke(crate::expr::body_source_map)]
|
||||||
fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>;
|
fn body_source_map(&self, func: Function) -> Arc<crate::expr::BodySourceMap>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
|
#[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
|
||||||
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
|
fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
|
||||||
|
@ -49,7 +49,7 @@ pub struct Body {
|
|||||||
/// a structure that is agnostic to the actual positions of expressions in the
|
/// 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.
|
/// file, so that we don't recompute types whenever some whitespace is typed.
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub struct BodySyntaxMapping {
|
pub struct BodySourceMap {
|
||||||
body: Arc<Body>,
|
body: Arc<Body>,
|
||||||
expr_syntax_mapping: FxHashMap<SyntaxNodePtr, ExprId>,
|
expr_syntax_mapping: FxHashMap<SyntaxNodePtr, ExprId>,
|
||||||
expr_syntax_mapping_back: ArenaMap<ExprId, SyntaxNodePtr>,
|
expr_syntax_mapping_back: ArenaMap<ExprId, SyntaxNodePtr>,
|
||||||
@ -78,8 +78,8 @@ impl Body {
|
|||||||
self.pats.iter()
|
self.pats.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
|
pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
|
||||||
db.body_syntax_mapping(self.owner)
|
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> {
|
pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> {
|
||||||
self.expr_syntax_mapping_back.get(expr).cloned()
|
self.expr_syntax_mapping_back.get(expr).cloned()
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ impl Pat {
|
|||||||
// Queries
|
// Queries
|
||||||
|
|
||||||
pub(crate) fn body_hir(db: &impl HirDatabase, func: Function) -> Arc<Body> {
|
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 {
|
struct ExprCollector {
|
||||||
@ -910,7 +910,7 @@ impl ExprCollector {
|
|||||||
self.body_expr = Some(body);
|
self.body_expr = Some(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_body_syntax_mapping(self) -> BodySyntaxMapping {
|
fn into_body_source_map(self) -> BodySourceMap {
|
||||||
let body = Body {
|
let body = Body {
|
||||||
owner: self.owner,
|
owner: self.owner,
|
||||||
exprs: self.exprs,
|
exprs: self.exprs,
|
||||||
@ -918,7 +918,7 @@ impl ExprCollector {
|
|||||||
params: self.params,
|
params: self.params,
|
||||||
body_expr: self.body_expr.expect("A body should have been collected"),
|
body_expr: self.body_expr.expect("A body should have been collected"),
|
||||||
};
|
};
|
||||||
BodySyntaxMapping {
|
BodySourceMap {
|
||||||
body: Arc::new(body),
|
body: Arc::new(body),
|
||||||
expr_syntax_mapping: self.expr_syntax_mapping,
|
expr_syntax_mapping: self.expr_syntax_mapping,
|
||||||
expr_syntax_mapping_back: self.expr_syntax_mapping_back,
|
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);
|
let mut collector = ExprCollector::new(func);
|
||||||
|
|
||||||
// TODO: consts, etc.
|
// TODO: consts, etc.
|
||||||
collector.collect_fn_body(&func.source(db).1);
|
collector.collect_fn_body(&func.source(db).1);
|
||||||
|
|
||||||
Arc::new(collector.into_body_syntax_mapping())
|
Arc::new(collector.into_body_source_map())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[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);
|
let mut collector = ExprCollector::new(function);
|
||||||
collector.collect_fn_body(node);
|
collector.collect_fn_body(node);
|
||||||
collector.into_body_syntax_mapping()
|
collector.into_body_source_map()
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use ra_arena::{Arena, RawId, impl_arena_id};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Name, AsName, Function,
|
Name, AsName, Function,
|
||||||
expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping},
|
expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySourceMap},
|
||||||
HirDatabase,
|
HirDatabase,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ impl ExprScopes {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ScopesWithSyntaxMapping {
|
pub struct ScopesWithSyntaxMapping {
|
||||||
pub syntax_mapping: Arc<BodySyntaxMapping>,
|
pub syntax_mapping: Arc<BodySourceMap>,
|
||||||
pub scopes: Arc<ExprScopes>,
|
pub scopes: Arc<ExprScopes>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1045,11 +1045,11 @@ fn test() {
|
|||||||
|
|
||||||
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 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 inference_result = func.infer(db);
|
||||||
let (_, syntax) = func.source(db);
|
let (_, syntax) = func.source(db);
|
||||||
let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap();
|
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];
|
let ty = &inference_result[expr];
|
||||||
ty.to_string()
|
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) {
|
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 func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
|
||||||
let inference_result = func.infer(&db);
|
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();
|
let mut types = Vec::new();
|
||||||
for (pat, ty) in inference_result.type_of_pat.iter() {
|
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,
|
Some(sp) => sp,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
types.push((syntax_ptr, ty));
|
types.push((syntax_ptr, ty));
|
||||||
}
|
}
|
||||||
for (expr, ty) in inference_result.type_of_expr.iter() {
|
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,
|
Some(sp) => sp,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
@ -225,6 +225,6 @@ impl RootDatabase {
|
|||||||
|
|
||||||
self.query(hir::db::LowerModuleQuery).sweep(sweep);
|
self.query(hir::db::LowerModuleQuery).sweep(sweep);
|
||||||
self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep);
|
self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep);
|
||||||
self.query(hir::db::BodySyntaxMappingQuery).sweep(sweep);
|
self.query(hir::db::BodySourceMapQuery).sweep(sweep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ 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_syntax_mapping(ctx.db);
|
let syntax_mapping = function.body_source_map(ctx.db);
|
||||||
let expr = match syntax_mapping.node_expr(receiver) {
|
let expr = match syntax_mapping.node_expr(receiver) {
|
||||||
Some(expr) => expr,
|
Some(expr) => expr,
|
||||||
None => return,
|
None => return,
|
||||||
|
@ -9,7 +9,7 @@ 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_syntax_mapping(ctx.db);
|
let syntax_mapping = function.body_source_map(ctx.db);
|
||||||
let expr = match syntax_mapping.node_expr(struct_lit.into()) {
|
let expr = match syntax_mapping.node_expr(struct_lit.into()) {
|
||||||
Some(expr) => expr,
|
Some(expr) => expr,
|
||||||
None => return,
|
None => return,
|
||||||
|
@ -54,7 +54,7 @@ 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_syntax_mapping(db);
|
let syntax_mapping = 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))
|
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) {
|
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_syntax_mapping(db);
|
let syntax_mapping = 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))
|
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);
|
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_syntax_mapping(db);
|
let syntax_mapping = 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);
|
||||||
|
|
||||||
|
@ -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 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_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)) {
|
if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.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| syntax_mapping.node_pat(p)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user