@@ -4,7 +4,6 @@ use std::io::Write;
4
4
use std:: time:: Duration ;
5
5
6
6
use anyhow:: { anyhow, Context } ;
7
- use salsa:: Setter ;
8
7
9
8
use red_knot_python_semantic:: {
10
9
resolve_module, ModuleName , Program , ProgramSettings , PythonVersion , SearchPathSettings ,
@@ -26,6 +25,7 @@ struct TestCase {
26
25
/// We need to hold on to it in the test case or the temp files get deleted.
27
26
_temp_dir : tempfile:: TempDir ,
28
27
root_dir : SystemPathBuf ,
28
+ search_path_settings : SearchPathSettings ,
29
29
}
30
30
31
31
impl TestCase {
@@ -108,18 +108,20 @@ impl TestCase {
108
108
fn update_search_path_settings (
109
109
& mut self ,
110
110
f : impl FnOnce ( & SearchPathSettings ) -> SearchPathSettings ,
111
- ) {
111
+ ) -> anyhow :: Result < ( ) > {
112
112
let program = Program :: get ( self . db ( ) ) ;
113
- let search_path_settings = program. search_paths ( self . db ( ) ) ;
114
113
115
- let new_settings = f ( search_path_settings) ;
114
+ let new_settings = f ( & self . search_path_settings ) ;
116
115
117
- program. set_search_paths ( & mut self . db ) . to ( new_settings) ;
116
+ program. update_search_paths ( & mut self . db , new_settings. clone ( ) ) ?;
117
+ self . search_path_settings = new_settings;
118
118
119
119
if let Some ( watcher) = & mut self . watcher {
120
120
watcher. update ( & self . db ) ;
121
121
assert ! ( !watcher. has_errored_paths( ) ) ;
122
122
}
123
+
124
+ Ok ( ( ) )
123
125
}
124
126
125
127
fn collect_package_files ( & self , path : & SystemPath ) -> Vec < File > {
@@ -221,24 +223,24 @@ where
221
223
let system = OsSystem :: new ( & workspace_path) ;
222
224
223
225
let workspace = WorkspaceMetadata :: from_path ( & workspace_path, & system) ?;
224
- let search_paths = create_search_paths ( & root_path, workspace. root ( ) ) ;
226
+ let search_path_settings = create_search_paths ( & root_path, workspace. root ( ) ) ;
225
227
226
- for path in search_paths
228
+ for path in search_path_settings
227
229
. extra_paths
228
230
. iter ( )
229
- . chain ( search_paths . site_packages . iter ( ) )
230
- . chain ( search_paths . custom_typeshed . iter ( ) )
231
+ . chain ( search_path_settings . site_packages . iter ( ) )
232
+ . chain ( search_path_settings . custom_typeshed . iter ( ) )
231
233
{
232
234
std:: fs:: create_dir_all ( path. as_std_path ( ) )
233
235
. with_context ( || format ! ( "Failed to create search path '{path}'" ) ) ?;
234
236
}
235
237
236
238
let settings = ProgramSettings {
237
239
target_version : PythonVersion :: default ( ) ,
238
- search_paths,
240
+ search_paths : search_path_settings . clone ( ) ,
239
241
} ;
240
242
241
- let db = RootDatabase :: new ( workspace, settings, system) ;
243
+ let db = RootDatabase :: new ( workspace, settings, system) ? ;
242
244
243
245
let ( sender, receiver) = crossbeam:: channel:: unbounded ( ) ;
244
246
let watcher = directory_watcher ( move |events| sender. send ( events) . unwrap ( ) )
@@ -253,6 +255,7 @@ where
253
255
watcher : Some ( watcher) ,
254
256
_temp_dir : temp_dir,
255
257
root_dir : root_path,
258
+ search_path_settings,
256
259
} ;
257
260
258
261
// Sometimes the file watcher reports changes for events that happened before the watcher was started.
@@ -737,7 +740,8 @@ fn add_search_path() -> anyhow::Result<()> {
737
740
case. update_search_path_settings ( |settings| SearchPathSettings {
738
741
site_packages : vec ! [ site_packages. clone( ) ] ,
739
742
..settings. clone ( )
740
- } ) ;
743
+ } )
744
+ . expect ( "Search path settings to be valid" ) ;
741
745
742
746
std:: fs:: write ( site_packages. join ( "a.py" ) . as_std_path ( ) , "class A: ..." ) ?;
743
747
@@ -767,7 +771,8 @@ fn remove_search_path() -> anyhow::Result<()> {
767
771
case. update_search_path_settings ( |settings| SearchPathSettings {
768
772
site_packages : vec ! [ ] ,
769
773
..settings. clone ( )
770
- } ) ;
774
+ } )
775
+ . expect ( "Search path settings to be valid" ) ;
771
776
772
777
std:: fs:: write ( site_packages. join ( "a.py" ) . as_std_path ( ) , "class A: ..." ) ?;
773
778
0 commit comments