Skip to content

Commit

Permalink
fix: broken preview feature flag (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin authored Jul 8, 2024
1 parent d95041d commit 4b1f8cd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/tinymist/src/actor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
pub mod editor;
pub mod export;
pub mod format;
#[cfg(feature = "preview")]
pub mod preview;
pub mod typ_client;
pub mod typ_server;
pub mod user_action;

use std::sync::Arc;

use parking_lot::lock_api::RwLock;
use tinymist_query::analysis::Analysis;
use tinymist_query::ExportKind;
use tinymist_render::PeriscopeRenderer;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl LanguageState {
let periscope_args = self.compile_config().periscope_args.clone();
let handle = Arc::new(CompileHandler {
#[cfg(feature = "preview")]
inner: std::sync::Arc::new(RwLock::new(None)),
inner: std::sync::Arc::new(parking_lot::RwLock::new(None)),
diag_group: editor_group.clone(),
intr_tx: intr_tx.clone(),
doc_tx,
Expand Down
6 changes: 4 additions & 2 deletions crates/tinymist/src/actor/typ_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::{

use anyhow::{anyhow, bail};
use log::{error, info, trace};
use parking_lot::{Mutex, RwLock};
use parking_lot::Mutex;
use tinymist_query::{
analysis::{Analysis, AnalysisContext, AnalysisResources},
DiagnosticsMap, ExportKind, ServerInfoResponse, VersionedDocument,
Expand Down Expand Up @@ -75,7 +75,7 @@ pub struct CompileHandler {
pub(crate) periscope: PeriscopeRenderer,

#[cfg(feature = "preview")]
pub(crate) inner: Arc<RwLock<Option<Arc<typst_preview::CompileWatcher>>>>,
pub(crate) inner: Arc<parking_lot::RwLock<Option<Arc<typst_preview::CompileWatcher>>>>,

pub(crate) intr_tx: mpsc::UnboundedSender<Interrupt<LspCompilerFeat>>,
pub(crate) doc_tx: watch::Sender<Option<Arc<TypstDocument>>>,
Expand Down Expand Up @@ -267,6 +267,8 @@ impl CompileHandler {
))
.unwrap();

#[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);
Expand Down
11 changes: 8 additions & 3 deletions crates/tinymist/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct LanguageState {
/// Source synchronized with client
pub memory_changes: HashMap<Arc<Path>, MemoryFileMeta>,
/// The preview state.
#[cfg(feature = "preview")]
pub preview: tool::preview::PreviewState,
/// The diagnostics sender to send diagnostics to `crate::actor::cluster`.
pub editor_tx: mpsc::UnboundedSender<EditorRequest>,
Expand Down Expand Up @@ -122,6 +123,7 @@ impl LanguageState {
editor_tx,
primary: None,
memory_changes: HashMap::new(),
#[cfg(feature = "preview")]
preview: tool::preview::PreviewState::new(client.cast(|s| &mut s.preview)),
ever_focusing_by_activities: false,
ever_manual_focusing: false,
Expand Down Expand Up @@ -193,6 +195,12 @@ impl LanguageState {
use lsp_types::notification::*;
use lsp_types::request::*;

#[cfg(feature = "preview")]
let provider = provider
.with_command("tinymist.doStartPreview", State::start_preview)
.with_command("tinymist.doKillPreview", State::kill_preview)
.with_command("tinymist.scrollPreview", State::scroll_preview);

// todo: .on_sync_mut::<notifs::Cancel>(handlers::handle_cancel)?
let mut provider = provider
.with_request::<Shutdown>(State::shutdown)
Expand Down Expand Up @@ -235,9 +243,6 @@ impl LanguageState {
.with_command("tinymist.doClearCache", State::clear_cache)
.with_command("tinymist.pinMain", State::pin_document)
.with_command("tinymist.focusMain", State::focus_document)
.with_command("tinymist.doStartPreview", State::start_preview)
.with_command("tinymist.doKillPreview", State::kill_preview)
.with_command("tinymist.scrollPreview", State::scroll_preview)
.with_command("tinymist.doInitTemplate", State::init_template)
.with_command("tinymist.doGetTemplateEntry", State::do_get_template_entry)
.with_command_("tinymist.interactCodeContext", State::interact_code_context)
Expand Down
8 changes: 8 additions & 0 deletions crates/tinymist/src/tool/preview_stub.rs
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[serde(tag = "kind", content = "data")]
pub enum CompileStatus {
Compiling,
CompileSuccess,
CompileError,
}
13 changes: 8 additions & 5 deletions crates/typst-preview/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ pub struct PreviewArgs {
pub invert_colors: String,

/// Used by lsp for identifying the task.
#[clap(
long = "task-id",
default_value = "default_preview",
value_name = "TASK_ID",
hide(true)
#[cfg_attr(
feature = "clap",
clap(
long = "task-id",
default_value = "default_preview",
value_name = "TASK_ID",
hide(true)
)
)]
pub task_id: String,

Expand Down

0 comments on commit 4b1f8cd

Please sign in to comment.