4
4
use smol_str:: { SmolStr , ToSmolStr } ;
5
5
use std:: cell:: RefCell ;
6
6
use std:: collections:: { HashMap , HashSet } ;
7
+ use std:: io:: ErrorKind ;
7
8
use std:: path:: { Path , PathBuf } ;
8
9
use std:: rc:: { Rc , Weak } ;
9
10
@@ -931,10 +932,7 @@ impl TypeLoader {
931
932
}
932
933
self . all_documents . dependencies . remove ( path) ;
933
934
if self . all_documents . currently_loading . contains_key ( path) {
934
- Err ( std:: io:: Error :: new (
935
- std:: io:: ErrorKind :: InvalidInput ,
936
- format ! ( "{path:?} is still loading" ) ,
937
- ) )
935
+ Err ( std:: io:: Error :: new ( ErrorKind :: InvalidInput , format ! ( "{path:?} is still loading" ) ) )
938
936
} else {
939
937
Ok ( ( ) )
940
938
}
@@ -1205,11 +1203,13 @@ impl TypeLoader {
1205
1203
) -> Option < PathBuf > {
1206
1204
let mut borrowed_state = state. borrow_mut ( ) ;
1207
1205
1206
+ let mut resolved = false ;
1208
1207
let ( path_canon, builtin) = match borrowed_state
1209
1208
. tl
1210
1209
. resolve_import_path ( import_token. as_ref ( ) , file_to_import)
1211
1210
{
1212
1211
Some ( x) => {
1212
+ resolved = true ;
1213
1213
if let Some ( file_name) = x. 0 . file_name ( ) . and_then ( |f| f. to_str ( ) ) {
1214
1214
let len = file_to_import. len ( ) ;
1215
1215
if !file_to_import. ends_with ( file_name)
@@ -1325,7 +1325,10 @@ impl TypeLoader {
1325
1325
Some ( & path_canon) ,
1326
1326
state. borrow_mut ( ) . diag ,
1327
1327
) ) ,
1328
- Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
1328
+ Err ( err)
1329
+ if !resolved
1330
+ && matches ! ( err. kind( ) , ErrorKind :: NotFound | ErrorKind :: NotADirectory ) =>
1331
+ {
1329
1332
state. borrow_mut ( ) . diag . push_error (
1330
1333
if file_to_import. starts_with ( '@' ) {
1331
1334
format ! (
@@ -1582,6 +1585,7 @@ impl TypeLoader {
1582
1585
} ;
1583
1586
crate :: fileaccess:: load_file ( path. as_path ( ) )
1584
1587
. map ( |virtual_file| ( virtual_file. canon_path , virtual_file. builtin_contents ) )
1588
+ . or_else ( || Some ( ( path, None ) ) )
1585
1589
} )
1586
1590
}
1587
1591
@@ -2118,12 +2122,27 @@ import { E } from "@unknown/lib.slint";
2118
2122
assert ! ( build_diagnostics. has_errors( ) ) ;
2119
2123
let diags = build_diagnostics. to_string_vec ( ) ;
2120
2124
assert_eq ! ( diags. len( ) , 5 ) ;
2121
- assert ! ( diags[ 0 ] . starts_with( & format!(
2122
- "HELLO:3: Error reading requested import \" {}\" : " ,
2123
- test_source_path. to_string_lossy( )
2124
- ) ) ) ;
2125
- assert_eq ! ( & diags[ 1 ] , "HELLO:4: Cannot find requested import \" @libdir/unknown.slint\" in the library search path" ) ;
2126
- assert_eq ! ( & diags[ 2 ] , "HELLO:5: Cannot find requested import \" @libfile.slint/unknown.slint\" in the library search path" ) ;
2125
+ assert_starts_with (
2126
+ & diags[ 0 ] ,
2127
+ & format ! (
2128
+ "HELLO:3: Error reading requested import \" {}\" : " ,
2129
+ test_source_path. to_string_lossy( )
2130
+ ) ,
2131
+ ) ;
2132
+ assert_starts_with (
2133
+ & diags[ 1 ] ,
2134
+ & format ! (
2135
+ "HELLO:4: Error reading requested import \" {}\" : " ,
2136
+ test_source_path. join( "unknown.slint" ) . to_string_lossy( ) ,
2137
+ ) ,
2138
+ ) ;
2139
+ assert_starts_with (
2140
+ & diags[ 2 ] ,
2141
+ & format ! (
2142
+ "HELLO:5: Error reading requested import \" {}\" : " ,
2143
+ test_source_path. join( "lib.slint" ) . join( "unknown.slint" ) . to_string_lossy( )
2144
+ ) ,
2145
+ ) ;
2127
2146
assert_eq ! (
2128
2147
& diags[ 3 ] ,
2129
2148
"HELLO:6: Cannot find requested import \" @unknown\" in the library search path"
@@ -2132,6 +2151,11 @@ import { E } from "@unknown/lib.slint";
2132
2151
& diags[ 4 ] ,
2133
2152
"HELLO:7: Cannot find requested import \" @unknown/lib.slint\" in the library search path"
2134
2153
) ;
2154
+
2155
+ #[ track_caller]
2156
+ fn assert_starts_with ( actual : & str , start : & str ) {
2157
+ assert ! ( actual. starts_with( start) , "{actual:?} does not start with {start:?}" ) ;
2158
+ }
2135
2159
}
2136
2160
2137
2161
#[ test]
0 commit comments