fix(lsp): close a window's documents when the window closes

Documents were only closed by sync_window, which runs when a window's
buffer set changes. Closing a window never ran it, so no didClose was
sent, the idle shutdown never started, and a language server lived on
until quit (forever, with the app retired to the tray).
This commit is contained in:
l0ng-ai
2026-09-28 18:03:05 +08:00
parent 9aec58688b
commit 4b7def2d74
2 changed files with 17 additions and 1 deletions
+10 -1
View File
@@ -1605,6 +1605,11 @@ impl Tty7App {
crate::ui::tray::init(cx);
}
app.refresh_shells(cx);
// Backstop for every other way a window goes away (a workspace
// closed from elsewhere): its language-server documents go with it.
let app_id = cx.entity_id();
cx.on_release(move |_, cx| crate::ui::lsp::LspStore::sync_window(app_id, Vec::new(), cx))
.detach();
cx.on_app_quit(|app, cx| {
app.save_session(cx);
crate::core::window_state::WindowState::from_bounds(app.window_bounds).save();
@@ -1670,7 +1675,10 @@ impl Tty7App {
if asked {
return false;
}
app.update(cx, |app, cx| app.prepare_window_close(cx));
app.update(cx, |app, cx| {
app.prepare_window_close(cx);
app.lsp_window_closed(cx);
});
true
});
@@ -1772,6 +1780,7 @@ impl Tty7App {
return;
}
self.prepare_window_close(cx);
self.lsp_window_closed(cx);
window.remove_window();
}
+7
View File
@@ -52,6 +52,13 @@ impl Tty7App {
LspStore::sync_window(cx.entity_id(), buffers, cx);
}
/// The window is closing: every document it owns is closed now, so an
/// idle server can wind down instead of outliving the window (with a
/// tray icon the app itself keeps running).
pub(crate) fn lsp_window_closed(&self, cx: &mut Context<Self>) {
LspStore::sync_window(cx.entity_id(), Vec::new(), cx);
}
/// A buffer's text changed.
pub(crate) fn lsp_buffer_edited(&self, id: BufferId, cx: &mut Context<Self>) {
if let Some(f) = self.editor_local_file(id) {