Skip to content

Commit

Permalink
dev: delete preview_stub (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Jul 9, 2024
1 parent b13643e commit 1662d58
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 73 deletions.
106 changes: 46 additions & 60 deletions crates/tinymist/src/actor/typ_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use super::{
};
use crate::{
task::{ExportConfig, ExportSignal, ExportTask},
tool::preview::CompileStatus,
world::{LspCompilerFeat, LspWorld},
CompileConfig,
};
Expand Down Expand Up @@ -219,77 +218,42 @@ impl CompileHandler {
}
}

impl CompileHandler {
pub fn preview_status(&self, _status: CompileStatus) {
self.editor_tx
impl CompilationHandle<LspCompilerFeat> for CompileHandler {
fn status(&self, _rep: CompileReport) {
let this = &self;
this.editor_tx
.send(EditorRequest::Status(
self.diag_group.clone(),
this.diag_group.clone(),
TinymistCompileStatusEnum::Compiling,
))
.unwrap();

#[cfg(feature = "preview")]
if let Some(inner) = self.inner.read().as_ref() {
inner.status(_status);
}
}

pub fn preview_notify_compile(
&self,
res: Result<Arc<TypstDocument>, CompileStatus>,
is_on_saved: bool,
) {
if let Ok(doc) = res.clone() {
let _ = self.doc_tx.send(Some(doc.clone()));
}

self.editor_tx
.send(EditorRequest::Status(
self.diag_group.clone(),
if res.is_ok() {
TinymistCompileStatusEnum::CompileSuccess
} else {
TinymistCompileStatusEnum::CompileError
},
))
.unwrap();
if let Some(inner) = this.inner.read().as_ref() {
use typst_preview::CompileStatus;

let status = match _rep {
CompileReport::Suspend => {
self.push_diagnostics(None);
CompileStatus::CompileError
}
CompileReport::Stage(_, _, _) => CompileStatus::Compiling,
CompileReport::CompileSuccess(_, _, _) | CompileReport::CompileWarning(_, _, _) => {
CompileStatus::CompileSuccess
}
CompileReport::CompileError(_, _, _) | CompileReport::ExportError(_, _, _) => {
CompileStatus::CompileError
}
};

#[cfg(not(feature = "preview"))]
let _ = is_on_saved;
#[cfg(feature = "preview")]
if let Some(inner) = self.inner.read().as_ref() {
inner.notify_compile(res, is_on_saved);
inner.status(status);
}
}
}

impl CompilationHandle<LspCompilerFeat> for CompileHandler {
fn status(&self, rep: CompileReport) {
let status = match rep {
CompileReport::Suspend => {
self.push_diagnostics(None);
CompileStatus::CompileError
}
CompileReport::Stage(_, _, _) => CompileStatus::Compiling,
CompileReport::CompileSuccess(_, _, _) | CompileReport::CompileWarning(_, _, _) => {
CompileStatus::CompileSuccess
}
CompileReport::CompileError(_, _, _) | CompileReport::ExportError(_, _, _) => {
CompileStatus::CompileError
}
};

self.preview_status(status);
}

fn notify_compile(&self, snap: &CompiledArtifact<LspCompilerFeat>, _rep: CompileReport) {
let (res, err) = match snap.doc.clone() {
Ok(doc) => (Ok(doc), EcoVec::new()),
Err(err) => (Err(CompileStatus::CompileError), err),
};
self.notify_diagnostics(
&snap.world,
err,
snap.doc.clone().err().unwrap_or_default(),
snap.env.tracer.as_ref().map(|e| e.clone().warnings()),
);

Expand All @@ -303,7 +267,29 @@ impl CompilationHandle<LspCompilerFeat> for CompileHandler {
self.export.signal(snap, ExportSignal::Saved);
}

self.preview_notify_compile(res, snap.flags.triggered_by_fs_events);
if let Ok(doc) = &snap.doc {
let _ = self.doc_tx.send(Some(doc.clone()));
}

self.editor_tx
.send(EditorRequest::Status(
self.diag_group.clone(),
if snap.doc.is_ok() {
TinymistCompileStatusEnum::CompileSuccess
} else {
TinymistCompileStatusEnum::CompileError
},
))
.unwrap();

#[cfg(feature = "preview")]
if let Some(inner) = self.inner.read().as_ref() {
let res = snap
.doc
.clone()
.map_err(|_| typst_preview::CompileStatus::CompileError);
inner.notify_compile(res, snap.flags.triggered_by_fs_events);
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions crates/tinymist/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ pub mod word_count;

#[cfg(feature = "preview")]
pub mod preview;
#[cfg(not(feature = "preview"))]
pub mod preview_stub;
#[cfg(not(feature = "preview"))]
pub use preview_stub as preview;
9 changes: 0 additions & 9 deletions crates/tinymist/src/tool/preview_stub.rs

This file was deleted.

0 comments on commit 1662d58

Please sign in to comment.