shape_ast/error/parse_error/
suggestions.rs1use crate::error::SourceLocation;
4
5#[derive(Debug, Clone)]
7pub struct Suggestion {
8 pub message: String,
10 pub edit: Option<TextEdit>,
12 pub confidence: SuggestionConfidence,
14}
15
16impl Suggestion {
17 pub fn new(message: impl Into<String>) -> Self {
18 Self {
19 message: message.into(),
20 edit: None,
21 confidence: SuggestionConfidence::Maybe,
22 }
23 }
24
25 pub fn certain(message: impl Into<String>) -> Self {
26 Self {
27 message: message.into(),
28 edit: None,
29 confidence: SuggestionConfidence::Certain,
30 }
31 }
32
33 pub fn likely(message: impl Into<String>) -> Self {
34 Self {
35 message: message.into(),
36 edit: None,
37 confidence: SuggestionConfidence::Likely,
38 }
39 }
40
41 pub fn with_edit(mut self, edit: TextEdit) -> Self {
42 self.edit = Some(edit);
43 self
44 }
45}
46
47#[derive(Debug, Clone)]
49pub struct TextEdit {
50 pub start: (usize, usize),
52 pub end: (usize, usize),
54 pub new_text: String,
56}
57
58impl TextEdit {
59 pub fn insert(line: usize, col: usize, text: impl Into<String>) -> Self {
60 Self {
61 start: (line, col),
62 end: (line, col),
63 new_text: text.into(),
64 }
65 }
66
67 pub fn replace(start: (usize, usize), end: (usize, usize), text: impl Into<String>) -> Self {
68 Self {
69 start,
70 end,
71 new_text: text.into(),
72 }
73 }
74}
75
76#[derive(Debug, Clone, Copy, PartialEq)]
77pub enum SuggestionConfidence {
78 Certain, Likely, Maybe, }
82
83#[derive(Debug, Clone)]
85pub struct RelatedInfo {
86 pub location: SourceLocation,
88 pub message: String,
90}
91
92impl RelatedInfo {
93 pub fn new(message: impl Into<String>, location: SourceLocation) -> Self {
94 Self {
95 location,
96 message: message.into(),
97 }
98 }
99}