Fix circular reference issue around PopoverMenu (#42461)

Follow up to https://github.com/zed-industries/zed/pull/42351

Release Notes:

- N/A
This commit is contained in:
feeiyu 2025-11-12 01:20:38 +08:00 committed by GitHub
parent c50f821613
commit 5f4d0dbaab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 12 deletions

View file

@ -128,20 +128,21 @@ impl Render for EditPredictionButton {
}),
);
}
let this = cx.entity();
let this = cx.weak_entity();
div().child(
PopoverMenu::new("copilot")
.menu(move |window, cx| {
let current_status = Copilot::global(cx)?.read(cx).status();
Some(match current_status {
match current_status {
Status::Authorized => this.update(cx, |this, cx| {
this.build_copilot_context_menu(window, cx)
}),
_ => this.update(cx, |this, cx| {
this.build_copilot_start_menu(window, cx)
}),
})
}
.ok()
})
.anchor(Corner::BottomRight)
.trigger_with_tooltip(
@ -182,7 +183,7 @@ impl Render for EditPredictionButton {
let icon = status.to_icon();
let tooltip_text = status.to_tooltip();
let has_menu = status.has_menu();
let this = cx.entity();
let this = cx.weak_entity();
let fs = self.fs.clone();
div().child(
@ -209,9 +210,11 @@ impl Render for EditPredictionButton {
)
}))
}
SupermavenButtonStatus::Ready => Some(this.update(cx, |this, cx| {
this.build_supermaven_context_menu(window, cx)
})),
SupermavenButtonStatus::Ready => this
.update(cx, |this, cx| {
this.build_supermaven_context_menu(window, cx)
})
.ok(),
_ => None,
})
.anchor(Corner::BottomRight)
@ -233,15 +236,16 @@ impl Render for EditPredictionButton {
let enabled = self.editor_enabled.unwrap_or(true);
let has_api_key = CodestralCompletionProvider::has_api_key(cx);
let fs = self.fs.clone();
let this = cx.entity();
let this = cx.weak_entity();
div().child(
PopoverMenu::new("codestral")
.menu(move |window, cx| {
if has_api_key {
Some(this.update(cx, |this, cx| {
this.update(cx, |this, cx| {
this.build_codestral_context_menu(window, cx)
}))
})
.ok()
} else {
Some(ContextMenu::build(window, cx, |menu, _, _| {
let fs = fs.clone();

View file

@ -1053,11 +1053,16 @@ impl Render for LspButton {
(None, "All Servers Operational")
};
let lsp_button = cx.entity();
let lsp_button = cx.weak_entity();
div().child(
PopoverMenu::new("lsp-tool")
.menu(move |_, cx| lsp_button.read(cx).lsp_menu.clone())
.menu(move |_, cx| {
lsp_button
.read_with(cx, |lsp_button, _| lsp_button.lsp_menu.clone())
.ok()
.flatten()
})
.anchor(Corner::BottomLeft)
.with_handle(self.popover_menu_handle.clone())
.trigger_with_tooltip(