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>,
}
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<()>;
fn current_component(&self) -> Option<PreviewComponent>;
}
#[allow(unused)]
#[derive(Default, Clone, Debug)]
pub struct PreviewComponent {
pub path: PathBuf,
pub component: Option<String>,
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,
}, }