mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
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.
This commit is contained in:
parent
a8196ffe84
commit
146f6f5a45
6 changed files with 8 additions and 51 deletions
|
@ -4,7 +4,7 @@ use std::any::Any;
|
||||||
|
|
||||||
use hir_expand::diagnostics::Diagnostic;
|
use hir_expand::diagnostics::Diagnostic;
|
||||||
use ra_db::RelativePathBuf;
|
use ra_db::RelativePathBuf;
|
||||||
use ra_syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
|
use ra_syntax::{ast, AstPtr, SyntaxNodePtr};
|
||||||
|
|
||||||
use hir_expand::{HirFileId, InFile};
|
use hir_expand::{HirFileId, InFile};
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ use hir_expand::{HirFileId, InFile};
|
||||||
pub struct UnresolvedModule {
|
pub struct UnresolvedModule {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub decl: AstPtr<ast::Module>,
|
pub decl: AstPtr<ast::Module>,
|
||||||
pub highlight_range: TextRange,
|
|
||||||
pub candidate: RelativePathBuf,
|
pub candidate: RelativePathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +19,6 @@ impl Diagnostic for UnresolvedModule {
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
"unresolved module".to_string()
|
"unresolved module".to_string()
|
||||||
}
|
}
|
||||||
fn highlight_range(&self) -> InFile<TextRange> {
|
|
||||||
InFile::new(self.file, self.highlight_range)
|
|
||||||
}
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile::new(self.file, self.decl.clone().into())
|
InFile::new(self.file, self.decl.clone().into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ pub enum ModuleSource {
|
||||||
mod diagnostics {
|
mod diagnostics {
|
||||||
use hir_expand::diagnostics::DiagnosticSink;
|
use hir_expand::diagnostics::DiagnosticSink;
|
||||||
use ra_db::RelativePathBuf;
|
use ra_db::RelativePathBuf;
|
||||||
use ra_syntax::{ast, AstNode, AstPtr};
|
use ra_syntax::{ast, AstPtr};
|
||||||
|
|
||||||
use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId};
|
use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId};
|
||||||
|
|
||||||
|
@ -326,7 +326,6 @@ mod diagnostics {
|
||||||
sink.push(UnresolvedModule {
|
sink.push(UnresolvedModule {
|
||||||
file: declaration.file_id,
|
file: declaration.file_id,
|
||||||
decl: AstPtr::new(&decl),
|
decl: AstPtr::new(&decl),
|
||||||
highlight_range: decl.syntax().text_range(),
|
|
||||||
candidate: candidate.clone(),
|
candidate: candidate.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,12 @@
|
||||||
|
|
||||||
use std::{any::Any, fmt};
|
use std::{any::Any, fmt};
|
||||||
|
|
||||||
use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange};
|
use ra_syntax::{SyntaxNode, SyntaxNodePtr};
|
||||||
|
|
||||||
use crate::{db::AstDatabase, InFile};
|
use crate::{db::AstDatabase, InFile};
|
||||||
|
|
||||||
pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
|
pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
|
||||||
fn message(&self) -> String;
|
fn message(&self) -> String;
|
||||||
fn highlight_range(&self) -> InFile<TextRange>;
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr>;
|
fn source(&self) -> InFile<SyntaxNodePtr>;
|
||||||
fn as_any(&self) -> &(dyn Any + Send + 'static);
|
fn as_any(&self) -> &(dyn Any + Send + 'static);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
|
use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
|
||||||
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr, TextRange};
|
use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
|
|
||||||
pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm};
|
pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm};
|
||||||
|
@ -13,7 +13,6 @@ pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
|
||||||
pub struct NoSuchField {
|
pub struct NoSuchField {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub field: AstPtr<ast::RecordField>,
|
pub field: AstPtr<ast::RecordField>,
|
||||||
pub highlight_range: TextRange,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic for NoSuchField {
|
impl Diagnostic for NoSuchField {
|
||||||
|
@ -21,10 +20,6 @@ impl Diagnostic for NoSuchField {
|
||||||
"no such field".to_string()
|
"no such field".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn highlight_range(&self) -> InFile<TextRange> {
|
|
||||||
InFile::new(self.file, self.highlight_range)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile::new(self.file, self.field.clone().into())
|
InFile::new(self.file, self.field.clone().into())
|
||||||
}
|
}
|
||||||
|
@ -38,7 +33,6 @@ impl Diagnostic for NoSuchField {
|
||||||
pub struct MissingFields {
|
pub struct MissingFields {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub field_list: AstPtr<ast::RecordFieldList>,
|
pub field_list: AstPtr<ast::RecordFieldList>,
|
||||||
pub highlight_range: TextRange,
|
|
||||||
pub missed_fields: Vec<Name>,
|
pub missed_fields: Vec<Name>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,10 +44,6 @@ impl Diagnostic for MissingFields {
|
||||||
}
|
}
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
fn highlight_range(&self) -> InFile<TextRange> {
|
|
||||||
InFile::new(self.file, self.highlight_range)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile { file_id: self.file, value: self.field_list.clone().into() }
|
InFile { file_id: self.file, value: self.field_list.clone().into() }
|
||||||
}
|
}
|
||||||
|
@ -76,7 +66,6 @@ impl AstDiagnostic for MissingFields {
|
||||||
pub struct MissingPatFields {
|
pub struct MissingPatFields {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub field_list: AstPtr<ast::RecordFieldPatList>,
|
pub field_list: AstPtr<ast::RecordFieldPatList>,
|
||||||
pub highlight_range: TextRange,
|
|
||||||
pub missed_fields: Vec<Name>,
|
pub missed_fields: Vec<Name>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +77,6 @@ impl Diagnostic for MissingPatFields {
|
||||||
}
|
}
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
fn highlight_range(&self) -> InFile<TextRange> {
|
|
||||||
InFile::new(self.file, self.highlight_range)
|
|
||||||
}
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile { file_id: self.file, value: self.field_list.clone().into() }
|
InFile { file_id: self.file, value: self.field_list.clone().into() }
|
||||||
}
|
}
|
||||||
|
@ -104,16 +90,12 @@ pub struct MissingMatchArms {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub match_expr: AstPtr<ast::Expr>,
|
pub match_expr: AstPtr<ast::Expr>,
|
||||||
pub arms: AstPtr<ast::MatchArmList>,
|
pub arms: AstPtr<ast::MatchArmList>,
|
||||||
pub highlight_range: TextRange,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic for MissingMatchArms {
|
impl Diagnostic for MissingMatchArms {
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
String::from("Missing match arm")
|
String::from("Missing match arm")
|
||||||
}
|
}
|
||||||
fn highlight_range(&self) -> InFile<TextRange> {
|
|
||||||
InFile::new(self.file, self.highlight_range)
|
|
||||||
}
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile { file_id: self.file, value: self.match_expr.clone().into() }
|
InFile { file_id: self.file, value: self.match_expr.clone().into() }
|
||||||
}
|
}
|
||||||
|
@ -126,16 +108,12 @@ impl Diagnostic for MissingMatchArms {
|
||||||
pub struct MissingOkInTailExpr {
|
pub struct MissingOkInTailExpr {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub expr: AstPtr<ast::Expr>,
|
pub expr: AstPtr<ast::Expr>,
|
||||||
pub highlight_range: TextRange,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic for MissingOkInTailExpr {
|
impl Diagnostic for MissingOkInTailExpr {
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
"wrap return expression in Ok".to_string()
|
"wrap return expression in Ok".to_string()
|
||||||
}
|
}
|
||||||
fn highlight_range(&self) -> InFile<TextRange> {
|
|
||||||
InFile::new(self.file, self.highlight_range)
|
|
||||||
}
|
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile { file_id: self.file, value: self.expr.clone().into() }
|
InFile { file_id: self.file, value: self.expr.clone().into() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId};
|
use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId};
|
||||||
use hir_expand::diagnostics::DiagnosticSink;
|
use hir_expand::diagnostics::DiagnosticSink;
|
||||||
use ra_syntax::{ast, AstNode, AstPtr};
|
use ra_syntax::{ast, AstPtr};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -100,7 +100,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
self.sink.push(MissingFields {
|
self.sink.push(MissingFields {
|
||||||
file: source_ptr.file_id,
|
file: source_ptr.file_id,
|
||||||
field_list: AstPtr::new(&field_list),
|
field_list: AstPtr::new(&field_list),
|
||||||
highlight_range: field_list.syntax().text_range(),
|
|
||||||
missed_fields,
|
missed_fields,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -131,7 +130,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
self.sink.push(MissingPatFields {
|
self.sink.push(MissingPatFields {
|
||||||
file: source_ptr.file_id,
|
file: source_ptr.file_id,
|
||||||
field_list: AstPtr::new(&field_list),
|
field_list: AstPtr::new(&field_list),
|
||||||
highlight_range: field_list.syntax().text_range(),
|
|
||||||
missed_fields,
|
missed_fields,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -215,7 +213,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
file: source_ptr.file_id,
|
file: source_ptr.file_id,
|
||||||
match_expr: AstPtr::new(&match_expr),
|
match_expr: AstPtr::new(&match_expr),
|
||||||
arms: AstPtr::new(&arms),
|
arms: AstPtr::new(&arms),
|
||||||
highlight_range: match_expr.syntax().text_range(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,13 +244,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
let (_, source_map) = db.body_with_source_map(self.func.into());
|
let (_, source_map) = db.body_with_source_map(self.func.into());
|
||||||
|
|
||||||
if let Ok(source_ptr) = source_map.expr_syntax(id) {
|
if let Ok(source_ptr) = source_map.expr_syntax(id) {
|
||||||
let root = source_ptr.file_syntax(db.upcast());
|
self.sink
|
||||||
let highlight_range = source_ptr.value.to_node(&root).syntax().text_range();
|
.push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value });
|
||||||
self.sink.push(MissingOkInTailExpr {
|
|
||||||
file: source_ptr.file_id,
|
|
||||||
expr: source_ptr.value,
|
|
||||||
highlight_range,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -665,7 +665,6 @@ impl Expectation {
|
||||||
mod diagnostics {
|
mod diagnostics {
|
||||||
use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
|
use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
|
||||||
use hir_expand::diagnostics::DiagnosticSink;
|
use hir_expand::diagnostics::DiagnosticSink;
|
||||||
use ra_syntax::AstNode;
|
|
||||||
|
|
||||||
use crate::{db::HirDatabase, diagnostics::NoSuchField};
|
use crate::{db::HirDatabase, diagnostics::NoSuchField};
|
||||||
|
|
||||||
|
@ -686,13 +685,7 @@ mod diagnostics {
|
||||||
let source = owner.lookup(db.upcast()).source(db.upcast());
|
let source = owner.lookup(db.upcast()).source(db.upcast());
|
||||||
let (_, source_map) = db.body_with_source_map(owner.into());
|
let (_, source_map) = db.body_with_source_map(owner.into());
|
||||||
let field = source_map.field_syntax(*expr, *field);
|
let field = source_map.field_syntax(*expr, *field);
|
||||||
let root = field.file_syntax(db.upcast());
|
sink.push(NoSuchField { file: source.file_id, field: field.value })
|
||||||
let highlight_range = field.value.to_node(&root).syntax().text_range();
|
|
||||||
sink.push(NoSuchField {
|
|
||||||
file: source.file_id,
|
|
||||||
field: field.value,
|
|
||||||
highlight_range,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue