Skip to content

Commit

Permalink
Initialize lsp_adapter_delegate when deserializing and in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdeviant committed May 24, 2024
1 parent 26802ca commit b67155e
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions crates/assistant/src/assistant_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,13 @@ impl AssistantPanel {
let slash_commands = self.slash_commands.clone();
let languages = self.languages.clone();
let telemetry = self.telemetry.clone();

let lsp_adapter_delegate = workspace
.update(cx, |workspace, cx| {
make_lsp_adapter_delegate(workspace.project(), cx)
})
.log_err();

cx.spawn(|this, mut cx| async move {
let saved_conversation = SavedConversation::load(&path, fs.as_ref()).await?;
let model = this.update(&mut cx, |this, _| this.model.clone())?;
Expand All @@ -1139,6 +1146,7 @@ impl AssistantPanel {
languages,
slash_commands,
Some(telemetry),
lsp_adapter_delegate,
&mut cx,
)
.await?;
Expand Down Expand Up @@ -1579,6 +1587,7 @@ impl Conversation {
language_registry: Arc<LanguageRegistry>,
slash_command_registry: Arc<SlashCommandRegistry>,
telemetry: Option<Arc<Telemetry>>,
lsp_adapter_delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut AsyncAppContext,
) -> Result<Model<Self>> {
let id = match saved_conversation.id {
Expand Down Expand Up @@ -1638,8 +1647,7 @@ impl Conversation {
telemetry,
language_registry,
slash_command_registry,
// TODO: Initialize this when deserializing.
lsp_adapter_delegate: None,
lsp_adapter_delegate,
};
this.set_language(cx);
this.reparse_edit_suggestions(cx);
Expand Down Expand Up @@ -2740,22 +2748,15 @@ impl ConversationEditor {
) -> Self {
let telemetry = workspace.read(cx).client().telemetry().clone();
let project = workspace.read(cx).project().clone();
let delegate = project.update(cx, |project, cx| {
// TODO: Find the right worktree.
let worktree = project
.worktrees()
.next()
.expect("expected at least one worktree");
ProjectLspAdapterDelegate::new(project, &worktree, cx)
});
let lsp_adapter_delegate = make_lsp_adapter_delegate(&project, cx);

let conversation = cx.new_model(|cx| {
Conversation::new(
model,
language_registry,
slash_command_registry,
Some(telemetry),
Some(delegate),
Some(lsp_adapter_delegate),
cx,
)
});
Expand Down Expand Up @@ -3929,6 +3930,20 @@ fn merge_ranges(ranges: &mut Vec<Range<Anchor>>, buffer: &MultiBufferSnapshot) {
}
}

fn make_lsp_adapter_delegate(
project: &Model<Project>,
cx: &mut AppContext,
) -> Arc<dyn LspAdapterDelegate> {
project.update(cx, |project, cx| {
// TODO: Find the right worktree.
let worktree = project
.worktrees()
.next()
.expect("expected at least one worktree");
ProjectLspAdapterDelegate::new(project, &worktree, cx)
})
}

#[cfg(test)]
mod tests {
use std::{cell::RefCell, path::Path, rc::Rc};
Expand Down Expand Up @@ -4317,14 +4332,23 @@ mod tests {
prompt_library.clone(),
));

let lsp_adapter_delegate = project.update(cx, |project, cx| {
// TODO: Find the right worktree.
let worktree = project
.worktrees()
.next()
.expect("expected at least one worktree");
ProjectLspAdapterDelegate::new(project, &worktree, cx)
});

let registry = Arc::new(LanguageRegistry::test(cx.executor()));
let conversation = cx.new_model(|cx| {
Conversation::new(
LanguageModel::default(),
registry.clone(),
slash_command_registry,
None,
None,
Some(lsp_adapter_delegate),
cx,
)
});
Expand Down Expand Up @@ -4669,6 +4693,7 @@ mod tests {
registry.clone(),
Default::default(),
None,
None,
&mut cx.to_async(),
)
.await
Expand Down

0 comments on commit b67155e

Please sign in to comment.