Skip to content

Commit 146f6f5

Browse files
committed
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.
1 parent a8196ff commit 146f6f5

File tree

6 files changed

+8
-51
lines changed

6 files changed

+8
-51
lines changed

crates/ra_hir_def/src/diagnostics.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@ use std::any::Any;
44

55
use hir_expand::diagnostics::Diagnostic;
66
use ra_db::RelativePathBuf;
7-
use ra_syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
7+
use ra_syntax::{ast, AstPtr, SyntaxNodePtr};
88

99
use hir_expand::{HirFileId, InFile};
1010

1111
#[derive(Debug)]
1212
pub struct UnresolvedModule {
1313
pub file: HirFileId,
1414
pub decl: AstPtr<ast::Module>,
15-
pub highlight_range: TextRange,
1615
pub candidate: RelativePathBuf,
1716
}
1817

1918
impl Diagnostic for UnresolvedModule {
2019
fn message(&self) -> String {
2120
"unresolved module".to_string()
2221
}
23-
fn highlight_range(&self) -> InFile<TextRange> {
24-
InFile::new(self.file, self.highlight_range)
25-
}
2622
fn source(&self) -> InFile<SyntaxNodePtr> {
2723
InFile::new(self.file, self.decl.clone().into())
2824
}

crates/ra_hir_def/src/nameres.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pub enum ModuleSource {
297297
mod diagnostics {
298298
use hir_expand::diagnostics::DiagnosticSink;
299299
use ra_db::RelativePathBuf;
300-
use ra_syntax::{ast, AstNode, AstPtr};
300+
use ra_syntax::{ast, AstPtr};
301301

302302
use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId};
303303

@@ -326,7 +326,6 @@ mod diagnostics {
326326
sink.push(UnresolvedModule {
327327
file: declaration.file_id,
328328
decl: AstPtr::new(&decl),
329-
highlight_range: decl.syntax().text_range(),
330329
candidate: candidate.clone(),
331330
})
332331
}

crates/ra_hir_expand/src/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
1717
use std::{any::Any, fmt};
1818

19-
use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange};
19+
use ra_syntax::{SyntaxNode, SyntaxNodePtr};
2020

2121
use crate::{db::AstDatabase, InFile};
2222

2323
pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
2424
fn message(&self) -> String;
25-
fn highlight_range(&self) -> InFile<TextRange>;
2625
fn source(&self) -> InFile<SyntaxNodePtr>;
2726
fn as_any(&self) -> &(dyn Any + Send + 'static);
2827
}

crates/ra_hir_ty/src/diagnostics.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::any::Any;
44

55
use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
6-
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr, TextRange};
6+
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
77
use stdx::format_to;
88

99
pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm};
@@ -13,18 +13,13 @@ pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
1313
pub struct NoSuchField {
1414
pub file: HirFileId,
1515
pub field: AstPtr<ast::RecordField>,
16-
pub highlight_range: TextRange,
1716
}
1817

1918
impl Diagnostic for NoSuchField {
2019
fn message(&self) -> String {
2120
"no such field".to_string()
2221
}
2322

24-
fn highlight_range(&self) -> InFile<TextRange> {
25-
InFile::new(self.file, self.highlight_range)
26-
}
27-
2823
fn source(&self) -> InFile<SyntaxNodePtr> {
2924
InFile::new(self.file, self.field.clone().into())
3025
}
@@ -38,7 +33,6 @@ impl Diagnostic for NoSuchField {
3833
pub struct MissingFields {
3934
pub file: HirFileId,
4035
pub field_list: AstPtr<ast::RecordFieldList>,
41-
pub highlight_range: TextRange,
4236
pub missed_fields: Vec<Name>,
4337
}
4438

@@ -50,10 +44,6 @@ impl Diagnostic for MissingFields {
5044
}
5145
buf
5246
}
53-
fn highlight_range(&self) -> InFile<TextRange> {
54-
InFile::new(self.file, self.highlight_range)
55-
}
56-
5747
fn source(&self) -> InFile<SyntaxNodePtr> {
5848
InFile { file_id: self.file, value: self.field_list.clone().into() }
5949
}
@@ -76,7 +66,6 @@ impl AstDiagnostic for MissingFields {
7666
pub struct MissingPatFields {
7767
pub file: HirFileId,
7868
pub field_list: AstPtr<ast::RecordFieldPatList>,
79-
pub highlight_range: TextRange,
8069
pub missed_fields: Vec<Name>,
8170
}
8271

@@ -88,9 +77,6 @@ impl Diagnostic for MissingPatFields {
8877
}
8978
buf
9079
}
91-
fn highlight_range(&self) -> InFile<TextRange> {
92-
InFile::new(self.file, self.highlight_range)
93-
}
9480
fn source(&self) -> InFile<SyntaxNodePtr> {
9581
InFile { file_id: self.file, value: self.field_list.clone().into() }
9682
}
@@ -104,16 +90,12 @@ pub struct MissingMatchArms {
10490
pub file: HirFileId,
10591
pub match_expr: AstPtr<ast::Expr>,
10692
pub arms: AstPtr<ast::MatchArmList>,
107-
pub highlight_range: TextRange,
10893
}
10994

11095
impl Diagnostic for MissingMatchArms {
11196
fn message(&self) -> String {
11297
String::from("Missing match arm")
11398
}
114-
fn highlight_range(&self) -> InFile<TextRange> {
115-
InFile::new(self.file, self.highlight_range)
116-
}
11799
fn source(&self) -> InFile<SyntaxNodePtr> {
118100
InFile { file_id: self.file, value: self.match_expr.clone().into() }
119101
}
@@ -126,16 +108,12 @@ impl Diagnostic for MissingMatchArms {
126108
pub struct MissingOkInTailExpr {
127109
pub file: HirFileId,
128110
pub expr: AstPtr<ast::Expr>,
129-
pub highlight_range: TextRange,
130111
}
131112

132113
impl Diagnostic for MissingOkInTailExpr {
133114
fn message(&self) -> String {
134115
"wrap return expression in Ok".to_string()
135116
}
136-
fn highlight_range(&self) -> InFile<TextRange> {
137-
InFile::new(self.file, self.highlight_range)
138-
}
139117
fn source(&self) -> InFile<SyntaxNodePtr> {
140118
InFile { file_id: self.file, value: self.expr.clone().into() }
141119
}

crates/ra_hir_ty/src/expr.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::Arc;
44

55
use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId};
66
use hir_expand::diagnostics::DiagnosticSink;
7-
use ra_syntax::{ast, AstNode, AstPtr};
7+
use ra_syntax::{ast, AstPtr};
88
use rustc_hash::FxHashSet;
99

1010
use crate::{
@@ -100,7 +100,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
100100
self.sink.push(MissingFields {
101101
file: source_ptr.file_id,
102102
field_list: AstPtr::new(&field_list),
103-
highlight_range: field_list.syntax().text_range(),
104103
missed_fields,
105104
})
106105
}
@@ -131,7 +130,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
131130
self.sink.push(MissingPatFields {
132131
file: source_ptr.file_id,
133132
field_list: AstPtr::new(&field_list),
134-
highlight_range: field_list.syntax().text_range(),
135133
missed_fields,
136134
})
137135
}
@@ -215,7 +213,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
215213
file: source_ptr.file_id,
216214
match_expr: AstPtr::new(&match_expr),
217215
arms: AstPtr::new(&arms),
218-
highlight_range: match_expr.syntax().text_range(),
219216
})
220217
}
221218
}
@@ -247,13 +244,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
247244
let (_, source_map) = db.body_with_source_map(self.func.into());
248245

249246
if let Ok(source_ptr) = source_map.expr_syntax(id) {
250-
let root = source_ptr.file_syntax(db.upcast());
251-
let highlight_range = source_ptr.value.to_node(&root).syntax().text_range();
252-
self.sink.push(MissingOkInTailExpr {
253-
file: source_ptr.file_id,
254-
expr: source_ptr.value,
255-
highlight_range,
256-
});
247+
self.sink
248+
.push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value });
257249
}
258250
}
259251
}

crates/ra_hir_ty/src/infer.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ impl Expectation {
665665
mod diagnostics {
666666
use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
667667
use hir_expand::diagnostics::DiagnosticSink;
668-
use ra_syntax::AstNode;
669668

670669
use crate::{db::HirDatabase, diagnostics::NoSuchField};
671670

@@ -686,13 +685,7 @@ mod diagnostics {
686685
let source = owner.lookup(db.upcast()).source(db.upcast());
687686
let (_, source_map) = db.body_with_source_map(owner.into());
688687
let field = source_map.field_syntax(*expr, *field);
689-
let root = field.file_syntax(db.upcast());
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-
})
688+
sink.push(NoSuchField { file: source.file_id, field: field.value })
696689
}
697690
}
698691
}

0 commit comments

Comments
 (0)