pub struct ModuleText<'a> { /* private fields */ }
Expand description
A view into the ScriptModule source code text and lexis.
Created by the ModuleRead::text function.
To fetch the raw text of the source code or a substring, use the ModuleText::substring function.
To print a snippet of the source code text with syntax highlighting and annotation messages to the terminal, use the ModuleText::snippet function. The Display implementation of this object also prints a highlighted snippet with default settings.
Implementations§
Source§impl<'a> ModuleText<'a>
impl<'a> ModuleText<'a>
Sourcepub fn snippet(&self) -> ScriptSnippet<'_>
pub fn snippet(&self) -> ScriptSnippet<'_>
Returns an annotated snippet that prints the module’s source code text with syntax highlighting and annotations for specific code fragments with string messages.
let module = ScriptModule::new(
Package::meta(),
r#"
let foo = 10;
let bar = foo + 20;
"#,
);
module.rename("my_module.adastra");
let handle = TriggerHandle::new();
let module_read = module.read(&handle, 1).unwrap();
let module_text = module_read.text();
let mut snippet = module_text.snippet();
snippet.annotate(
Position::new(2, 9)..Position::new(2, 12),
AnnotationPriority::Primary,
"Annotation text.",
);
println!("{snippet}");
Outputs:
╭──╢ ‹doctest›.‹my_module.adastra› ╟────────────────────────────────────────╮
1 │ │
2 │ let foo = 10; │
│ ╰╴ Annotation text. │
3 │ let bar = foo + 20; │
4 │ │
╰───────────────────────────────────────────────────────────────────────────╯
Sourcepub fn is_well_formed(&self) -> bool
pub fn is_well_formed(&self) -> bool
Returns true if the script module does not have syntax errors.
Sourcepub fn format(&self, config: ScriptFormatConfig) -> Option<String>
pub fn format(&self, config: ScriptFormatConfig) -> Option<String>
If the script module does not have syntax errors (i.e., the module is well-formed), returns the reformatted source code text according to the formatting rules.
See format_script_text for details.
Trait Implementations§
Source§impl<'a> Debug for ModuleText<'a>
impl<'a> Debug for ModuleText<'a>
Source§impl<'a> Display for ModuleText<'a>
impl<'a> Display for ModuleText<'a>
Source§impl<'a> Identifiable for ModuleText<'a>
impl<'a> Identifiable for ModuleText<'a>
Source§impl<'a> Lexis for ModuleText<'a>
impl<'a> Lexis for ModuleText<'a>
Source§type Lexis = Document<ScriptNode>
type Lexis = Document<ScriptNode>
Source§fn lexis(&self) -> &Self::Lexis
fn lexis(&self) -> &Self::Lexis
Source§impl<'a> ModuleTextResolver for ModuleText<'a>
impl<'a> ModuleTextResolver for ModuleText<'a>
Source§fn resolve(&self, id: Id) -> Option<&ModuleText<'_>>
fn resolve(&self, id: Id) -> Option<&ModuleText<'_>>
id
, returns
ModuleText of this module. Otherwise, returns None.Auto Trait Implementations§
impl<'a> Freeze for ModuleText<'a>
impl<'a> !RefUnwindSafe for ModuleText<'a>
impl<'a> !Send for ModuleText<'a>
impl<'a> Sync for ModuleText<'a>
impl<'a> Unpin for ModuleText<'a>
impl<'a> !UnwindSafe for ModuleText<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<F> SourceCode for Fwhere
F: Lexis,
impl<F> SourceCode for Fwhere
F: Lexis,
Source§type Token = <<F as Lexis>::Lexis as SourceCode>::Token
type Token = <<F as Lexis>::Lexis as SourceCode>::Token
Source§type Cursor<'code> = <<F as Lexis>::Lexis as SourceCode>::Cursor<'code>
where
F: 'code
type Cursor<'code> = <<F as Lexis>::Lexis as SourceCode>::Cursor<'code> where F: 'code
Source§type CharIterator<'code> = <<F as Lexis>::Lexis as SourceCode>::CharIterator<'code>
where
F: 'code
type CharIterator<'code> = <<F as Lexis>::Lexis as SourceCode>::CharIterator<'code> where F: 'code
Source§fn chars(&self, span: impl ToSpan) -> <F as SourceCode>::CharIterator<'_>
fn chars(&self, span: impl ToSpan) -> <F as SourceCode>::CharIterator<'_>
span
. Read moreSource§fn has_chunk(&self, entry: &Entry) -> bool
fn has_chunk(&self, entry: &Entry) -> bool
Source§fn get_token(&self, entry: &Entry) -> Option<<F as SourceCode>::Token>
fn get_token(&self, entry: &Entry) -> Option<<F as SourceCode>::Token>
Source§fn get_site(&self, entry: &Entry) -> Option<usize>
fn get_site(&self, entry: &Entry) -> Option<usize>
Source§fn get_string(&self, entry: &Entry) -> Option<&str>
fn get_string(&self, entry: &Entry) -> Option<&str>
Source§fn cursor(&self, span: impl ToSpan) -> <F as SourceCode>::Cursor<'_>
fn cursor(&self, span: impl ToSpan) -> <F as SourceCode>::Cursor<'_>
span
. Read moreSource§fn length(&self) -> usize
fn length(&self) -> usize
Source§fn lines(&self) -> &LineIndex
fn lines(&self) -> &LineIndex
Source§fn substring(&self, span: impl ToSpan) -> Cow<'_, str>where
Self: Sized,
fn substring(&self, span: impl ToSpan) -> Cow<'_, str>where
Self: Sized,
span
. Read moreSource§fn end_site_ref(&self) -> SiteRef
fn end_site_ref(&self) -> SiteRef
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more