pub struct SourceErrorManager { /* private fields */ }Expand description
The source manager owning the parsed buffers, re-exported because
ResolvedJS::source_manager returns one.
A facade that owns source buffers and reports diagnostics against them.
Rust port of hermes::SourceErrorManager.
Implementations§
Source§impl SourceErrorManager
impl SourceErrorManager
pub fn new() -> SourceErrorManager
Sourcepub fn add_buffer(&mut self, name: &str, contents: &str) -> SourceId
pub fn add_buffer(&mut self, name: &str, contents: &str) -> SourceId
Register a real source buffer and return its id.
Sourcepub fn add_buffer_bytes(&mut self, name: &str, contents: &[u8]) -> SourceId
pub fn add_buffer_bytes(&mut self, name: &str, contents: &[u8]) -> SourceId
Register a real source buffer from raw (possibly already NUL-terminated) bytes.
Sourcepub fn add_virtual_buffer(&mut self, name: &str) -> SourceId
pub fn add_virtual_buffer(&mut self, name: &str) -> SourceId
Register a virtual buffer: a name with no contents, used for synthetic
locations. Port of addNewVirtualSourceBuffer.
pub fn is_virtual(&self, id: SourceId) -> bool
pub fn buffer_file_name(&self, id: SourceId) -> &str
Sourcepub fn source_buffer(&self, id: SourceId) -> Rc<SourceBuffer>
pub fn source_buffer(&self, id: SourceId) -> Rc<SourceBuffer>
Obtain a buffer by id (cloning the Rc, e.g. to hand to a lexer).
Sourcepub fn find_buffer_for_loc(&self, loc: SMLoc) -> Rc<SourceBuffer>
pub fn find_buffer_for_loc(&self, loc: SMLoc) -> Rc<SourceBuffer>
Obtain the buffer containing loc (cloning the Rc). The location
carries its buffer, so this is a direct lookup. Port of findBufferForLoc.
pub fn lookup_name(&self, name: &str) -> Option<SourceId>
pub fn set_source_url(&mut self, id: SourceId, url: &str)
pub fn source_url(&self, id: SourceId) -> Option<&str>
pub fn set_source_mapping_url(&mut self, id: SourceId, url: &str)
pub fn source_mapping_url(&self, id: SourceId) -> Option<&str>
Source§impl SourceErrorManager
impl SourceErrorManager
Sourcepub fn set_translator(&mut self, translator: Option<Rc<dyn CoordTranslator>>)
pub fn set_translator(&mut self, translator: Option<Rc<dyn CoordTranslator>>)
Install (or clear) the coordinate translator applied during resolution.
Sourcepub fn find_buffer_id(&self, loc: SMLoc) -> SourceId
pub fn find_buffer_id(&self, loc: SMLoc) -> SourceId
The buffer containing loc. Trivial: the location carries its buffer.
Port of findBufferIdForLoc.
Sourcepub fn find_coords(&self, loc: SMLoc) -> SourceCoords
pub fn find_coords(&self, loc: SMLoc) -> SourceCoords
Decode loc to 1-based (buffer, line, col), applying the coordinate
translator if one is installed. Port of findBufferLineAndLoc.
Sourcepub fn find_smrange_for_line(&self, buf: SourceId, line: u32) -> Option<SMRange>
pub fn find_smrange_for_line(&self, buf: SourceId, line: u32) -> Option<SMRange>
Return the 1-based line span [start, end) for line in buffer buf
as an SMRange, after LF and CR trimming. Matches the line-span branch of
findForCoordsImpl (cpp:357-398). Returns None if line is out of range.
Sourcepub fn find_smloc_from_coords(&self, coords: SourceCoords) -> Option<SMLoc>
pub fn find_smloc_from_coords(&self, coords: SourceCoords) -> Option<SMLoc>
Resolve a SourceCoords (buffer + 1-based line + 1-based col) to an
SMLoc. Port of findSMLocFromCoords / findForCoordsImpl (cpp:397-439).
Returns None if the line is out of range or the column is past the line.
Sourcepub fn find_buffer_and_line(&self, loc: SMLoc) -> (SourceId, u32, Range<u32>)
pub fn find_buffer_and_line(&self, loc: SMLoc) -> (SourceId, u32, Range<u32>)
Return (buf, 1-based-line, byte-range-of-line) for the line containing
loc. Equivalent to findBufferAndLine (C++ header:428).
§Lifetime note
The C++ returns a LineCoord with a borrow into the buffer’s bytes.
Because with_line_index scopes the borrow to a closure, we cannot
return a LineCoord<'_> without lifetime gymnastics. Instead we return
the byte range as a std::ops::Range<u32> (owned, zero-copy). Callers
can retrieve the actual slice via source_buffer(buf).bytes()[range].
Sourcepub fn find_untranslated_coords(&self, loc: SMLoc) -> SourceCoords
pub fn find_untranslated_coords(&self, loc: SMLoc) -> SourceCoords
Decode loc without applying the translator, including the
adjustSourceLocation correction for ‘\r’/UTF-8 continuation bytes.
Port of findUntranslatedBufferLineAndLoc.
Sourcepub fn combine_into_range(&self, a: SMLoc, b: SMLoc) -> SMRange
pub fn combine_into_range(&self, a: SMLoc, b: SMLoc) -> SMRange
Build the smallest SMRange covering both a and b (both must be in
the same buffer). Delegates to SMRange::combine.
Port of combineIntoRange (C++ header:601-607).
Sourcepub fn convert_end_to_location(range: SMRange) -> SMLoc
pub fn convert_end_to_location(range: SMRange) -> SMLoc
Convert the exclusive end of range to an inclusive location by
subtracting one. If the range is empty (start == end), returns the start
unchanged. Port of convertEndToLocation (cpp:670-676).
Sourcepub fn dump_coords(&self, coords: SourceCoords) -> String
pub fn dump_coords(&self, coords: SourceCoords) -> String
Format coords as "name:line:col", where name prefers the buffer’s
source URL over its file name (matching C++ dumpCoords, which uses
getSourceUrl). Port of dumpCoords(OS, SourceCoords) (cpp:109-117).
Sourcepub fn dump_coords_loc(&self, loc: SMLoc) -> String
pub fn dump_coords_loc(&self, loc: SMLoc) -> String
Resolve loc to coordinates and format as "filename:line:col".
Port of dumpCoords(OS, SMLoc) (cpp:119-123).
Sourcepub fn output_options(&self) -> OutputOptions
pub fn output_options(&self) -> OutputOptions
Return the current advisory output options.
Port of getOutputOptions (C++ header:331).
Sourcepub fn set_output_options(&mut self, o: OutputOptions)
pub fn set_output_options(&mut self, o: OutputOptions)
Replace the current advisory output options.
Port of setOutputOptions (C++ header:335).
Sourcepub fn translator(&self) -> Option<Rc<dyn CoordTranslator>>
pub fn translator(&self) -> Option<Rc<dyn CoordTranslator>>
Clone the installed translator, if any.
Port of getTranslator (C++ header:355).
Sourcepub fn get_message_count(&self, dk: DiagKind) -> u32
pub fn get_message_count(&self, dk: DiagKind) -> u32
Number of messages of kind dk emitted so far.
Port of getMessageCount (C++ header:586).
Sourcepub fn note_count(&self) -> u32
pub fn note_count(&self) -> u32
Convenience: number of notes emitted.
Port of getNoteCount (C++ header:597).
Source§impl SourceErrorManager
impl SourceErrorManager
Sourcepub fn set_handler(&mut self, h: Box<dyn DiagHandler>)
pub fn set_handler(&mut self, h: Box<dyn DiagHandler>)
Install the diagnostic sink. Replaces any previously installed handler.
Sourcepub fn handler_as<T>(&self) -> Option<&T>where
T: 'static,
pub fn handler_as<T>(&self) -> Option<&T>where
T: 'static,
Downcast the installed handler to a concrete type (for tests/inspection).
Sourcepub fn set_error_limit(&mut self, limit: u32)
pub fn set_error_limit(&mut self, limit: u32)
Set the maximum number of errors before suppressing further messages.
Sourcepub fn get_error_limit(&self) -> u32
pub fn get_error_limit(&self) -> u32
Return the current error limit. Port of getErrorLimit (C++ header:285).
Sourcepub fn is_error_limit_reached(&self) -> bool
pub fn is_error_limit_reached(&self) -> bool
Return true if the error limit has been reached.
Sourcepub fn clear_error_limit_reached(&mut self)
pub fn clear_error_limit_reached(&mut self)
Clear the error-limit-reached flag AND reset the error counter, so a
fresh batch of errors can be emitted (e.g. to resume after recovery).
Port of clearErrorLimitReached (C++ header:295-298), which resets both.
Sourcepub fn error_count(&self) -> u32
pub fn error_count(&self) -> u32
Convenience: number of errors emitted.
Sourcepub fn warning_count(&self) -> u32
pub fn warning_count(&self) -> u32
Convenience: number of warnings emitted (before any is-error promotion).
Sourcepub fn set_warning_status(&mut self, w: Warning, enabled: bool)
pub fn set_warning_status(&mut self, w: Warning, enabled: bool)
Enable or disable a warning category.
Port of setWarningStatus / disableAllWarnings.
Sourcepub fn set_warning_is_error(&mut self, w: Warning, v: bool)
pub fn set_warning_is_error(&mut self, w: Warning, v: bool)
Promote (or demote) a warning category to errors.
Port of setWarningIsError.
Sourcepub fn set_warnings_are_errors(&mut self, v: bool)
pub fn set_warnings_are_errors(&mut self, v: bool)
Promote all warning categories to errors (equivalent to -Werror).
Sourcepub fn disable_all_warnings(&mut self)
pub fn disable_all_warnings(&mut self)
Disable all warning categories.
Sourcepub fn is_warning_enabled(&self, w: Warning) -> bool
pub fn is_warning_enabled(&self, w: Warning) -> bool
Return true if the warning category is currently enabled.
Sourcepub fn is_warning_an_error(&self, w: Warning) -> bool
pub fn is_warning_an_error(&self, w: Warning) -> bool
Return true if the warning category is promoted to error.
Sourcepub fn set_suppressed_messages(&mut self, s: Option<Subsystem>)
pub fn set_suppressed_messages(&mut self, s: Option<Subsystem>)
Set (or clear) the subsystem whose messages are suppressed.
Pass Some(Subsystem::Unspecified) to suppress all messages.
Pass None to lift suppression.
See the suppressed_messages field comment for the Rust vs C++ design
rationale.
Sourcepub fn suppressed_messages(&self) -> Option<Subsystem>
pub fn suppressed_messages(&self) -> Option<Subsystem>
Return the currently suppressed subsystem, if any.
Sourcepub fn error(&mut self, loc: SMLoc, msg: impl Into<String>)
pub fn error(&mut self, loc: SMLoc, msg: impl Into<String>)
Emit an error at loc (subsystem: Unspecified).
Sourcepub fn error_range(&mut self, range: SMRange, msg: impl Into<String>)
pub fn error_range(&mut self, range: SMRange, msg: impl Into<String>)
Emit an error at the start of range, underscoring the full range
(subsystem: Unspecified).
Sourcepub fn error_at(
&mut self,
loc: SMLoc,
range: Option<SMRange>,
msg: impl Into<String>,
subsystem: Subsystem,
)
pub fn error_at( &mut self, loc: SMLoc, range: Option<SMRange>, msg: impl Into<String>, subsystem: Subsystem, )
Emit an error at loc with an optional range and explicit subsystem.
The lexer calls this form to allow per-subsystem suppression.
Sourcepub fn note(&mut self, loc: SMLoc, msg: impl Into<String>)
pub fn note(&mut self, loc: SMLoc, msg: impl Into<String>)
Emit a note at loc (subsystem: Unspecified).
Sourcepub fn note_range(
&mut self,
range: SMRange,
msg: impl Into<String>,
subsystem: Subsystem,
)
pub fn note_range( &mut self, range: SMRange, msg: impl Into<String>, subsystem: Subsystem, )
Emit a note over range (the caret sits at range.start).
Sourcepub fn note_at(
&mut self,
loc: SMLoc,
range: Option<SMRange>,
msg: impl Into<String>,
subsystem: Subsystem,
)
pub fn note_at( &mut self, loc: SMLoc, range: Option<SMRange>, msg: impl Into<String>, subsystem: Subsystem, )
Emit a note at loc, optionally underlining range, in subsystem.
Sourcepub fn warning(&mut self, w: Warning, loc: SMLoc, msg: impl Into<String>)
pub fn warning(&mut self, w: Warning, loc: SMLoc, msg: impl Into<String>)
Emit a warning of the given category at loc (subsystem: Unspecified).
Sourcepub fn warning_misc(&mut self, loc: SMLoc, msg: impl Into<String>)
pub fn warning_misc(&mut self, loc: SMLoc, msg: impl Into<String>)
Emit a Misc warning at loc (subsystem: Unspecified).
Sourcepub fn warning_range(
&mut self,
w: Warning,
range: SMRange,
msg: impl Into<String>,
subsystem: Subsystem,
)
pub fn warning_range( &mut self, w: Warning, range: SMRange, msg: impl Into<String>, subsystem: Subsystem, )
Emit a warning of the given category at the start of range,
underscoring the full range, with an explicit subsystem.
Sourcepub fn message(
&mut self,
dk: DiagKind,
w: Warning,
subsystem: Subsystem,
loc: Option<SMLoc>,
range: Option<SMRange>,
msg: impl Into<String>,
)
pub fn message( &mut self, dk: DiagKind, w: Warning, subsystem: Subsystem, loc: Option<SMLoc>, range: Option<SMRange>, msg: impl Into<String>, )
General-purpose overload: caller supplies all parameters.
Port of the message(DiagKind, Warning, Subsystem, ...) C++ overloads.
Sourcepub fn enable_buffering(&mut self)
pub fn enable_buffering(&mut self)
Increment the buffering reference count. While the count is > 0,
messages are queued rather than dispatched to the handler.
Port of enableBuffering in SourceErrorManager.cpp.
Sourcepub fn disable_buffering(&mut self)
pub fn disable_buffering(&mut self)
Decrement the buffering reference count. When it reaches zero, flush
all buffered messages — stable-sorted by source position — to the
handler. Port of disableBuffering in SourceErrorManager.cpp.
§Flush ordering
Messages with a source location are emitted in (buffer-index, offset) order. The “too many errors emitted” sentinel (Error with no location) is forced last. No deduplication — matches C++ behavior. Each top-level message is immediately followed by its attached notes in insertion order.
Sourcepub fn begin_collecting(&mut self) -> Option<Vec<MessageData>>
pub fn begin_collecting(&mut self) -> Option<Vec<MessageData>>
Begin collecting messages. Returns the previous collector (if nested) to
be passed back to end_collecting. While active, filtered messages are
captured (not counted or dispatched). Also enables buffering so the
replayed messages are source-sorted on flush.
Port of CollectMessagesRAII constructor.
Sourcepub fn end_collecting(
&mut self,
previous: Option<Vec<MessageData>>,
discard: bool,
)
pub fn end_collecting( &mut self, previous: Option<Vec<MessageData>>, discard: bool, )
End collection. If discard is false, replay the collected messages
through the normal count+buffer path (counting them and flushing
source-sorted); otherwise drop them. Restores the previous collector.
Port of the CollectMessagesRAII destructor.
Order matches C++: replay (counts + buffers) → disable_buffering
(flushes) → restore previous collector. During replay message_collector
is None (taken), so count_and_gen → do_gen_message buffers them
rather than re-collecting.