aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/diagnostics.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-17 10:38:51 +0100
committerAleksey Kladov <[email protected]>2020-04-17 11:25:41 +0100
commit302bf97bbf1855e3c7def9ab4f9f3d338be5e3b7 (patch)
treef26fcf569dea4fa40ca3814d30e340572a66374b /crates/ra_hir_ty/src/diagnostics.rs
parent69f0cb6cd77c2dc93f2eed180a6c16fd8c3fca5a (diff)
Don't expose impl details of SyntaxPtr
Diffstat (limited to 'crates/ra_hir_ty/src/diagnostics.rs')
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 927896d6f..da85bd082 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}; 6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr, TextRange};
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,6 +13,7 @@ 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,
16} 17}
17 18
18impl Diagnostic for NoSuchField { 19impl Diagnostic for NoSuchField {
@@ -20,6 +21,10 @@ impl Diagnostic for NoSuchField {
20 "no such field".to_string() 21 "no such field".to_string()
21 } 22 }
22 23
24 fn highlight_range(&self) -> TextRange {
25 self.highlight_range
26 }
27
23 fn source(&self) -> InFile<SyntaxNodePtr> { 28 fn source(&self) -> InFile<SyntaxNodePtr> {
24 InFile { file_id: self.file, value: self.field.clone().into() } 29 InFile { file_id: self.file, value: self.field.clone().into() }
25 } 30 }
@@ -33,6 +38,7 @@ impl Diagnostic for NoSuchField {
33pub struct MissingFields { 38pub struct MissingFields {
34 pub file: HirFileId, 39 pub file: HirFileId,
35 pub field_list: AstPtr<ast::RecordFieldList>, 40 pub field_list: AstPtr<ast::RecordFieldList>,
41 pub highlight_range: TextRange,
36 pub missed_fields: Vec<Name>, 42 pub missed_fields: Vec<Name>,
37} 43}
38 44
@@ -44,6 +50,10 @@ impl Diagnostic for MissingFields {
44 } 50 }
45 buf 51 buf
46 } 52 }
53 fn highlight_range(&self) -> TextRange {
54 self.highlight_range
55 }
56
47 fn source(&self) -> InFile<SyntaxNodePtr> { 57 fn source(&self) -> InFile<SyntaxNodePtr> {
48 InFile { file_id: self.file, value: self.field_list.clone().into() } 58 InFile { file_id: self.file, value: self.field_list.clone().into() }
49 } 59 }
@@ -66,6 +76,7 @@ impl AstDiagnostic for MissingFields {
66pub struct MissingPatFields { 76pub struct MissingPatFields {
67 pub file: HirFileId, 77 pub file: HirFileId,
68 pub field_list: AstPtr<ast::RecordFieldPatList>, 78 pub field_list: AstPtr<ast::RecordFieldPatList>,
79 pub highlight_range: TextRange,
69 pub missed_fields: Vec<Name>, 80 pub missed_fields: Vec<Name>,
70} 81}
71 82
@@ -77,6 +88,9 @@ impl Diagnostic for MissingPatFields {
77 } 88 }
78 buf 89 buf
79 } 90 }
91 fn highlight_range(&self) -> TextRange {
92 self.highlight_range
93 }
80 fn source(&self) -> InFile<SyntaxNodePtr> { 94 fn source(&self) -> InFile<SyntaxNodePtr> {
81 InFile { file_id: self.file, value: self.field_list.clone().into() } 95 InFile { file_id: self.file, value: self.field_list.clone().into() }
82 } 96 }
@@ -90,12 +104,16 @@ pub struct MissingMatchArms {
90 pub file: HirFileId, 104 pub file: HirFileId,
91 pub match_expr: AstPtr<ast::Expr>, 105 pub match_expr: AstPtr<ast::Expr>,
92 pub arms: AstPtr<ast::MatchArmList>, 106 pub arms: AstPtr<ast::MatchArmList>,
107 pub highlight_range: TextRange,
93} 108}
94 109
95impl Diagnostic for MissingMatchArms { 110impl Diagnostic for MissingMatchArms {
96 fn message(&self) -> String { 111 fn message(&self) -> String {
97 String::from("Missing match arm") 112 String::from("Missing match arm")
98 } 113 }
114 fn highlight_range(&self) -> TextRange {
115 self.highlight_range
116 }
99 fn source(&self) -> InFile<SyntaxNodePtr> { 117 fn source(&self) -> InFile<SyntaxNodePtr> {
100 InFile { file_id: self.file, value: self.match_expr.clone().into() } 118 InFile { file_id: self.file, value: self.match_expr.clone().into() }
101 } 119 }
@@ -108,12 +126,16 @@ impl Diagnostic for MissingMatchArms {
108pub struct MissingOkInTailExpr { 126pub struct MissingOkInTailExpr {
109 pub file: HirFileId, 127 pub file: HirFileId,
110 pub expr: AstPtr<ast::Expr>, 128 pub expr: AstPtr<ast::Expr>,
129 pub highlight_range: TextRange,
111} 130}
112 131
113impl Diagnostic for MissingOkInTailExpr { 132impl Diagnostic for MissingOkInTailExpr {
114 fn message(&self) -> String { 133 fn message(&self) -> String {
115 "wrap return expression in Ok".to_string() 134 "wrap return expression in Ok".to_string()
116 } 135 }
136 fn highlight_range(&self) -> TextRange {
137 self.highlight_range
138 }
117 fn source(&self) -> InFile<SyntaxNodePtr> { 139 fn source(&self) -> InFile<SyntaxNodePtr> {
118 InFile { file_id: self.file, value: self.expr.clone().into() } 140 InFile { file_id: self.file, value: self.expr.clone().into() }
119 } 141 }