From 8911fd46e12695f4bfb87e49e3261d8100dc8c97 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 9 Oct 2024 18:45:22 +0300 Subject: [PATCH] Do not log errors when no worktree is found for certain assistant panel editors (#18923) Nothing in the assistant panel needs LSP so far, so the errors are not useful. Release Notes: - N/A --- crates/assistant/src/assistant_panel.rs | 32 +++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 20e6347d01..c3b4fcc4dc 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -18,7 +18,7 @@ use crate::{ PendingSlashCommand, PendingSlashCommandStatus, QuoteSelection, RemoteContextMetadata, SavedContextMetadata, Split, ToggleFocus, ToggleModelSelector, WorkflowStepResolution, }; -use anyhow::{anyhow, Result}; +use anyhow::Result; use assistant_slash_command::{SlashCommand, SlashCommandOutputSection}; use assistant_tool::ToolRegistry; use client::{proto, Client, Status}; @@ -697,7 +697,9 @@ impl AssistantPanel { log::error!("no context found with ID: {}", context_id.to_proto()); return; }; - let lsp_adapter_delegate = make_lsp_adapter_delegate(&self.project, cx).log_err(); + let lsp_adapter_delegate = make_lsp_adapter_delegate(&self.project, cx) + .log_err() + .flatten(); let assistant_panel = cx.view().downgrade(); let editor = cx.new_view(|cx| { @@ -971,7 +973,8 @@ impl AssistantPanel { this.update(&mut cx, |this, cx| { let workspace = this.workspace.clone(); let project = this.project.clone(); - let lsp_adapter_delegate = make_lsp_adapter_delegate(&project, cx).log_err(); + let lsp_adapter_delegate = + make_lsp_adapter_delegate(&project, cx).log_err().flatten(); let fs = this.fs.clone(); let project = this.project.clone(); @@ -1001,7 +1004,9 @@ impl AssistantPanel { None } else { let context = self.context_store.update(cx, |store, cx| store.create(cx)); - let lsp_adapter_delegate = make_lsp_adapter_delegate(&self.project, cx).log_err(); + let lsp_adapter_delegate = make_lsp_adapter_delegate(&self.project, cx) + .log_err() + .flatten(); let assistant_panel = cx.view().downgrade(); let editor = cx.new_view(|cx| { @@ -1207,7 +1212,7 @@ impl AssistantPanel { let project = self.project.clone(); let workspace = self.workspace.clone(); - let lsp_adapter_delegate = make_lsp_adapter_delegate(&project, cx).log_err(); + let lsp_adapter_delegate = make_lsp_adapter_delegate(&project, cx).log_err().flatten(); cx.spawn(|this, mut cx| async move { let context = context.await?; @@ -1254,7 +1259,9 @@ impl AssistantPanel { .update(cx, |store, cx| store.open_remote_context(id, cx)); let fs = self.fs.clone(); let workspace = self.workspace.clone(); - let lsp_adapter_delegate = make_lsp_adapter_delegate(&self.project, cx).log_err(); + let lsp_adapter_delegate = make_lsp_adapter_delegate(&self.project, cx) + .log_err() + .flatten(); cx.spawn(|this, mut cx| async move { let context = context.await?; @@ -5505,22 +5512,21 @@ fn render_docs_slash_command_trailer( fn make_lsp_adapter_delegate( project: &Model, cx: &mut AppContext, -) -> Result> { +) -> Result>> { project.update(cx, |project, cx| { // TODO: Find the right worktree. - let worktree = project - .worktrees(cx) - .next() - .ok_or_else(|| anyhow!("no worktrees when constructing LocalLspAdapterDelegate"))?; + let Some(worktree) = project.worktrees(cx).next() else { + return Ok(None::>); + }; let http_client = project.client().http_client().clone(); project.lsp_store().update(cx, |lsp_store, cx| { - Ok(LocalLspAdapterDelegate::new( + Ok(Some(LocalLspAdapterDelegate::new( lsp_store, &worktree, http_client, project.fs().clone(), cx, - ) as Arc) + ) as Arc)) }) }) }