@@ -7,6 +7,7 @@ use once_cell::sync::OnceCell;
77use serde_json:: { json, Value } ;
88use std:: path:: Path ;
99use std:: sync:: Mutex ;
10+ use std:: time:: SystemTime ;
1011use std:: { collections:: HashMap , path:: PathBuf } ;
1112use xclog:: { XCCompilationDatabase , XCCompileArgs , XCCompileCommand } ;
1213mod extensions;
@@ -29,6 +30,8 @@ pub struct State {
2930 compile_db : XCCompilationDatabase ,
3031 file_args : HashMap < PathBuf , XCCompileArgs > ,
3132 root_path : PathBuf ,
33+ compile_filepath : PathBuf ,
34+ last_modified : SystemTime ,
3235}
3336
3437fn state ( ) -> & ' static Mutex < State > {
@@ -43,7 +46,10 @@ fn initialize(params: &InitializeBuild) -> Result<InitializeBuild> {
4346 let compile_filepath = get_compile_filepath ( root_uri) . unwrap ( ) ;
4447 let cache_path = get_build_cache_dir ( & root_path) ?;
4548 let index_store_path = get_index_store_path ( & cache_path, & config_filepath) ;
46- let compile_db = XCCompilationDatabase :: try_from_filepath ( compile_filepath) ?;
49+ let compile_db = XCCompilationDatabase :: try_from_filepath ( & compile_filepath) ?;
50+
51+ let attr = std:: fs:: metadata ( & compile_filepath) ?;
52+ let last_modified = attr. modified ( ) ?;
4753
4854 let response = InitializeBuild :: new (
4955 SERVER_NAME ,
@@ -62,7 +68,9 @@ fn initialize(params: &InitializeBuild) -> Result<InitializeBuild> {
6268 . set ( Mutex :: new ( State {
6369 root_path,
6470 file_args : Default :: default ( ) ,
71+ compile_filepath,
6572 compile_db,
73+ last_modified,
6674 } ) )
6775 . unwrap ( ) ;
6876 Ok ( response)
@@ -71,6 +79,12 @@ fn initialize(params: &InitializeBuild) -> Result<InitializeBuild> {
7179fn get_compile_args < ' a > ( path : impl AsRef < Path > ) -> Result < XCCompileArgs > {
7280 let mut state = state ( ) . lock ( ) . unwrap ( ) ;
7381 let path = path. as_ref ( ) ;
82+
83+ if state. last_modified != std:: fs:: metadata ( & state. compile_filepath ) ?. modified ( ) ? {
84+ state. compile_db = XCCompilationDatabase :: try_from_filepath ( & state. compile_filepath ) ?;
85+ state. file_args = Default :: default ( ) ;
86+ }
87+
7488 if state. file_args . contains_key ( path) {
7589 log:: debug!( "Using Cached file args ..." ) ;
7690 state. file_args . get ( path)
0 commit comments