aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-17 12:55:05 +0100
committerAleksey Kladov <[email protected]>2020-04-17 12:56:42 +0100
commit146f6f5a45a4bfd98ab0eb54bb30610d784433c9 (patch)
treee56f182d50f8863c2535fcd9d736ffb4e3425ae6 /crates/ra_hir_ty
parenta8196ffe8466aa60dec56e77c2da717793c0debe (diff)
Simplify Diagnostic structure
It's not entirely clear what subnode ranges should mean in the presence of macros, so let's leave them out for now. We are not using them heavily anyway.
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs24
-rw-r--r--crates/ra_hir_ty/src/expr.rs14
-rw-r--r--crates/ra_hir_ty/src/infer.rs9
3 files changed, 5 insertions, 42 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 018c2ad3f..c8fd54861 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -3,7 +3,7 @@
3use std::any::Any; 3use std::any::Any;
4 4
5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; 5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr, TextRange}; 6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
7use stdx::format_to; 7use stdx::format_to;
8 8
9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm}; 9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm};
@@ -13,7 +13,6 @@ pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
13pub struct NoSuchField { 13pub struct NoSuchField {
14 pub file: HirFileId, 14 pub file: HirFileId,
15 pub field: AstPtr<ast::RecordField>, 15 pub field: AstPtr<ast::RecordField>,
16 pub highlight_range: TextRange,
17} 16}
18 17
19impl Diagnostic for NoSuchField { 18impl Diagnostic for NoSuchField {
@@ -21,10 +20,6 @@ impl Diagnostic for NoSuchField {
21 "no such field".to_string() 20 "no such field".to_string()
22 } 21 }
23 22
24 fn highlight_range(&self) -> InFile<TextRange> {
25 InFile::new(self.file, self.highlight_range)
26 }
27
28 fn source(&self) -> InFile<SyntaxNodePtr> { 23 fn source(&self) -> InFile<SyntaxNodePtr> {
29 InFile::new(self.file, self.field.clone().into()) 24 InFile::new(self.file, self.field.clone().into())
30 } 25 }
@@ -38,7 +33,6 @@ impl Diagnostic for NoSuchField {
38pub struct MissingFields { 33pub struct MissingFields {
39 pub file: HirFileId, 34 pub file: HirFileId,
40 pub field_list: AstPtr<ast::RecordFieldList>, 35 pub field_list: AstPtr<ast::RecordFieldList>,
41 pub highlight_range: TextRange,
42 pub missed_fields: Vec<Name>, 36 pub missed_fields: Vec<Name>,
43} 37}
44 38
@@ -50,10 +44,6 @@ impl Diagnostic for MissingFields {
50 } 44 }
51 buf 45 buf
52 } 46 }
53 fn highlight_range(&self) -> InFile<TextRange> {
54 InFile::new(self.file, self.highlight_range)
55 }
56
57 fn source(&self) -> InFile<SyntaxNodePtr> { 47 fn source(&self) -> InFile<SyntaxNodePtr> {
58 InFile { file_id: self.file, value: self.field_list.clone().into() } 48 InFile { file_id: self.file, value: self.field_list.clone().into() }
59 } 49 }
@@ -76,7 +66,6 @@ impl AstDiagnostic for MissingFields {
76pub struct MissingPatFields { 66pub struct MissingPatFields {
77 pub file: HirFileId, 67 pub file: HirFileId,
78 pub field_list: AstPtr<ast::RecordFieldPatList>, 68 pub field_list: AstPtr<ast::RecordFieldPatList>,
79 pub highlight_range: TextRange,
80 pub missed_fields: Vec<Name>, 69 pub missed_fields: Vec<Name>,
81} 70}
82 71
@@ -88,9 +77,6 @@ impl Diagnostic for MissingPatFields {
88 } 77 }
89 buf 78 buf
90 } 79 }
91 fn highlight_range(&self) -> InFile<TextRange> {
92 InFile::new(self.file, self.highlight_range)
93 }
94 fn source(&self) -> InFile<SyntaxNodePtr> { 80 fn source(&self) -> InFile<SyntaxNodePtr> {
95 InFile { file_id: self.file, value: self.field_list.clone().into() } 81 InFile { file_id: self.file, value: self.field_list.clone().into() }
96 } 82 }
@@ -104,16 +90,12 @@ pub struct MissingMatchArms {
104 pub file: HirFileId, 90 pub file: HirFileId,
105 pub match_expr: AstPtr<ast::Expr>, 91 pub match_expr: AstPtr<ast::Expr>,
106 pub arms: AstPtr<ast::MatchArmList>, 92 pub arms: AstPtr<ast::MatchArmList>,
107 pub highlight_range: TextRange,
108} 93}
109 94
110impl Diagnostic for MissingMatchArms { 95impl Diagnostic for MissingMatchArms {
111 fn message(&self) -> String { 96 fn message(&self) -> String {
112 String::from("Missing match arm") 97 String::from("Missing match arm")
113 } 98 }
114 fn highlight_range(&self) -> InFile<TextRange> {
115 InFile::new(self.file, self.highlight_range)
116 }
117 fn source(&self) -> InFile<SyntaxNodePtr> { 99 fn source(&self) -> InFile<SyntaxNodePtr> {
118 InFile { file_id: self.file, value: self.match_expr.clone().into() } 100 InFile { file_id: self.file, value: self.match_expr.clone().into() }
119 } 101 }
@@ -126,16 +108,12 @@ impl Diagnostic for MissingMatchArms {
126pub struct MissingOkInTailExpr { 108pub struct MissingOkInTailExpr {
127 pub file: HirFileId, 109 pub file: HirFileId,
128 pub expr: AstPtr<ast::Expr>, 110 pub expr: AstPtr<ast::Expr>,
129 pub highlight_range: TextRange,
130} 111}
131 112
132impl Diagnostic for MissingOkInTailExpr { 113impl Diagnostic for MissingOkInTailExpr {
133 fn message(&self) -> String { 114 fn message(&self) -> String {
134 "wrap return expression in Ok".to_string() 115 "wrap return expression in Ok".to_string()
135 } 116 }
136 fn highlight_range(&self) -> InFile<TextRange> {
137 InFile::new(self.file, self.highlight_range)
138 }
139 fn source(&self) -> InFile<SyntaxNodePtr> { 117 fn source(&self) -> InFile<SyntaxNodePtr> {
140 InFile { file_id: self.file, value: self.expr.clone().into() } 118 InFile { file_id: self.file, value: self.expr.clone().into() }
141 } 119 }
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index 1d3950b70..fd59f4320 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -4,7 +4,7 @@ use std::sync::Arc;
4 4
5use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId}; 5use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId};
6use hir_expand::diagnostics::DiagnosticSink; 6use hir_expand::diagnostics::DiagnosticSink;
7use ra_syntax::{ast, AstNode, AstPtr}; 7use ra_syntax::{ast, AstPtr};
8use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
9 9
10use crate::{ 10use crate::{
@@ -100,7 +100,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
100 self.sink.push(MissingFields { 100 self.sink.push(MissingFields {
101 file: source_ptr.file_id, 101 file: source_ptr.file_id,
102 field_list: AstPtr::new(&field_list), 102 field_list: AstPtr::new(&field_list),
103 highlight_range: field_list.syntax().text_range(),
104 missed_fields, 103 missed_fields,
105 }) 104 })
106 } 105 }
@@ -131,7 +130,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
131 self.sink.push(MissingPatFields { 130 self.sink.push(MissingPatFields {
132 file: source_ptr.file_id, 131 file: source_ptr.file_id,
133 field_list: AstPtr::new(&field_list), 132 field_list: AstPtr::new(&field_list),
134 highlight_range: field_list.syntax().text_range(),
135 missed_fields, 133 missed_fields,
136 }) 134 })
137 } 135 }
@@ -215,7 +213,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
215 file: source_ptr.file_id, 213 file: source_ptr.file_id,
216 match_expr: AstPtr::new(&match_expr), 214 match_expr: AstPtr::new(&match_expr),
217 arms: AstPtr::new(&arms), 215 arms: AstPtr::new(&arms),
218 highlight_range: match_expr.syntax().text_range(),
219 }) 216 })
220 } 217 }
221 } 218 }
@@ -247,13 +244,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
247 let (_, source_map) = db.body_with_source_map(self.func.into()); 244 let (_, source_map) = db.body_with_source_map(self.func.into());
248 245
249 if let Ok(source_ptr) = source_map.expr_syntax(id) { 246 if let Ok(source_ptr) = source_map.expr_syntax(id) {
250 let root = source_ptr.file_syntax(db.upcast()); 247 self.sink
251 let highlight_range = source_ptr.value.to_node(&root).syntax().text_range(); 248 .push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value });
252 self.sink.push(MissingOkInTailExpr {
253 file: source_ptr.file_id,
254 expr: source_ptr.value,
255 highlight_range,
256 });
257 } 249 }
258 } 250 }
259 } 251 }
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index 7e6cdefe4..b6d9b3438 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -665,7 +665,6 @@ impl Expectation {
665mod diagnostics { 665mod diagnostics {
666 use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup}; 666 use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
667 use hir_expand::diagnostics::DiagnosticSink; 667 use hir_expand::diagnostics::DiagnosticSink;
668 use ra_syntax::AstNode;
669 668
670 use crate::{db::HirDatabase, diagnostics::NoSuchField}; 669 use crate::{db::HirDatabase, diagnostics::NoSuchField};
671 670
@@ -686,13 +685,7 @@ mod diagnostics {
686 let source = owner.lookup(db.upcast()).source(db.upcast()); 685 let source = owner.lookup(db.upcast()).source(db.upcast());
687 let (_, source_map) = db.body_with_source_map(owner.into()); 686 let (_, source_map) = db.body_with_source_map(owner.into());
688 let field = source_map.field_syntax(*expr, *field); 687 let field = source_map.field_syntax(*expr, *field);
689 let root = field.file_syntax(db.upcast()); 688 sink.push(NoSuchField { file: source.file_id, field: field.value })
690 let highlight_range = field.value.to_node(&root).syntax().text_range();
691 sink.push(NoSuchField {
692 file: source.file_id,
693 field: field.value,
694 highlight_range,
695 })
696 } 689 }
697 } 690 }
698 } 691 }