From 302bf97bbf1855e3c7def9ab4f9f3d338be5e3b7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Apr 2020 11:38:51 +0200 Subject: Don't expose impl details of SyntaxPtr --- crates/ra_hir_ty/src/diagnostics.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/diagnostics.rs') 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 @@ use std::any::Any; use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; -use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; +use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr, TextRange}; use stdx::format_to; pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm}; @@ -13,6 +13,7 @@ pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; pub struct NoSuchField { pub file: HirFileId, pub field: AstPtr, + pub highlight_range: TextRange, } impl Diagnostic for NoSuchField { @@ -20,6 +21,10 @@ impl Diagnostic for NoSuchField { "no such field".to_string() } + fn highlight_range(&self) -> TextRange { + self.highlight_range + } + fn source(&self) -> InFile { InFile { file_id: self.file, value: self.field.clone().into() } } @@ -33,6 +38,7 @@ impl Diagnostic for NoSuchField { pub struct MissingFields { pub file: HirFileId, pub field_list: AstPtr, + pub highlight_range: TextRange, pub missed_fields: Vec, } @@ -44,6 +50,10 @@ impl Diagnostic for MissingFields { } buf } + fn highlight_range(&self) -> TextRange { + self.highlight_range + } + fn source(&self) -> InFile { InFile { file_id: self.file, value: self.field_list.clone().into() } } @@ -66,6 +76,7 @@ impl AstDiagnostic for MissingFields { pub struct MissingPatFields { pub file: HirFileId, pub field_list: AstPtr, + pub highlight_range: TextRange, pub missed_fields: Vec, } @@ -77,6 +88,9 @@ impl Diagnostic for MissingPatFields { } buf } + fn highlight_range(&self) -> TextRange { + self.highlight_range + } fn source(&self) -> InFile { InFile { file_id: self.file, value: self.field_list.clone().into() } } @@ -90,12 +104,16 @@ pub struct MissingMatchArms { pub file: HirFileId, pub match_expr: AstPtr, pub arms: AstPtr, + pub highlight_range: TextRange, } impl Diagnostic for MissingMatchArms { fn message(&self) -> String { String::from("Missing match arm") } + fn highlight_range(&self) -> TextRange { + self.highlight_range + } fn source(&self) -> InFile { InFile { file_id: self.file, value: self.match_expr.clone().into() } } @@ -108,12 +126,16 @@ impl Diagnostic for MissingMatchArms { pub struct MissingOkInTailExpr { pub file: HirFileId, pub expr: AstPtr, + pub highlight_range: TextRange, } impl Diagnostic for MissingOkInTailExpr { fn message(&self) -> String { "wrap return expression in Ok".to_string() } + fn highlight_range(&self) -> TextRange { + self.highlight_range + } fn source(&self) -> InFile { InFile { file_id: self.file, value: self.expr.clone().into() } } -- cgit v1.2.3