diff options
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 52 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics/expr.rs | 1 |
2 files changed, 49 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 977c0525b..a5b00ed48 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -9,7 +9,7 @@ use hir_def::DefWithBodyId; | |||
9 | use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; | 9 | use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; |
10 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; | 10 | use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; |
11 | use ra_prof::profile; | 11 | use ra_prof::profile; |
12 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; | 12 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr}; |
13 | use stdx::format_to; | 13 | use stdx::format_to; |
14 | 14 | ||
15 | use crate::db::HirDatabase; | 15 | use crate::db::HirDatabase; |
@@ -61,6 +61,17 @@ pub struct MissingFields { | |||
61 | pub file: HirFileId, | 61 | pub file: HirFileId, |
62 | pub field_list: AstPtr<ast::RecordExprFieldList>, | 62 | pub field_list: AstPtr<ast::RecordExprFieldList>, |
63 | pub missed_fields: Vec<Name>, | 63 | pub missed_fields: Vec<Name>, |
64 | pub list_parent_path: Option<AstPtr<ast::Path>>, | ||
65 | } | ||
66 | |||
67 | impl MissingFields { | ||
68 | fn root(&self, db: &dyn AstDatabase) -> SyntaxNode { | ||
69 | db.parse_or_expand(self.file).unwrap() | ||
70 | } | ||
71 | |||
72 | pub fn list_parent_ast(&self, db: &dyn AstDatabase) -> Option<ast::Path> { | ||
73 | self.list_parent_path.as_ref().map(|path| path.to_node(&self.root(db))) | ||
74 | } | ||
64 | } | 75 | } |
65 | 76 | ||
66 | impl Diagnostic for MissingFields { | 77 | impl Diagnostic for MissingFields { |
@@ -83,9 +94,7 @@ impl AstDiagnostic for MissingFields { | |||
83 | type AST = ast::RecordExprFieldList; | 94 | type AST = ast::RecordExprFieldList; |
84 | 95 | ||
85 | fn ast(&self, db: &dyn AstDatabase) -> Self::AST { | 96 | fn ast(&self, db: &dyn AstDatabase) -> Self::AST { |
86 | let root = db.parse_or_expand(self.source().file_id).unwrap(); | 97 | self.field_list.to_node(&self.root(db)) |
87 | let node = self.source().value.to_node(&root); | ||
88 | ast::RecordExprFieldList::cast(node).unwrap() | ||
89 | } | 98 | } |
90 | } | 99 | } |
91 | 100 | ||
@@ -319,6 +328,41 @@ mod tests { | |||
319 | } | 328 | } |
320 | 329 | ||
321 | #[test] | 330 | #[test] |
331 | fn structure_name_highlighted_for_missing_fields() { | ||
332 | check_diagnostics( | ||
333 | r#" | ||
334 | struct Beefy { | ||
335 | one: i32, | ||
336 | two: i32, | ||
337 | three: i32, | ||
338 | four: i32, | ||
339 | five: i32, | ||
340 | six: i32, | ||
341 | seven: i32, | ||
342 | eight: i32, | ||
343 | nine: i32, | ||
344 | ten: i32, | ||
345 | } | ||
346 | fn baz() { | ||
347 | let zz = Beefy { | ||
348 | //^^^^^... Missing structure fields: | ||
349 | // | - seven | ||
350 | one: (), | ||
351 | two: (), | ||
352 | three: (), | ||
353 | four: (), | ||
354 | five: (), | ||
355 | six: (), | ||
356 | eight: (), | ||
357 | nine: (), | ||
358 | ten: (), | ||
359 | }; | ||
360 | } | ||
361 | "#, | ||
362 | ); | ||
363 | } | ||
364 | |||
365 | #[test] | ||
322 | fn no_such_field_diagnostics() { | 366 | fn no_such_field_diagnostics() { |
323 | check_diagnostics( | 367 | check_diagnostics( |
324 | r#" | 368 | r#" |
diff --git a/crates/ra_hir_ty/src/diagnostics/expr.rs b/crates/ra_hir_ty/src/diagnostics/expr.rs index 95bbf2d95..3c37fc58e 100644 --- a/crates/ra_hir_ty/src/diagnostics/expr.rs +++ b/crates/ra_hir_ty/src/diagnostics/expr.rs | |||
@@ -111,6 +111,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
111 | file: source_ptr.file_id, | 111 | file: source_ptr.file_id, |
112 | field_list: AstPtr::new(&field_list), | 112 | field_list: AstPtr::new(&field_list), |
113 | missed_fields, | 113 | missed_fields, |
114 | list_parent_path: record_lit.path().map(|path| AstPtr::new(&path)), | ||
114 | }) | 115 | }) |
115 | } | 116 | } |
116 | } | 117 | } |