sqruff_lib_core/parser/segments/
fix.rs

1use std::ops::Range;
2
3use smol_str::SmolStr;
4
5/// A stored reference to a fix in the non-templated file.
6#[derive(Hash, Debug, Clone, PartialEq, Eq)]
7pub struct SourceFix {
8    pub(crate) edit: SmolStr,
9    pub(crate) source_slice: Range<usize>,
10    // TODO: It might be possible to refactor this to not require
11    // a templated_slice (because in theory it's unnecessary).
12    // However much of the fix handling code assumes we need
13    // a position in the templated file to interpret it.
14    // More work required to achieve that if desired.
15    pub(crate) templated_slice: Range<usize>,
16}
17
18impl SourceFix {
19    pub fn new(edit: SmolStr, source_slice: Range<usize>, templated_slice: Range<usize>) -> Self {
20        SourceFix {
21            edit,
22            source_slice,
23            templated_slice,
24        }
25    }
26}
27
28/// An edit patch for a source file.
29#[derive(Clone, Debug)]
30#[allow(dead_code)]
31pub struct FixPatch {
32    templated_slice: Range<usize>,
33    pub fixed_raw: SmolStr,
34    // The patch category, functions mostly for debugging and explanation
35    // than for function. It allows traceability of *why* this patch was
36    // generated. It has no significance for processing. Brought over from sqlfluff
37    // patch_category: FixPatchCategory,
38    pub source_slice: Range<usize>,
39    templated_str: String,
40    source_str: String,
41}
42
43impl FixPatch {
44    pub fn new(
45        templated_slice: Range<usize>,
46        fixed_raw: SmolStr,
47        source_slice: Range<usize>,
48        templated_str: String,
49        source_str: String,
50    ) -> Self {
51        FixPatch {
52            templated_slice,
53            fixed_raw,
54            source_slice,
55            templated_str,
56            source_str,
57        }
58    }
59
60    /// Generate a tuple of this fix for deduping.
61    pub fn dedupe_tuple(&self) -> Range<usize> {
62        self.source_slice.clone()
63    }
64}