use crate::error::SourceLocation;
#[derive(Debug, Clone)]
pub struct Suggestion {
pub message: String,
pub edit: Option<TextEdit>,
pub confidence: SuggestionConfidence,
}
impl Suggestion {
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
edit: None,
confidence: SuggestionConfidence::Maybe,
}
}
pub fn certain(message: impl Into<String>) -> Self {
Self {
message: message.into(),
edit: None,
confidence: SuggestionConfidence::Certain,
}
}
pub fn likely(message: impl Into<String>) -> Self {
Self {
message: message.into(),
edit: None,
confidence: SuggestionConfidence::Likely,
}
}
pub fn with_edit(mut self, edit: TextEdit) -> Self {
self.edit = Some(edit);
self
}
}
#[derive(Debug, Clone)]
pub struct TextEdit {
pub start: (usize, usize),
pub end: (usize, usize),
pub new_text: String,
}
impl TextEdit {
pub fn insert(line: usize, col: usize, text: impl Into<String>) -> Self {
Self {
start: (line, col),
end: (line, col),
new_text: text.into(),
}
}
pub fn replace(start: (usize, usize), end: (usize, usize), text: impl Into<String>) -> Self {
Self {
start,
end,
new_text: text.into(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SuggestionConfidence {
Certain, Likely, Maybe, }
#[derive(Debug, Clone)]
pub struct RelatedInfo {
pub location: SourceLocation,
pub message: String,
}
impl RelatedInfo {
pub fn new(message: impl Into<String>, location: SourceLocation) -> Self {
Self {
location,
message: message.into(),
}
}
}