aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-02 12:14:37 +0000
committerAleksey Kladov <[email protected]>2019-03-02 12:40:40 +0000
commiteaf1df26e9903772d40df30dd70c75c38d8cb887 (patch)
tree4e7a6f4bb15caf4e134305ab1c4ba749e9e1d5b0 /crates/ra_hir/src
parent592b906604d60a86af74c5dbb3bf40b2ddcf8061 (diff)
rename syntax-mapping -> source-map
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model_api.rs8
-rw-r--r--crates/ra_hir/src/db.rs4
-rw-r--r--crates/ra_hir/src/expr.rs22
-rw-r--r--crates/ra_hir/src/expr/scope.rs4
-rw-r--r--crates/ra_hir/src/ty/tests.rs10
5 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index da0f1ec94..f8521e895 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -9,7 +9,7 @@ use crate::{
9 HirDatabase, PersistentHirDatabase, 9 HirDatabase, PersistentHirDatabase,
10 type_ref::TypeRef, 10 type_ref::TypeRef,
11 nameres::{ModuleScope, Namespace, lower::ImportId}, 11 nameres::{ModuleScope, Namespace, lower::ImportId},
12 expr::{Body, BodySyntaxMapping}, 12 expr::{Body, BodySourceMap},
13 ty::InferenceResult, 13 ty::InferenceResult,
14 adt::{EnumVariantId, StructFieldId, VariantDef}, 14 adt::{EnumVariantId, StructFieldId, VariantDef},
15 generics::GenericParams, 15 generics::GenericParams,
@@ -483,8 +483,8 @@ impl Function {
483 self.signature(db).name.clone() 483 self.signature(db).name.clone()
484 } 484 }
485 485
486 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> { 486 pub fn body_source_map(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
487 db.body_syntax_mapping(*self) 487 db.body_source_map(*self)
488 } 488 }
489 489
490 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> { 490 pub fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
@@ -497,7 +497,7 @@ impl Function {
497 497
498 pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping { 498 pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
499 let scopes = db.expr_scopes(*self); 499 let scopes = db.expr_scopes(*self);
500 let syntax_mapping = db.body_syntax_mapping(*self); 500 let syntax_mapping = db.body_source_map(*self);
501 ScopesWithSyntaxMapping { scopes, syntax_mapping } 501 ScopesWithSyntaxMapping { scopes, syntax_mapping }
502 } 502 }
503 503
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index ec848f1b2..cb1c24561 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -108,8 +108,8 @@ pub trait HirDatabase: PersistentHirDatabase {
108 #[salsa::invoke(crate::expr::body_hir)] 108 #[salsa::invoke(crate::expr::body_hir)]
109 fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>; 109 fn body_hir(&self, func: Function) -> Arc<crate::expr::Body>;
110 110
111 #[salsa::invoke(crate::expr::body_syntax_mapping)] 111 #[salsa::invoke(crate::expr::body_source_map)]
112 fn body_syntax_mapping(&self, func: Function) -> Arc<crate::expr::BodySyntaxMapping>; 112 fn body_source_map(&self, func: Function) -> Arc<crate::expr::BodySourceMap>;
113 113
114 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] 114 #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)]
115 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>; 115 fn impls_in_crate(&self, krate: Crate) -> Arc<CrateImplBlocks>;
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index aa39d28ed..b1398411b 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -49,7 +49,7 @@ pub struct Body {
49/// a structure that is agnostic to the actual positions of expressions in the 49/// a structure that is agnostic to the actual positions of expressions in the
50/// file, so that we don't recompute types whenever some whitespace is typed. 50/// file, so that we don't recompute types whenever some whitespace is typed.
51#[derive(Debug, Eq, PartialEq)] 51#[derive(Debug, Eq, PartialEq)]
52pub struct BodySyntaxMapping { 52pub struct BodySourceMap {
53 body: Arc<Body>, 53 body: Arc<Body>,
54 expr_syntax_mapping: FxHashMap<SyntaxNodePtr, ExprId>, 54 expr_syntax_mapping: FxHashMap<SyntaxNodePtr, ExprId>,
55 expr_syntax_mapping_back: ArenaMap<ExprId, SyntaxNodePtr>, 55 expr_syntax_mapping_back: ArenaMap<ExprId, SyntaxNodePtr>,
@@ -78,8 +78,8 @@ impl Body {
78 self.pats.iter() 78 self.pats.iter()
79 } 79 }
80 80
81 pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> { 81 pub fn syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySourceMap> {
82 db.body_syntax_mapping(self.owner) 82 db.body_source_map(self.owner)
83 } 83 }
84} 84}
85 85
@@ -119,7 +119,7 @@ impl Index<PatId> for Body {
119 } 119 }
120} 120}
121 121
122impl BodySyntaxMapping { 122impl BodySourceMap {
123 pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> { 123 pub fn expr_syntax(&self, expr: ExprId) -> Option<SyntaxNodePtr> {
124 self.expr_syntax_mapping_back.get(expr).cloned() 124 self.expr_syntax_mapping_back.get(expr).cloned()
125 } 125 }
@@ -468,7 +468,7 @@ impl Pat {
468// Queries 468// Queries
469 469
470pub(crate) fn body_hir(db: &impl HirDatabase, func: Function) -> Arc<Body> { 470pub(crate) fn body_hir(db: &impl HirDatabase, func: Function) -> Arc<Body> {
471 Arc::clone(&body_syntax_mapping(db, func).body) 471 Arc::clone(&body_source_map(db, func).body)
472} 472}
473 473
474struct ExprCollector { 474struct ExprCollector {
@@ -910,7 +910,7 @@ impl ExprCollector {
910 self.body_expr = Some(body); 910 self.body_expr = Some(body);
911 } 911 }
912 912
913 fn into_body_syntax_mapping(self) -> BodySyntaxMapping { 913 fn into_body_source_map(self) -> BodySourceMap {
914 let body = Body { 914 let body = Body {
915 owner: self.owner, 915 owner: self.owner,
916 exprs: self.exprs, 916 exprs: self.exprs,
@@ -918,7 +918,7 @@ impl ExprCollector {
918 params: self.params, 918 params: self.params,
919 body_expr: self.body_expr.expect("A body should have been collected"), 919 body_expr: self.body_expr.expect("A body should have been collected"),
920 }; 920 };
921 BodySyntaxMapping { 921 BodySourceMap {
922 body: Arc::new(body), 922 body: Arc::new(body),
923 expr_syntax_mapping: self.expr_syntax_mapping, 923 expr_syntax_mapping: self.expr_syntax_mapping,
924 expr_syntax_mapping_back: self.expr_syntax_mapping_back, 924 expr_syntax_mapping_back: self.expr_syntax_mapping_back,
@@ -928,18 +928,18 @@ impl ExprCollector {
928 } 928 }
929} 929}
930 930
931pub(crate) fn body_syntax_mapping(db: &impl HirDatabase, func: Function) -> Arc<BodySyntaxMapping> { 931pub(crate) fn body_source_map(db: &impl HirDatabase, func: Function) -> Arc<BodySourceMap> {
932 let mut collector = ExprCollector::new(func); 932 let mut collector = ExprCollector::new(func);
933 933
934 // TODO: consts, etc. 934 // TODO: consts, etc.
935 collector.collect_fn_body(&func.source(db).1); 935 collector.collect_fn_body(&func.source(db).1);
936 936
937 Arc::new(collector.into_body_syntax_mapping()) 937 Arc::new(collector.into_body_source_map())
938} 938}
939 939
940#[cfg(test)] 940#[cfg(test)]
941pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySyntaxMapping { 941pub(crate) fn collect_fn_body_syntax(function: Function, node: &ast::FnDef) -> BodySourceMap {
942 let mut collector = ExprCollector::new(function); 942 let mut collector = ExprCollector::new(function);
943 collector.collect_fn_body(node); 943 collector.collect_fn_body(node);
944 collector.into_body_syntax_mapping() 944 collector.into_body_source_map()
945} 945}
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index bb8d50db8..bb919dcfa 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -11,7 +11,7 @@ use ra_arena::{Arena, RawId, impl_arena_id};
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Function, 13 Name, AsName, Function,
14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySyntaxMapping}, 14 expr::{PatId, ExprId, Pat, Expr, Body, Statement, BodySourceMap},
15 HirDatabase, 15 HirDatabase,
16}; 16};
17 17
@@ -109,7 +109,7 @@ impl ExprScopes {
109 109
110#[derive(Debug, Clone, PartialEq, Eq)] 110#[derive(Debug, Clone, PartialEq, Eq)]
111pub struct ScopesWithSyntaxMapping { 111pub struct ScopesWithSyntaxMapping {
112 pub syntax_mapping: Arc<BodySyntaxMapping>, 112 pub syntax_mapping: Arc<BodySourceMap>,
113 pub scopes: Arc<ExprScopes>, 113 pub scopes: Arc<ExprScopes>,
114} 114}
115 115
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 8de46a29e..2fdfb54f4 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -1045,11 +1045,11 @@ fn test() {
1045 1045
1046fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 1046fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
1047 let func = source_binder::function_from_position(db, pos).unwrap(); 1047 let func = source_binder::function_from_position(db, pos).unwrap();
1048 let body_syntax_mapping = func.body_syntax_mapping(db); 1048 let body_source_map = func.body_source_map(db);
1049 let inference_result = func.infer(db); 1049 let inference_result = func.infer(db);
1050 let (_, syntax) = func.source(db); 1050 let (_, syntax) = func.source(db);
1051 let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap(); 1051 let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap();
1052 let expr = body_syntax_mapping.node_expr(node).unwrap(); 1052 let expr = body_source_map.node_expr(node).unwrap();
1053 let ty = &inference_result[expr]; 1053 let ty = &inference_result[expr];
1054 ty.to_string() 1054 ty.to_string()
1055} 1055}
@@ -1061,17 +1061,17 @@ fn infer(content: &str) -> String {
1061 for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) { 1061 for fn_def in source_file.syntax().descendants().filter_map(ast::FnDef::cast) {
1062 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); 1062 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
1063 let inference_result = func.infer(&db); 1063 let inference_result = func.infer(&db);
1064 let body_syntax_mapping = func.body_syntax_mapping(&db); 1064 let body_source_map = func.body_source_map(&db);
1065 let mut types = Vec::new(); 1065 let mut types = Vec::new();
1066 for (pat, ty) in inference_result.type_of_pat.iter() { 1066 for (pat, ty) in inference_result.type_of_pat.iter() {
1067 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { 1067 let syntax_ptr = match body_source_map.pat_syntax(pat) {
1068 Some(sp) => sp, 1068 Some(sp) => sp,
1069 None => continue, 1069 None => continue,
1070 }; 1070 };
1071 types.push((syntax_ptr, ty)); 1071 types.push((syntax_ptr, ty));
1072 } 1072 }
1073 for (expr, ty) in inference_result.type_of_expr.iter() { 1073 for (expr, ty) in inference_result.type_of_expr.iter() {
1074 let syntax_ptr = match body_syntax_mapping.expr_syntax(expr) { 1074 let syntax_ptr = match body_source_map.expr_syntax(expr) {
1075 Some(sp) => sp, 1075 Some(sp) => sp,
1076 None => continue, 1076 None => continue,
1077 }; 1077 };