Skip to main content

SourceErrorManager

Struct SourceErrorManager 

Source
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

Source

pub fn new() -> SourceErrorManager

Source

pub fn add_buffer(&mut self, name: &str, contents: &str) -> SourceId

Register a real source buffer and return its id.

Source

pub fn add_buffer_bytes(&mut self, name: &str, contents: &[u8]) -> SourceId

Register a real source buffer from raw (possibly already NUL-terminated) bytes.

Source

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.

Source

pub fn is_virtual(&self, id: SourceId) -> bool

Source

pub fn buffer_file_name(&self, id: SourceId) -> &str

Source

pub fn source_buffer(&self, id: SourceId) -> Rc<SourceBuffer>

Obtain a buffer by id (cloning the Rc, e.g. to hand to a lexer).

Source

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.

Source

pub fn lookup_name(&self, name: &str) -> Option<SourceId>

Source

pub fn set_source_url(&mut self, id: SourceId, url: &str)

Source

pub fn source_url(&self, id: SourceId) -> Option<&str>

Source

pub fn set_source_mapping_url(&mut self, id: SourceId, url: &str)

Source

pub fn source_mapping_url(&self, id: SourceId) -> Option<&str>

Source§

impl SourceErrorManager

Source

pub fn set_translator(&mut self, translator: Option<Rc<dyn CoordTranslator>>)

Install (or clear) the coordinate translator applied during resolution.

Source

pub fn find_buffer_id(&self, loc: SMLoc) -> SourceId

The buffer containing loc. Trivial: the location carries its buffer. Port of findBufferIdForLoc.

Source

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.

Source

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.

Source

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.

Source

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].

Source

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.

Source

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).

Source

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).

Source

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).

Source

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).

Source

pub fn output_options(&self) -> OutputOptions

Return the current advisory output options. Port of getOutputOptions (C++ header:331).

Source

pub fn set_output_options(&mut self, o: OutputOptions)

Replace the current advisory output options. Port of setOutputOptions (C++ header:335).

Source

pub fn translator(&self) -> Option<Rc<dyn CoordTranslator>>

Clone the installed translator, if any. Port of getTranslator (C++ header:355).

Source

pub fn get_message_count(&self, dk: DiagKind) -> u32

Number of messages of kind dk emitted so far. Port of getMessageCount (C++ header:586).

Source

pub fn note_count(&self) -> u32

Convenience: number of notes emitted. Port of getNoteCount (C++ header:597).

Source§

impl SourceErrorManager

Source

pub fn set_handler(&mut self, h: Box<dyn DiagHandler>)

Install the diagnostic sink. Replaces any previously installed handler.

Source

pub fn handler_as<T>(&self) -> Option<&T>
where T: 'static,

Downcast the installed handler to a concrete type (for tests/inspection).

Source

pub fn set_error_limit(&mut self, limit: u32)

Set the maximum number of errors before suppressing further messages.

Source

pub fn get_error_limit(&self) -> u32

Return the current error limit. Port of getErrorLimit (C++ header:285).

Source

pub fn is_error_limit_reached(&self) -> bool

Return true if the error limit has been reached.

Source

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.

Source

pub fn error_count(&self) -> u32

Convenience: number of errors emitted.

Source

pub fn warning_count(&self) -> u32

Convenience: number of warnings emitted (before any is-error promotion).

Source

pub fn set_warning_status(&mut self, w: Warning, enabled: bool)

Enable or disable a warning category. Port of setWarningStatus / disableAllWarnings.

Source

pub fn set_warning_is_error(&mut self, w: Warning, v: bool)

Promote (or demote) a warning category to errors. Port of setWarningIsError.

Source

pub fn set_warnings_are_errors(&mut self, v: bool)

Promote all warning categories to errors (equivalent to -Werror).

Source

pub fn disable_all_warnings(&mut self)

Disable all warning categories.

Source

pub fn is_warning_enabled(&self, w: Warning) -> bool

Return true if the warning category is currently enabled.

Source

pub fn is_warning_an_error(&self, w: Warning) -> bool

Return true if the warning category is promoted to error.

Source

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.

Source

pub fn suppressed_messages(&self) -> Option<Subsystem>

Return the currently suppressed subsystem, if any.

Source

pub fn error(&mut self, loc: SMLoc, msg: impl Into<String>)

Emit an error at loc (subsystem: Unspecified).

Source

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).

Source

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.

Source

pub fn note(&mut self, loc: SMLoc, msg: impl Into<String>)

Emit a note at loc (subsystem: Unspecified).

Source

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).

Source

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.

Source

pub fn warning(&mut self, w: Warning, loc: SMLoc, msg: impl Into<String>)

Emit a warning of the given category at loc (subsystem: Unspecified).

Source

pub fn warning_misc(&mut self, loc: SMLoc, msg: impl Into<String>)

Emit a Misc warning at loc (subsystem: Unspecified).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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_gendo_gen_message buffers them rather than re-collecting.

Trait Implementations§

Source§

impl Default for SourceErrorManager

Source§

fn default() -> SourceErrorManager

Returns the “default value” for a type. 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> 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, 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.