Skip to content

Commit b3d565e

Browse files
committed
try fix deadlock
1 parent a3a27a6 commit b3d565e

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

crates/emmylua_ls/src/context/workspace_manager.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

crates/emmylua_ls/src/handlers/configuration/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub async fn on_did_change_configuration(
3333
let mut workspace_manager = context.workspace_manager().write().await;
3434
workspace_manager.client_config = new_client_config;
3535
log::info!("reloading workspace folders");
36-
workspace_manager.reload_workspace().await;
36+
workspace_manager.add_reload_workspace_task();
3737
}
3838

3939
Some(())

0 commit comments

Comments
 (0)