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/. */
45mod cursor_position;
6mod error_converter;
7mod error_kind;
8mod error_path;
9mod values_finder;
1011pub(crate) use cursor_position::{CursorPosition, CursorSpan};
12pub(crate) use error_converter::ErrorConverter;
13pub(crate) use error_kind::ErrorKind;
14pub(crate) use error_path::ErrorPath;
1516pub(crate) struct FeatureValidationError {
17pub(crate) path: ErrorPath,
18pub(crate) kind: ErrorKind,
19}
2021#[derive(Debug, PartialEq, Default)]
22pub struct FmlEditorError {
23/// The message to display to the user.
24pub message: String,
25/// The token to highlight, and to replace
26pub highlight: Option<String>,
27/// The position in the source code of the first
28 /// character of the highlight
29pub error_span: CursorSpan,
30/// The list of possible corrective actions the user
31 /// can take to fix this error.
32pub corrections: Vec<CorrectionCandidate>,
33pub line: u32,
34pub col: u32,
35}
3637#[derive(Debug, Default, PartialEq)]
38pub struct CorrectionCandidate {
39/// The string that should be inserted into the source
40pub insert: String,
41/// The short display name to represent the fix.
42pub display_name: Option<String>,
4344/// The span where the `insert` string should overwrite. If None,
45 /// then use the `error_span`.
46pub insertion_span: Option<CursorSpan>,
4748/// The final position of the cursor after the insertion has taken place.
49 /// If None, then should be left to the editor to decide.
50pub cursor_at: Option<CursorPosition>,
51}
5253/// Constructors
54#[cfg(feature = "client-lib")]
55impl CorrectionCandidate {
56/// Replace the error token with a quoted string.
57 /// The display is the unquoted string.
58pub(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 }
6566/// Replace the error token with the literal,
67 /// represented by the `s: &str`.
68pub(crate) fn literal_replacement(s: &str) -> Self {
69 CorrectionCandidate {
70 insert: s.to_owned(),
71 ..Default::default()
72 }
73 }
74}