77
88use std:: collections:: HashMap ;
99use std:: collections:: HashSet ;
10- use std:: ffi:: OsString ;
1110use std:: iter:: once;
1211use std:: path:: Path ;
1312use std:: path:: PathBuf ;
1413use std:: sync:: Arc ;
15- use std:: sync:: LazyLock ;
1614use std:: sync:: atomic:: AtomicBool ;
1715use std:: sync:: atomic:: AtomicI32 ;
1816use std:: sync:: atomic:: Ordering ;
@@ -147,7 +145,6 @@ use lsp_types::request::WorkspaceConfiguration;
147145use lsp_types:: request:: WorkspaceSymbolRequest ;
148146use pyrefly_build:: handle:: Handle ;
149147use pyrefly_config:: config:: ConfigSource ;
150- use pyrefly_python:: COMPILED_FILE_SUFFIXES ;
151148use pyrefly_python:: PYTHON_EXTENSIONS ;
152149use pyrefly_python:: module:: TextRangeWithModule ;
153150use pyrefly_python:: module_name:: ModuleName ;
@@ -171,6 +168,8 @@ use starlark_map::small_set::SmallSet;
171168use crate :: commands:: lsp:: IndexingMode ;
172169use crate :: config:: config:: ConfigFile ;
173170use crate :: error:: error:: Error ;
171+ use crate :: lsp:: build_system:: queue_source_db_rebuild_and_recheck;
172+ use crate :: lsp:: build_system:: should_requery_build_system;
174173use crate :: lsp:: features:: hover:: get_hover;
175174use crate :: lsp:: lsp:: apply_change_events;
176175use crate :: lsp:: lsp:: as_notification;
@@ -1078,7 +1077,7 @@ impl Server {
10781077 ide_transaction_manager. save ( transaction) ;
10791078 }
10801079 }
1081- Self :: queue_source_db_rebuild_and_recheck (
1080+ queue_source_db_rebuild_and_recheck (
10821081 & self . state ,
10831082 self . invalidated_configs . dupe ( ) ,
10841083 self . sourcedb_queue . dupe ( ) ,
@@ -1087,47 +1086,6 @@ impl Server {
10871086 ) ;
10881087 }
10891088
1090- /// Attempts to requery any open sourced_dbs for open files, and if there are changes,
1091- /// invalidate find and perform a recheck.
1092- fn queue_source_db_rebuild_and_recheck (
1093- state : & State ,
1094- invalidated_configs : Arc < Mutex < SmallSet < ArcId < ConfigFile > > > > ,
1095- sourcedb_queue : HeavyTaskQueue ,
1096- lsp_queue : LspQueue ,
1097- handles : & [ Handle ] ,
1098- ) {
1099- let mut configs_to_paths: SmallMap < ArcId < ConfigFile > , SmallSet < ModulePath > > =
1100- SmallMap :: new ( ) ;
1101- let config_finder = state. config_finder ( ) ;
1102- for handle in handles {
1103- let config = config_finder. python_file ( handle. module ( ) , handle. path ( ) ) ;
1104- configs_to_paths
1105- . entry ( config)
1106- . or_default ( )
1107- . insert ( handle. path ( ) . dupe ( ) ) ;
1108- }
1109- sourcedb_queue. queue_task ( Box :: new ( move || {
1110- let new_invalidated_configs: SmallSet < ArcId < ConfigFile > > = configs_to_paths
1111- . into_iter ( )
1112- . filter ( |( c, files) | match c. requery_source_db ( files) {
1113- Ok ( reloaded) => reloaded,
1114- Err ( error) => {
1115- eprintln ! ( "Error reloading source database for config: {error}" ) ;
1116- false
1117- }
1118- } )
1119- . map ( |( c, _) | c)
1120- . collect ( ) ;
1121- if !new_invalidated_configs. is_empty ( ) {
1122- let mut lock = invalidated_configs. lock ( ) ;
1123- for c in new_invalidated_configs {
1124- lock. insert ( c) ;
1125- }
1126- let _ = lsp_queue. send ( LspEvent :: InvalidateConfigFind ) ;
1127- }
1128- } ) ) ;
1129- }
1130-
11311089 fn invalidate_find_for_configs ( & self , invalidated_configs : SmallSet < ArcId < ConfigFile > > ) {
11321090 self . invalidate ( |t| t. invalidate_find_for_configs ( invalidated_configs) ) ;
11331091 }
@@ -1379,25 +1337,7 @@ impl Server {
13791337
13801338 let events = CategorizedEvents :: new_lsp ( params. changes ) ;
13811339
1382- static CONFIG_NAMES : LazyLock < SmallSet < OsString > > = LazyLock :: new ( || {
1383- ConfigFile :: CONFIG_FILE_NAMES
1384- . iter ( )
1385- . chain ( ConfigFile :: ADDITIONAL_ROOT_FILE_NAMES . iter ( ) )
1386- . map ( OsString :: from)
1387- . collect ( )
1388- } ) ;
1389- static PYTHON_SUFFIXES : LazyLock < SmallSet < OsString > > = LazyLock :: new ( || {
1390- PYTHON_EXTENSIONS
1391- . iter ( )
1392- . chain ( COMPILED_FILE_SUFFIXES . iter ( ) )
1393- . map ( OsString :: from)
1394- . collect ( )
1395- } ) ;
1396-
1397- let should_requery_build_system = events. iter ( ) . any ( |f| {
1398- !( f. file_name ( ) . is_some_and ( |n| CONFIG_NAMES . contains ( n) )
1399- || f. extension ( ) . is_some_and ( |e| PYTHON_SUFFIXES . contains ( e) ) )
1400- } ) ;
1340+ let should_requery_build_system = should_requery_build_system ( & events) ;
14011341
14021342 self . invalidate ( move |t| t. invalidate_events ( & events) ) ;
14031343 // rewatch files in case we loaded or dropped any configs
@@ -1413,7 +1353,7 @@ impl Server {
14131353 . keys ( )
14141354 . map ( |x| make_open_handle ( & self . state , x) )
14151355 . collect :: < Vec < _ > > ( ) ;
1416- Self :: queue_source_db_rebuild_and_recheck (
1356+ queue_source_db_rebuild_and_recheck (
14171357 & self . state ,
14181358 self . invalidated_configs . dupe ( ) ,
14191359 self . sourcedb_queue . dupe ( ) ,
@@ -1443,7 +1383,7 @@ impl Server {
14431383 let handles =
14441384 Self :: validate_in_memory_for_transaction ( & state, & open_files, transaction. as_mut ( ) ) ;
14451385 state. commit_transaction ( transaction) ;
1446- Self :: queue_source_db_rebuild_and_recheck (
1386+ queue_source_db_rebuild_and_recheck (
14471387 & state,
14481388 invalidated_configs,
14491389 sourcedb_queue,
0 commit comments