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

feat: introduce lockDatabase project resolution #1142

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
81 changes: 57 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ env_logger = "0.11.3"
log = "0.4"

# Typst
reflexo = { version = "=0.5.1", default-features = false, features = [
reflexo = { version = "=0.5.4", default-features = false, features = [
"flat-vector",
] }
reflexo-world = { version = "=0.5.1", features = ["system"] }
reflexo-typst = { version = "=0.5.1", features = [
reflexo-world = { version = "=0.5.4", features = ["system"] }
reflexo-typst = { version = "=0.5.4", features = [
"system",
], default-features = false }
reflexo-vec2svg = { version = "=0.5.1" }
reflexo-typst-shim = { version = "=0.5.1", features = ["nightly"] }
reflexo-vec2svg = { version = "=0.5.4" }
reflexo-typst-shim = { version = "=0.5.4", features = ["nightly"] }


typst = "0.12.0"
Expand Down
13 changes: 13 additions & 0 deletions crates/sync-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ impl<S: 'static> TypedLspClient<S> {
self.client
.send_request_::<R>(params, move |s, resp| handler(caster(s), resp))
}

/// Sends a event to the client itself.
pub fn send_event<T: std::any::Any + Send + 'static>(&self, event: T) {
let Some(sender) = self.sender.upgrade() else {
log::warn!("failed to send request: connection closed");
return;
};

let Err(res) = sender.event.send(Box::new(event)) else {
return;
};
log::warn!("failed to send event: {res:?}");
}
}

impl<S> Clone for TypedLspClient<S> {
Expand Down
3 changes: 2 additions & 1 deletion crates/tinymist-query/src/docs/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::sync::{Arc, LazyLock};

use ecow::{eco_format, EcoString};
use parking_lot::Mutex;
use tinymist_world::base::{EntryState, ShadowApi, TaskInputs};
use tinymist_world::base::{EntryState, ShadowApi};
use tinymist_world::TaskInputs;
use typlite::scopes::Scopes;
use typlite::value::Value;
use typlite::TypliteFeat;
Expand Down
4 changes: 2 additions & 2 deletions crates/tinymist-query/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use parking_lot::Mutex;
use reflexo_typst::typst::prelude::*;
use reflexo_typst::{package::PackageSpec, TypstFileId};
use serde::{Deserialize, Serialize};
use tinymist_world::package::HttpsRegistry;
use tinymist_world::package::http::HttpRegistry;
use typst::diag::{EcoString, StrResult};
use typst::syntax::package::PackageManifest;
use typst::syntax::VirtualPath;
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn check_package(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult<()

/// Get the packages in namespaces and their descriptions.
pub fn list_package_by_namespace(
registry: &HttpsRegistry,
registry: &HttpRegistry,
ns: EcoString,
) -> EcoVec<(PathBuf, PackageSpec)> {
// search packages locally. We only search in the data
Expand Down
21 changes: 10 additions & 11 deletions crates/tinymist-query/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use std::{
use once_cell::sync::Lazy;
use reflexo_typst::package::PackageSpec;
use reflexo_typst::world::EntryState;
use reflexo_typst::{CompileDriverImpl, EntryManager, EntryReader, ShadowApi, TaskInputs};
use reflexo_typst::{Compiler, EntryManager, EntryReader, ShadowApi};
use serde_json::{ser::PrettyFormatter, Serializer, Value};
use tinymist_world::CompileFontArgs;
use tinymist_world::TaskInputs;
use typst::foundations::Bytes;
use typst::syntax::ast::{self, AstNode};
use typst::syntax::{FileId as TypstFileId, LinkedNode, Source, SyntaxKind, VirtualPath};
Expand All @@ -31,8 +32,6 @@ use crate::{
};
use crate::{to_lsp_position, CompletionFeat, LspWorldExt};

type CompileDriver<C> = CompileDriverImpl<C, tinymist_world::LspCompilerFeat>;

pub fn snapshot_testing(name: &str, f: &impl Fn(&mut LocalContext, PathBuf)) {
let name = if name.is_empty() { "playground" } else { name };

Expand Down Expand Up @@ -147,7 +146,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
} else {
PathBuf::from("/")
};
let mut world = LspUniverseBuilder::build(
let mut verse = LspUniverseBuilder::build(
EntryState::new_rooted(root.as_path().into(), None),
Default::default(),
Arc::new(
Expand Down Expand Up @@ -181,19 +180,19 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
let path = path.unwrap_or_else(|| format!("/s{idx}.typ"));

let pw = root.join(Path::new(&path));
world
verse
.map_shadow(&pw, Bytes::from(source.as_bytes()))
.unwrap();
last_pw = Some(pw);
}

world.mutate_entry(EntryState::new_detached()).unwrap();
let mut driver = CompileDriver::new(std::marker::PhantomData, world);
let _ = driver.compile(&mut Default::default());
verse.mutate_entry(EntryState::new_detached()).unwrap();
let world = verse.snapshot();
std::marker::PhantomData.ensure_main(&world).unwrap();
let _ = std::marker::PhantomData.compile(&world, &mut Default::default());

let pw = last_pw.unwrap();
driver
.universe_mut()
verse
.mutate_entry(EntryState::new_rooted(
root.as_path().into(),
Some(TypstFileId::new(
Expand All @@ -202,7 +201,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
)),
))
.unwrap();
f(driver.universe_mut(), pw)
f(&mut verse, pw)
}

pub fn find_test_range(s: &Source) -> Range<usize> {
Expand Down
5 changes: 5 additions & 0 deletions crates/tinymist-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ serde.workspace = true
serde_json.workspace = true
anyhow.workspace = true
log.workspace = true
tokio.workspace = true
rayon.workspace = true

reflexo-typst.workspace = true
reflexo-typst-shim = { workspace = true, features = ["nightly"] }
typst.workspace = true
codespan-reporting = "0.11"

tinymist-assets = { workspace = true }
tinymist-project.workspace = true
tinymist-fs.workspace = true
typst-assets = { workspace = true, features = ["fonts"] }

dirs.workspace = true
Expand Down
Loading
Loading