forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.rs
92 lines (81 loc) · 2.64 KB
/
common.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
//! Data structures common between LSP and previewer
use std::{
collections::HashMap,
path::{Path, PathBuf},
};
pub type Error = Box<dyn std::error::Error>;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Default, Clone, PartialEq, Debug, serde::Deserialize, serde::Serialize)]
pub struct PreviewConfig {
pub hide_ui: Option<bool>,
pub style: String,
pub include_paths: Vec<PathBuf>,
pub library_paths: HashMap<String, PathBuf>,
}
/// API used by the LSP to talk to the Preview. The other direction uses the
/// ServerNotifier
pub trait PreviewApi {
fn set_use_external_previewer(&self, use_external: bool);
fn set_contents(&self, path: &Path, contents: &str);
fn load_preview(&self, component: PreviewComponent);
fn config_changed(&self, config: PreviewConfig);
fn highlight(&self, path: Option<PathBuf>, offset: u32) -> Result<()>;
/// What is the current component to preview?
fn current_component(&self) -> Option<PreviewComponent>;
}
/// The Component to preview
#[allow(unused)]
#[derive(Default, Clone, Debug)]
pub struct PreviewComponent {
/// The file name to preview
pub path: PathBuf,
/// The name of the component within that file.
/// If None, then the last component is going to be shown.
pub component: Option<String>,
/// The style name for the preview
pub style: String,
}
#[allow(unused)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub enum LspToPreviewMessage {
SetContents { path: String, contents: String },
SetConfiguration { config: PreviewConfig },
ShowPreview { path: String, component: Option<String>, style: String },
HighlightFromEditor { path: Option<String>, offset: u32 },
}
#[allow(unused)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Diagnostic {
pub message: String,
pub file: Option<String>,
pub line: usize,
pub column: usize,
pub level: String,
}
#[allow(unused)]
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub enum PreviewToLspMessage {
Status {
message: String,
health: crate::lsp_ext::Health,
},
Diagnostics {
uri: lsp_types::Url,
diagnostics: Vec<lsp_types::Diagnostic>,
},
ShowDocument {
file: String,
start_line: u32,
start_column: u32,
end_line: u32,
end_column: u32,
},
PreviewTypeChanged {
is_external: bool,
},
RequestState {
unused: bool,
}, // send all documents!
}