diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 55 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 12 |
8 files changed, 40 insertions, 55 deletions
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 05147901e..58ae6ce41 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -317,8 +317,7 @@ fn scope_for_offset( | |||
317 | if source.file_id != offset.file_id { | 317 | if source.file_id != offset.file_id { |
318 | return None; | 318 | return None; |
319 | } | 319 | } |
320 | let syntax_node_ptr = | 320 | let syntax_node_ptr = source.value.syntax_node_ptr(); |
321 | source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); | ||
322 | Some((syntax_node_ptr, scope)) | 321 | Some((syntax_node_ptr, scope)) |
323 | }) | 322 | }) |
324 | // find containing scope | 323 | // find containing scope |
@@ -397,8 +396,7 @@ fn adjust( | |||
397 | if source.file_id != file_id { | 396 | if source.file_id != file_id { |
398 | return None; | 397 | return None; |
399 | } | 398 | } |
400 | let syntax_node_ptr = | 399 | let syntax_node_ptr = source.value.syntax_node_ptr(); |
401 | source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()); | ||
402 | Some((syntax_node_ptr, scope)) | 400 | Some((syntax_node_ptr, scope)) |
403 | }) | 401 | }) |
404 | .map(|(ptr, scope)| (ptr.range(), scope)) | 402 | .map(|(ptr, scope)| (ptr.range(), scope)) |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 67d623714..eafaf48c1 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -9,6 +9,8 @@ use drop_bomb::DropBomb; | |||
9 | use either::Either; | 9 | use either::Either; |
10 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId}; | 10 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId}; |
11 | use ra_arena::{map::ArenaMap, Arena}; | 11 | use ra_arena::{map::ArenaMap, Arena}; |
12 | use ra_cfg::CfgOptions; | ||
13 | use ra_db::CrateId; | ||
12 | use ra_prof::profile; | 14 | use ra_prof::profile; |
13 | use ra_syntax::{ast, AstNode, AstPtr}; | 15 | use ra_syntax::{ast, AstNode, AstPtr}; |
14 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
@@ -24,8 +26,6 @@ use crate::{ | |||
24 | src::HasSource, | 26 | src::HasSource, |
25 | AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, | 27 | AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, |
26 | }; | 28 | }; |
27 | use ra_cfg::CfgOptions; | ||
28 | use ra_db::CrateId; | ||
29 | 29 | ||
30 | /// A subser of Exander that only deals with cfg attributes. We only need it to | 30 | /// A subser of Exander that only deals with cfg attributes. We only need it to |
31 | /// avoid cyclic queries in crate def map during enum processing. | 31 | /// avoid cyclic queries in crate def map during enum processing. |
@@ -187,7 +187,7 @@ pub struct Body { | |||
187 | pub item_scope: ItemScope, | 187 | pub item_scope: ItemScope, |
188 | } | 188 | } |
189 | 189 | ||
190 | pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>; | 190 | pub type ExprPtr = AstPtr<ast::Expr>; |
191 | pub type ExprSource = InFile<ExprPtr>; | 191 | pub type ExprSource = InFile<ExprPtr>; |
192 | 192 | ||
193 | pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; | 193 | pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; |
@@ -285,7 +285,7 @@ impl BodySourceMap { | |||
285 | } | 285 | } |
286 | 286 | ||
287 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { | 287 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { |
288 | let src = node.map(|it| Either::Left(AstPtr::new(it))); | 288 | let src = node.map(|it| AstPtr::new(it)); |
289 | self.expr_map.get(&src).cloned() | 289 | self.expr_map.get(&src).cloned() |
290 | } | 290 | } |
291 | 291 | ||
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 990761661..cc2532e88 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -101,7 +101,6 @@ impl ExprCollector<'_> { | |||
101 | } | 101 | } |
102 | 102 | ||
103 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { | 103 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { |
104 | let ptr = Either::Left(ptr); | ||
105 | let src = self.expander.to_source(ptr); | 104 | let src = self.expander.to_source(ptr); |
106 | let id = self.make_expr(expr, Ok(src.clone())); | 105 | let id = self.make_expr(expr, Ok(src.clone())); |
107 | self.source_map.expr_map.insert(src, id); | 106 | self.source_map.expr_map.insert(src, id); |
@@ -281,7 +280,7 @@ impl ExprCollector<'_> { | |||
281 | ast::Expr::ParenExpr(e) => { | 280 | ast::Expr::ParenExpr(e) => { |
282 | let inner = self.collect_expr_opt(e.expr()); | 281 | let inner = self.collect_expr_opt(e.expr()); |
283 | // make the paren expr point to the inner expression as well | 282 | // make the paren expr point to the inner expression as well |
284 | let src = self.expander.to_source(Either::Left(syntax_ptr)); | 283 | let src = self.expander.to_source(syntax_ptr); |
285 | self.source_map.expr_map.insert(src, inner); | 284 | self.source_map.expr_map.insert(src, inner); |
286 | inner | 285 | inner |
287 | } | 286 | } |
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index 827b687de..69b527f74 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -89,21 +89,19 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
89 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 89 | let (_, source_map) = db.body_with_source_map(self.func.into()); |
90 | 90 | ||
91 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 91 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
92 | if let Some(expr) = source_ptr.value.as_ref().left() { | 92 | let root = source_ptr.file_syntax(db.upcast()); |
93 | let root = source_ptr.file_syntax(db.upcast()); | 93 | if let ast::Expr::RecordLit(record_lit) = &source_ptr.value.to_node(&root) { |
94 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { | 94 | if let Some(field_list) = record_lit.record_field_list() { |
95 | if let Some(field_list) = record_lit.record_field_list() { | 95 | let variant_data = variant_data(db.upcast(), variant_def); |
96 | let variant_data = variant_data(db.upcast(), variant_def); | 96 | let missed_fields = missed_fields |
97 | let missed_fields = missed_fields | 97 | .into_iter() |
98 | .into_iter() | 98 | .map(|idx| variant_data.fields()[idx].name.clone()) |
99 | .map(|idx| variant_data.fields()[idx].name.clone()) | 99 | .collect(); |
100 | .collect(); | 100 | self.sink.push(MissingFields { |
101 | self.sink.push(MissingFields { | 101 | file: source_ptr.file_id, |
102 | file: source_ptr.file_id, | 102 | field_list: AstPtr::new(&field_list), |
103 | field_list: AstPtr::new(&field_list), | 103 | missed_fields, |
104 | missed_fields, | 104 | }) |
105 | }) | ||
106 | } | ||
107 | } | 105 | } |
108 | } | 106 | } |
109 | } | 107 | } |
@@ -205,18 +203,16 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
205 | } | 203 | } |
206 | 204 | ||
207 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 205 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
208 | if let Some(expr) = source_ptr.value.as_ref().left() { | 206 | let root = source_ptr.file_syntax(db.upcast()); |
209 | let root = source_ptr.file_syntax(db.upcast()); | 207 | if let ast::Expr::MatchExpr(match_expr) = &source_ptr.value.to_node(&root) { |
210 | if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) { | 208 | if let (Some(match_expr), Some(arms)) = |
211 | if let (Some(match_expr), Some(arms)) = | 209 | (match_expr.expr(), match_expr.match_arm_list()) |
212 | (match_expr.expr(), match_expr.match_arm_list()) | 210 | { |
213 | { | 211 | self.sink.push(MissingMatchArms { |
214 | self.sink.push(MissingMatchArms { | 212 | file: source_ptr.file_id, |
215 | file: source_ptr.file_id, | 213 | match_expr: AstPtr::new(&match_expr), |
216 | match_expr: AstPtr::new(&match_expr), | 214 | arms: AstPtr::new(&arms), |
217 | arms: AstPtr::new(&arms), | 215 | }) |
218 | }) | ||
219 | } | ||
220 | } | 216 | } |
221 | } | 217 | } |
222 | } | 218 | } |
@@ -247,9 +243,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
247 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 243 | let (_, source_map) = db.body_with_source_map(self.func.into()); |
248 | 244 | ||
249 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 245 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
250 | if let Some(expr) = source_ptr.value.left() { | 246 | self.sink |
251 | self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr }); | 247 | .push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value }); |
252 | } | ||
253 | } | 248 | } |
254 | } | 249 | } |
255 | } | 250 | } |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 54e31602f..81fc0f63a 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -82,9 +82,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
82 | 82 | ||
83 | for (expr, ty) in inference_result.type_of_expr.iter() { | 83 | for (expr, ty) in inference_result.type_of_expr.iter() { |
84 | let syntax_ptr = match body_source_map.expr_syntax(expr) { | 84 | let syntax_ptr = match body_source_map.expr_syntax(expr) { |
85 | Ok(sp) => { | 85 | Ok(sp) => sp.map(|ast| ast.syntax_node_ptr()), |
86 | sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr())) | ||
87 | } | ||
88 | Err(SyntheticSyntax) => continue, | 86 | Err(SyntheticSyntax) => continue, |
89 | }; | 87 | }; |
90 | types.push((syntax_ptr.clone(), ty)); | 88 | types.push((syntax_ptr.clone(), ty)); |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 7dc024991..63e272fbf 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -189,8 +189,6 @@ impl ast::StructDef { | |||
189 | 189 | ||
190 | impl ast::RecordField { | 190 | impl ast::RecordField { |
191 | pub fn for_field_name(field_name: &ast::NameRef) -> Option<ast::RecordField> { | 191 | pub fn for_field_name(field_name: &ast::NameRef) -> Option<ast::RecordField> { |
192 | eprintln!("field_name = {}", field_name); | ||
193 | dbg!(field_name.syntax().ancestors().nth(6)); | ||
194 | let candidate = | 192 | let candidate = |
195 | field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| { | 193 | field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| { |
196 | field_name.syntax().ancestors().nth(4).and_then(ast::RecordField::cast) | 194 | field_name.syntax().ancestors().nth(4).and_then(ast::RecordField::cast) |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index f0e16dc2b..a796e78b1 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -19,6 +19,11 @@ | |||
19 | //! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256> | 19 | //! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256> |
20 | //! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md> | 20 | //! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md> |
21 | 21 | ||
22 | #[allow(unused)] | ||
23 | macro_rules! eprintln { | ||
24 | ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; | ||
25 | } | ||
26 | |||
22 | mod syntax_node; | 27 | mod syntax_node; |
23 | mod syntax_error; | 28 | mod syntax_error; |
24 | mod parsing; | 29 | mod parsing; |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 75cf2dae5..e9ee0b888 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -163,10 +163,7 @@ pub fn analysis_stats( | |||
163 | if let Ok(src) = src { | 163 | if let Ok(src) = src { |
164 | let original_file = src.file_id.original_file(db); | 164 | let original_file = src.file_id.original_file(db); |
165 | let line_index = host.analysis().file_line_index(original_file).unwrap(); | 165 | let line_index = host.analysis().file_line_index(original_file).unwrap(); |
166 | let text_range = src.value.either( | 166 | let text_range = src.value.syntax_node_ptr().range(); |
167 | |it| it.syntax_node_ptr().range(), | ||
168 | |it| it.syntax_node_ptr().range(), | ||
169 | ); | ||
170 | let (start, end) = ( | 167 | let (start, end) = ( |
171 | line_index.line_col(text_range.start()), | 168 | line_index.line_col(text_range.start()), |
172 | line_index.line_col(text_range.end()), | 169 | line_index.line_col(text_range.end()), |
@@ -192,12 +189,7 @@ pub fn analysis_stats( | |||
192 | // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly | 189 | // FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly |
193 | // But also, we should just turn the type mismatches into diagnostics and provide these | 190 | // But also, we should just turn the type mismatches into diagnostics and provide these |
194 | let root = db.parse_or_expand(src.file_id).unwrap(); | 191 | let root = db.parse_or_expand(src.file_id).unwrap(); |
195 | let node = src.map(|e| { | 192 | let node = src.map(|e| e.to_node(&root).syntax().clone()); |
196 | e.either( | ||
197 | |p| p.to_node(&root).syntax().clone(), | ||
198 | |p| p.to_node(&root).syntax().clone(), | ||
199 | ) | ||
200 | }); | ||
201 | let original_range = original_range(db, node.as_ref()); | 193 | let original_range = original_range(db, node.as_ref()); |
202 | let path = db.file_relative_path(original_range.file_id); | 194 | let path = db.file_relative_path(original_range.file_id); |
203 | let line_index = | 195 | let line_index = |