Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: steal the latest compiled document for lsp functions #68

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/tinymist/src/actor/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pub struct CompileActor<C: Compiler> {
estimated_shadow_files: HashSet<Arc<Path>>,
/// The latest compiled document.
latest_doc: Option<Arc<TypstDocument>>,
/// The latest successly compiled document.
latest_success_doc: Option<Arc<TypstDocument>>,
/// feature set for compile_once mode.
once_feature_set: Arc<FeatureSet>,
/// Shared feature set for watch mode.
Expand Down Expand Up @@ -144,6 +146,7 @@ where

estimated_shadow_files: Default::default(),
latest_doc: None,
latest_success_doc: None,
once_feature_set: Arc::new(feature_set),
watch_feature_set,

Expand All @@ -162,6 +165,15 @@ where
Self::new_with_features(compiler, root, entry, FeatureSet::default())
}

pub fn success_doc(&self) -> Option<VersionedDocument> {
self.latest_success_doc
.clone()
.map(|doc| VersionedDocument {
version: self.logical_tick,
document: doc,
})
}

pub fn doc(&self) -> Option<VersionedDocument> {
self.latest_doc.clone().map(|doc| VersionedDocument {
version: self.logical_tick,
Expand Down Expand Up @@ -325,6 +337,10 @@ where
self.steal_send.send(ExternalInterrupt::Compile).ok();
}
}

// Reset the document state.
self.latest_doc = None;
self.latest_success_doc = None;
}

/// Compile the document.
Expand All @@ -341,6 +357,9 @@ where
.compiler
.compile(&mut CompileEnv::default().configure_shared(self.watch_feature_set.clone()))
.ok();
if self.latest_doc.is_some() {
self.latest_success_doc = self.latest_doc.clone();
}

// Evict compilation cache.
let evict_start = std::time::Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist/src/actor/typst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl CompileActor {
&self,
f: impl FnOnce(&TypstSystemWorld, Option<VersionedDocument>) -> T + Send + Sync + 'static,
) -> anyhow::Result<T> {
let fut = self.steal(move |compiler| f(compiler.compiler.world(), compiler.doc()));
let fut = self.steal(move |compiler| f(compiler.compiler.world(), compiler.success_doc()));

Ok(fut?)
}
Expand Down