From 78aaa29d5b768f09ae393bf3d3f150d9f803f3df Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 25 May 2024 15:59:40 -0400 Subject: [PATCH] assistant: Replace an `expect` with a precondition check (#12292) This PR replaces an `expect` with a precondition check to avoid a panic if the `LspAdapterDelegate` isn't set when invoking a slash command. Release Notes: - N/A --- crates/assistant/src/assistant_panel.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index e753d75b2706df01164c608ef2c29d7ab82c035f..e58731a00b8696b8dde0a45085991c33fa086417 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -1858,20 +1858,18 @@ impl Conversation { let name = &line[call.name]; if let Some(call) = unchanged_call { new_calls.push(call); - } else if let Some(command) = this.slash_command_registry.command(name) { + } else if let Some((command, lsp_adapter_delegate)) = this + .slash_command_registry + .command(name) + .zip(this.lsp_adapter_delegate.clone()) + { changed = true; let name = name.to_string(); let source_range = buffer.anchor_after(offset)..buffer.anchor_before(line_end_offset); let argument = call.argument.map(|range| &line[range]); - let invocation = command.run( - argument, - this.lsp_adapter_delegate - .clone() - .expect("no LspAdapterDelegate present when invoking command"), - cx, - ); + let invocation = command.run(argument, lsp_adapter_delegate, cx); new_calls.push(SlashCommandCall { name,