diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-02 14:09:46 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-02 14:09:46 +0000 |
commit | fd7240837b5fab6b2854bb63aa3b5c7771b4ddc0 (patch) | |
tree | 88b876a78136413b8fbdf59a524e1bcf12d17f78 /crates/ra_ide_api/src | |
parent | 30b87eb88073e48b8cde416ca7ff4eb59e408e20 (diff) | |
parent | f0a9d026fcd8bea1944287b1fe7c6573ca62ca9d (diff) |
Merge #915
915: Bring BodySyntaxMapping in line with other source-map instances r=flodiebold a=matklad
* rename to SourceMap
* don't store the actual body inline, just return a pair
r? @flodiebold
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_struct_literal.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 17 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 6 |
5 files changed, 17 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 3f041f9c3..0c90ed5b5 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -223,8 +223,7 @@ impl RootDatabase { | |||
223 | self.query(hir::db::FileItemsQuery).sweep(sweep); | 223 | self.query(hir::db::FileItemsQuery).sweep(sweep); |
224 | self.query(hir::db::FileItemQuery).sweep(sweep); | 224 | self.query(hir::db::FileItemQuery).sweep(sweep); |
225 | 225 | ||
226 | self.query(hir::db::LowerModuleQuery).sweep(sweep); | 226 | self.query(hir::db::LowerModuleWithSourceMapQuery).sweep(sweep); |
227 | self.query(hir::db::LowerModuleSourceMapQuery).sweep(sweep); | 227 | self.query(hir::db::BodyWithSourceMapQuery).sweep(sweep); |
228 | self.query(hir::db::BodySyntaxMappingQuery).sweep(sweep); | ||
229 | } | 228 | } |
230 | } | 229 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index d5ad2e79f..94c66be31 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -9,8 +9,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | |||
9 | _ => return, | 9 | _ => return, |
10 | }; | 10 | }; |
11 | let infer_result = function.infer(ctx.db); | 11 | let infer_result = function.infer(ctx.db); |
12 | let syntax_mapping = function.body_syntax_mapping(ctx.db); | 12 | let source_map = function.body_source_map(ctx.db); |
13 | let expr = match syntax_mapping.node_expr(receiver) { | 13 | let expr = match source_map.node_expr(receiver) { |
14 | Some(expr) => expr, | 14 | Some(expr) => expr, |
15 | None => return, | 15 | None => return, |
16 | }; | 16 | }; |
diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index afb092f59..6bef9624e 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs | |||
@@ -9,8 +9,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon | |||
9 | _ => return, | 9 | _ => return, |
10 | }; | 10 | }; |
11 | let infer_result = function.infer(ctx.db); | 11 | let infer_result = function.infer(ctx.db); |
12 | let syntax_mapping = function.body_syntax_mapping(ctx.db); | 12 | let source_map = function.body_source_map(ctx.db); |
13 | let expr = match syntax_mapping.node_expr(struct_lit.into()) { | 13 | let expr = match source_map.node_expr(struct_lit.into()) { |
14 | Some(expr) => expr, | 14 | Some(expr) => expr, |
15 | None => return, | 15 | None => return, |
16 | }; | 16 | }; |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 6fa430754..9ec179593 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -54,10 +54,10 @@ pub(crate) fn reference_definition( | |||
54 | if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) { | 54 | if let Some(method_call) = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast) { |
55 | tested_by!(goto_definition_works_for_methods); | 55 | tested_by!(goto_definition_works_for_methods); |
56 | let infer_result = function.infer(db); | 56 | let infer_result = function.infer(db); |
57 | let syntax_mapping = function.body_syntax_mapping(db); | 57 | let source_map = function.body_source_map(db); |
58 | let expr = ast::Expr::cast(method_call.syntax()).unwrap(); | 58 | let expr = ast::Expr::cast(method_call.syntax()).unwrap(); |
59 | if let Some(func) = | 59 | if let Some(func) = |
60 | syntax_mapping.node_expr(expr).and_then(|it| infer_result.method_resolution(it)) | 60 | source_map.node_expr(expr).and_then(|it| infer_result.method_resolution(it)) |
61 | { | 61 | { |
62 | return Exact(NavigationTarget::from_function(db, func)); | 62 | return Exact(NavigationTarget::from_function(db, func)); |
63 | }; | 63 | }; |
@@ -66,10 +66,10 @@ pub(crate) fn reference_definition( | |||
66 | if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) { | 66 | if let Some(field_expr) = name_ref.syntax().parent().and_then(ast::FieldExpr::cast) { |
67 | tested_by!(goto_definition_works_for_fields); | 67 | tested_by!(goto_definition_works_for_fields); |
68 | let infer_result = function.infer(db); | 68 | let infer_result = function.infer(db); |
69 | let syntax_mapping = function.body_syntax_mapping(db); | 69 | let source_map = function.body_source_map(db); |
70 | let expr = ast::Expr::cast(field_expr.syntax()).unwrap(); | 70 | let expr = ast::Expr::cast(field_expr.syntax()).unwrap(); |
71 | if let Some(field) = | 71 | if let Some(field) = |
72 | syntax_mapping.node_expr(expr).and_then(|it| infer_result.field_resolution(it)) | 72 | source_map.node_expr(expr).and_then(|it| infer_result.field_resolution(it)) |
73 | { | 73 | { |
74 | return Exact(NavigationTarget::from_field(db, field)); | 74 | return Exact(NavigationTarget::from_field(db, field)); |
75 | }; | 75 | }; |
@@ -80,11 +80,11 @@ pub(crate) fn reference_definition( | |||
80 | tested_by!(goto_definition_works_for_named_fields); | 80 | tested_by!(goto_definition_works_for_named_fields); |
81 | 81 | ||
82 | let infer_result = function.infer(db); | 82 | let infer_result = function.infer(db); |
83 | let syntax_mapping = function.body_syntax_mapping(db); | 83 | let source_map = function.body_source_map(db); |
84 | 84 | ||
85 | let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast); | 85 | let struct_lit = field_expr.syntax().ancestors().find_map(ast::StructLit::cast); |
86 | 86 | ||
87 | if let Some(expr) = struct_lit.and_then(|lit| syntax_mapping.node_expr(lit.into())) { | 87 | if let Some(expr) = struct_lit.and_then(|lit| source_map.node_expr(lit.into())) { |
88 | let ty = infer_result[expr].clone(); | 88 | let ty = infer_result[expr].clone(); |
89 | if let hir::Ty::Adt { def_id, .. } = ty { | 89 | if let hir::Ty::Adt { def_id, .. } = ty { |
90 | if let hir::AdtDef::Struct(s) = def_id { | 90 | if let hir::AdtDef::Struct(s) = def_id { |
@@ -109,9 +109,8 @@ pub(crate) fn reference_definition( | |||
109 | Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), | 109 | Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), |
110 | Some(Resolution::LocalBinding(pat)) => { | 110 | Some(Resolution::LocalBinding(pat)) => { |
111 | let body = resolver.body().expect("no body for local binding"); | 111 | let body = resolver.body().expect("no body for local binding"); |
112 | let syntax_mapping = body.syntax_mapping(db); | 112 | let source_map = body.owner().body_source_map(db); |
113 | let ptr = | 113 | let ptr = source_map.pat_syntax(pat).expect("pattern not found in syntax mapping"); |
114 | syntax_mapping.pat_syntax(pat).expect("pattern not found in syntax mapping"); | ||
115 | let name = | 114 | let name = |
116 | path.as_ident().cloned().expect("local binding from a multi-segment path"); | 115 | path.as_ident().cloned().expect("local binding from a multi-segment path"); |
117 | let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); | 116 | let nav = NavigationTarget::from_scope_entry(file_id, name, ptr); |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 1a1853df3..a2d203b4f 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -132,10 +132,10 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> { | |||
132 | let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?; | 132 | let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?; |
133 | let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?; | 133 | let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?; |
134 | let infer = function.infer(db); | 134 | let infer = function.infer(db); |
135 | let syntax_mapping = function.body_syntax_mapping(db); | 135 | let source_map = function.body_source_map(db); |
136 | if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { | 136 | if let Some(expr) = ast::Expr::cast(node).and_then(|e| source_map.node_expr(e)) { |
137 | Some(infer[expr].to_string()) | 137 | Some(infer[expr].to_string()) |
138 | } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { | 138 | } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| source_map.node_pat(p)) { |
139 | Some(infer[pat].to_string()) | 139 | Some(infer[pat].to_string()) |
140 | } else { | 140 | } else { |
141 | None | 141 | None |