@@ -127,7 +127,7 @@ impl WorkspaceManager {
127127 update_code_style ( & parent_dir, & file_normalized) ;
128128 }
129129
130- pub async fn reload_workspace ( & self ) -> Option < ( ) > {
130+ pub fn add_reload_workspace_task ( & self ) -> Option < ( ) > {
131131 let config_root: Option < PathBuf > = self . workspace_folders . first ( ) . map ( PathBuf :: from) ;
132132
133133 let emmyrc = load_emmy_config ( config_root, self . client_config . clone ( ) ) ;
@@ -136,15 +136,34 @@ impl WorkspaceManager {
136136 let status_bar = self . status_bar . clone ( ) ;
137137 let file_diagnostic = self . file_diagnostic . clone ( ) ;
138138 let lsp_features = self . lsp_features . clone ( ) ;
139- init_analysis (
140- & analysis,
141- & status_bar,
142- & file_diagnostic,
143- & lsp_features,
144- workspace_folders,
145- emmyrc,
146- )
147- . await ;
139+ let client = self . client . clone ( ) ;
140+ let workspace_diagnostic_status = self . workspace_diagnostic_level . clone ( ) ;
141+ tokio:: spawn ( async move {
142+ // Perform reindex with minimal lock holding time
143+ init_analysis (
144+ & analysis,
145+ & status_bar,
146+ & file_diagnostic,
147+ & lsp_features,
148+ workspace_folders,
149+ emmyrc,
150+ )
151+ . await ;
152+
153+ // Cancel diagnostics and update status without holding analysis lock
154+ file_diagnostic. cancel_workspace_diagnostic ( ) . await ;
155+ workspace_diagnostic_status
156+ . store ( WorkspaceDiagnosticLevel :: Fast . to_u8 ( ) , Ordering :: Release ) ;
157+
158+ // Trigger diagnostics refresh
159+ if lsp_features. supports_workspace_diagnostic ( ) {
160+ client. refresh_workspace_diagnostics ( ) ;
161+ } else {
162+ file_diagnostic
163+ . add_workspace_diagnostic_task ( 500 , true )
164+ . await ;
165+ }
166+ } ) ;
148167
149168 Some ( ( ) )
150169 }
0 commit comments