pub struct Suggestion {
pub span: SourceSpan,
pub replacement: String,
}Expand description
A machine-actionable fix for a Diagnostic.
A Suggestion says “replace the bytes at this SourceSpan with this
text” — it is structured data a tool can apply automatically, as opposed
to the prose advice carried by DiagnosticAnnotation::Help. Backends
consume it without re-parsing: the CLI can print a fix-it diff and an LSP
can surface it as a code action keyed on the same span.
Two edge cases fall out of the replace-the-span model and are intentional:
- an empty
replacementdeletes the bytes covered byspan; - a zero-length
span(start == end) insertsreplacementat that offset without removing anything.
§Examples
use std::path::PathBuf;
use mos_core::{SourceSpan, Suggestion};
let span = SourceSpan::new(PathBuf::from("main.mos"), 4, 10);
let fix = Suggestion::new(span, "@intro");
assert_eq!(fix.replacement, "@intro");Fields§
§span: SourceSpanThe source range the fix replaces. A zero-length span
(start == end) marks a pure insertion point.
replacement: StringThe text to substitute for the bytes covered by span. An empty
string deletes that range.
Implementations§
Source§impl Suggestion
impl Suggestion
Sourcepub fn new(span: SourceSpan, replacement: impl Into<String>) -> Self
pub fn new(span: SourceSpan, replacement: impl Into<String>) -> Self
Construct a suggestion replacing span with replacement.
§Examples
use std::path::PathBuf;
use mos_core::{SourceSpan, Suggestion};
let span = SourceSpan::new(PathBuf::from("main.mos"), 0, 3);
let fix = Suggestion::new(span, "set".to_owned());
assert_eq!(fix.span.start, 0);Trait Implementations§
Source§impl Clone for Suggestion
impl Clone for Suggestion
Source§fn clone(&self) -> Suggestion
fn clone(&self) -> Suggestion
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Suggestion
impl Debug for Suggestion
Source§impl PartialEq for Suggestion
impl PartialEq for Suggestion
Source§fn eq(&self, other: &Suggestion) -> bool
fn eq(&self, other: &Suggestion) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for Suggestion
impl StructuralPartialEq for Suggestion
Auto Trait Implementations§
impl Freeze for Suggestion
impl RefUnwindSafe for Suggestion
impl Send for Suggestion
impl Sync for Suggestion
impl Unpin for Suggestion
impl UnsafeUnpin for Suggestion
impl UnwindSafe for Suggestion
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
Mutably borrows from an owned value. Read more