feat: encode and use workspace information into PackageSpec (#1187)

* feat: remove an unused API

* feat: encode workspace information into `PackageSpec`

* feat: remove unused real_path

* feat: remove unused mtime

* feat: add ResolveAccessModel

* feat: implement id overlay semantics

* feat: remove mtime checking in overlay model

* feat: remove mtime checking in notify model

* feat: format ids

* fix: cases

* feat: resolve root by world

* dev: add untitled root

* fix: warnings

* fix: a wrong usage

* fix: snapshots

* fix: tests
This commit is contained in:
Myriad-Dreamin 2025-01-19 11:51:00 +08:00 committed by GitHub
parent a25d208124
commit 56714675b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 835 additions and 774 deletions

View file

@ -11,6 +11,7 @@ use rustc_hash::FxHashMap;
use tinymist_project::LspWorld;
use tinymist_std::debug_loc::DataSource;
use tinymist_std::hash::{hash128, FxDashMap};
use tinymist_world::vfs::{PathResolution, WorkspaceResolver};
use tinymist_world::{EntryReader, WorldDeps, DETACHED_ENTRY};
use typst::diag::{eco_format, At, FileError, FileResult, SourceResult, StrResult};
use typst::engine::{Route, Sink, Traced};
@ -315,9 +316,9 @@ impl LocalContext {
self.caches
.completion_files
.get_or_init(|| {
if let Some(root) = self.world.workspace_root() {
if let Some(root) = self.world.entry_state().workspace_root() {
scan_workspace_files(&root, PathPreference::Special.ext_matcher(), |path| {
TypstFileId::new(None, VirtualPath::new(path))
WorkspaceResolver::workspace_file(Some(&root), VirtualPath::new(path))
})
} else {
vec![]
@ -357,7 +358,7 @@ impl LocalContext {
}
/// Get all depended files in the workspace, inclusively.
pub fn depended_source_files(&self) -> Vec<TypstFileId> {
pub fn depended_source_files(&self) -> EcoVec<TypstFileId> {
let mut ids = self.depended_files();
let preference = PathPreference::Source {
allow_package: false,
@ -368,22 +369,10 @@ impl LocalContext {
/// Get all depended file ids of a compilation, inclusively.
/// Note: must be called after compilation.
pub fn depended_files(&self) -> Vec<TypstFileId> {
let mut ids = vec![];
for dep in self.depended_paths() {
if let Ok(ref_fid) = self.file_id_by_path(&dep) {
ids.push(ref_fid);
}
}
ids
}
/// Get depended paths of a compilation.
/// Note: must be called after compilation.
pub(crate) fn depended_paths(&self) -> EcoVec<tinymist_std::ImmutPath> {
pub fn depended_files(&self) -> EcoVec<TypstFileId> {
let mut deps = EcoVec::new();
self.world.iter_dependencies(&mut |path| {
deps.push(path);
self.world.iter_dependencies(&mut |file_id| {
deps.push(file_id);
});
deps
@ -585,7 +574,7 @@ impl SharedContext {
}
/// Resolve the real path for a file id.
pub fn path_for_id(&self, id: TypstFileId) -> Result<PathBuf, FileError> {
pub fn path_for_id(&self, id: TypstFileId) -> Result<PathResolution, FileError> {
self.world.path_for_id(id)
}