6659: Explain how we get precise spans for diagnostics. r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-11-28 15:16:33 +00:00 committed by GitHub
commit e437e38d7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@
//! //!
//! `DiagnosticSink` struct is used as an emitter for diagnostic. When creating //! `DiagnosticSink` struct is used as an emitter for diagnostic. When creating
//! a `DiagnosticSink`, you supply a callback which can react to a `dyn //! a `DiagnosticSink`, you supply a callback which can react to a `dyn
//! Diagnostic` or to any concrete diagnostic (downcasting is sued internally). //! Diagnostic` or to any concrete diagnostic (downcasting is used internally).
//! //!
//! Because diagnostics store file offsets, it's a bad idea to store them //! Because diagnostics store file offsets, it's a bad idea to store them
//! directly in salsa. For this reason, every hir subsytem defines it's own //! directly in salsa. For this reason, every hir subsytem defines it's own
@ -32,7 +32,12 @@ impl DiagnosticCode {
pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
fn code(&self) -> DiagnosticCode; fn code(&self) -> DiagnosticCode;
fn message(&self) -> String; fn message(&self) -> String;
/// Used in highlighting and related purposes /// Source element that triggered the diagnostics.
///
/// Note that this should reflect "semantics", rather than specific span we
/// want to highlight. When rendering the diagnostics into an error message,
/// the IDE will fetch the `SyntaxNode` and will narrow the span
/// appropriately.
fn display_source(&self) -> InFile<SyntaxNodePtr>; fn display_source(&self) -> InFile<SyntaxNodePtr>;
fn as_any(&self) -> &(dyn Any + Send + 'static); fn as_any(&self) -> &(dyn Any + Send + 'static);
fn is_experimental(&self) -> bool { fn is_experimental(&self) -> bool {