@@ -8,23 +8,16 @@ use typst::{
88 syntax:: {
99 ast:: { self , AstNode , ModuleImport } ,
1010 package:: { PackageSpec , PackageVersion , VersionlessPackageSpec } ,
11- FileId , VirtualPath ,
1211 } ,
1312 World ,
1413} ;
14+ use walkdir:: WalkDir ;
1515
16- use crate :: {
17- check:: { label, TryExt } ,
18- world:: SystemWorld ,
19- } ;
20-
21- use super :: { Diagnostics , Result } ;
16+ use crate :: check:: path:: PackagePath ;
17+ use crate :: check:: { label, Diagnostics , Result , TryExt } ;
18+ use crate :: world:: SystemWorld ;
2219
2320pub fn check ( diags : & mut Diagnostics , package_dir : & Path , world : & SystemWorld ) -> Result < ( ) > {
24- check_dir ( diags, package_dir, world)
25- }
26-
27- pub fn check_dir ( diags : & mut Diagnostics , dir : & Path , world : & SystemWorld ) -> Result < ( ) > {
2821 let root_path = world. root ( ) ;
2922 let main_path = root_path
3023 . join ( world. main ( ) . vpath ( ) . as_rootless_path ( ) )
@@ -35,36 +28,24 @@ pub fn check_dir(diags: &mut Diagnostics, dir: &Path, world: &SystemWorld) -> Re
3528 . and_then ( |package_dir| package_dir. parent ( ) )
3629 . and_then ( |namespace_dir| namespace_dir. parent ( ) ) ;
3730
38- for ch in std:: fs:: read_dir ( dir) . error ( "internal/io" , "Can't read directory" ) ? {
39- let Ok ( ch) = ch else {
40- continue ;
41- } ;
31+ for ch in WalkDir :: new ( package_dir) . into_iter ( ) . flatten ( ) {
4232 let Ok ( meta) = ch. metadata ( ) else {
4333 continue ;
4434 } ;
45-
46- let path = dir. join ( ch. file_name ( ) ) ;
47- if meta. is_dir ( ) {
48- check_dir ( diags, & path, world) ?;
35+ if !meta. is_file ( ) {
36+ continue ;
4937 }
50- if path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) == Some ( "typ" ) {
51- let fid = FileId :: new (
52- None ,
53- VirtualPath :: new (
54- path. strip_prefix ( root_path)
55- // Not actually true
56- . error (
57- "internal" ,
58- "Prefix striping failed even though `path` is built from `root_dir`" ,
59- ) ?,
60- ) ,
61- ) ;
62- let source = world. lookup ( fid) . error ( "io" , "Can't read source file" ) ?;
38+
39+ let path = PackagePath :: from_full ( package_dir, ch. path ( ) ) ;
40+ if path. extension ( ) . is_some_and ( |ext| ext == "typ" ) {
41+ let source = world
42+ . lookup ( path. file_id ( ) )
43+ . error ( "io" , "Can't read source file" ) ?;
6344 check_ast (
6445 diags,
6546 world,
6647 source. root ( ) ,
67- & path,
48+ path. full ( ) ,
6849 main_path. as_deref ( ) ,
6950 all_packages,
7051 ) ;
0 commit comments