nimbus_fml/editing/
mod.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2* License, v. 2.0. If a copy of the MPL was not distributed with this
3* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5mod cursor_position;
6mod error_converter;
7mod error_kind;
8mod error_path;
9mod values_finder;
10
11pub(crate) use cursor_position::{CursorPosition, CursorSpan};
12pub(crate) use error_converter::ErrorConverter;
13pub(crate) use error_kind::ErrorKind;
14pub(crate) use error_path::ErrorPath;
15
16pub(crate) struct FeatureValidationError {
17    pub(crate) path: ErrorPath,
18    pub(crate) kind: ErrorKind,
19}
20
21#[derive(Debug, PartialEq, Default)]
22pub struct FmlEditorError {
23    /// The message to display to the user.
24    pub message: String,
25    /// The token to highlight, and to replace
26    pub highlight: Option<String>,
27    /// The position in the source code of the first
28    /// character of the highlight
29    pub error_span: CursorSpan,
30    /// The list of possible corrective actions the user
31    /// can take to fix this error.
32    pub corrections: Vec<CorrectionCandidate>,
33    pub line: u32,
34    pub col: u32,
35}
36
37#[derive(Debug, Default, PartialEq)]
38pub struct CorrectionCandidate {
39    /// The string that should be inserted into the source
40    pub insert: String,
41    /// The short display name to represent the fix.
42    pub display_name: Option<String>,
43
44    /// The span where the `insert` string should overwrite. If None,
45    /// then use the `error_span`.
46    pub insertion_span: Option<CursorSpan>,
47
48    /// The final position of the cursor after the insertion has taken place.
49    /// If None, then should be left to the editor to decide.
50    pub cursor_at: Option<CursorPosition>,
51}
52
53/// Constructors
54#[cfg(feature = "client-lib")]
55impl CorrectionCandidate {
56    /// Replace the error token with a quoted string.
57    /// The display is the unquoted string.
58    pub(crate) fn string_replacement(s: &str) -> Self {
59        CorrectionCandidate {
60            insert: format!("\"{}\"", s),
61            display_name: Some(s.to_owned()),
62            ..Default::default()
63        }
64    }
65
66    /// Replace the error token with the literal,
67    /// represented by the `s: &str`.
68    pub(crate) fn literal_replacement(s: &str) -> Self {
69        CorrectionCandidate {
70            insert: s.to_owned(),
71            ..Default::default()
72        }
73    }
74}