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
impl ModuleDiagnostics
Sourcepub fn len(&self, severity_mask: u8) -> usize
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this collection does not contain any diagnostic issues.
Sourcepub fn depth(&self) -> DiagnosticsDepth
pub fn depth(&self) -> DiagnosticsDepth
Returns the diagnostic analysis depth at which this collection was constructed.
See DiagnosticsDepth for details.
Sourcepub fn revision(&self) -> Revision
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.
Sourcepub fn iter(&self) -> DiagnosticsIter<'_> ⓘ
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).
Sourcepub fn highlight<'a>(
&self,
text: &'a ModuleText<'_>,
severity_mask: u8,
) -> ScriptSnippet<'a>
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
impl Clone for ModuleDiagnostics
Source§fn clone(&self) -> ModuleDiagnostics
fn clone(&self) -> ModuleDiagnostics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more