Struct ModuleDiagnostics

Source
pub struct ModuleDiagnostics { /* private fields */ }
Expand description

A collection of diagnostic issues (errors and warnings) in the script module’s source code.

Created by the diagnostics function.

Implementations§

Source§

impl ModuleDiagnostics

Source

pub fn len(&self, severity_mask: u8) -> usize

Returns the number of issues in this collection that match the specified issue mask (severity_mask).

For example, len(IssueSeverity::Error as u8) returns the number of errors, while len(!0) returns the total number of issues, including both errors and warnings.

Source

pub fn is_empty(&self) -> bool

Returns true if this collection does not contain any diagnostic issues.

Source

pub fn depth(&self) -> DiagnosticsDepth

Returns the diagnostic analysis depth at which this collection was constructed.

See DiagnosticsDepth for details.

Source

pub fn revision(&self) -> Revision

Returns the revision number at which this collection was constructed.

For a specific script module instance and DiagnosticsDepth, this number always increases and never decreases.

If two collections (of the same script module and the same diagnostic depth) have the same revision number, their content can be considered identical.

However, if one collection has a higher revision number than the previous one, it indicates that the diagnostics at this level of depth have been updated.

Source

pub fn iter(&self) -> DiagnosticsIter<'_>

Returns an iterator that yields references to each diagnostic issue (error or warning) in this diagnostics collection.

The issues are returned in an unspecified order. If you want to print each issue manually, you may consider sorting them (e.g., by issue type or by their position in the source code).

Source

pub fn highlight<'a>( &self, text: &'a ModuleText<'_>, severity_mask: u8, ) -> ScriptSnippet<'a>

Returns a script snippet that highlights source code fragments associated with the underlying issues and annotates them with diagnostic messages.

This function provides an easy way to print all diagnostic issues at once to the terminal.

To construct the returned snippet object, you need access to the module’s text, which can be obtained using the text function.

The severity_mask allows you to filter issues by their severity: IssueSeverity::Error as u8 shows only error issues, while !0 shows both error and warning issues.

§Example
let module = ScriptModule::new(Package::meta(), "let foo = ; let = 10;");
module.rename("my_module.adastra");

let handle = TriggerHandle::new();
let module_read = module.read(&handle, 1).unwrap();

let diagnostics = module_read.diagnostics(1).unwrap();
let text = module_read.text();

println!("{}", diagnostics.highlight(&text, !0));

Outputs:

   ╭──╢ diagnostics [‹doctest›.‹my_module.adastra›] ╟──────────────────────────╮
 1 │ let foo = ; let = 10;                                                     │
   │          │     ╰╴ missing var name in 'let <var> = <expr>;'               │
   │          ╰╴ missing expression in 'let <var> = <expr>;'                   │
   ├───────────────────────────────────────────────────────────────────────────┤
   │ Errors: 2                                                                 │
   │ Warnings: 0                                                               │
   ╰───────────────────────────────────────────────────────────────────────────╯

Trait Implementations§

Source§

impl Clone for ModuleDiagnostics

Source§

fn clone(&self) -> ModuleDiagnostics

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Identifiable for ModuleDiagnostics

Source§

fn id(&self) -> Id

Returns the globally unique identifier of the compilation unit to which this object belongs.
Source§

impl<'a> IntoIterator for &'a ModuleDiagnostics

Source§

type Item = ModuleIssue<'a>

The type of the elements being iterated over.
Source§

type IntoIter = DiagnosticsIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.