authenticate with completion provider on new inline assists

This commit is contained in:
KCaverly 2023-11-02 09:34:18 -04:00
parent 78f47f179a
commit b5fe0d72ee
2 changed files with 17 additions and 12 deletions

View file

@ -259,7 +259,13 @@ impl AssistantPanel {
cx: &mut ViewContext<Workspace>,
) {
let this = if let Some(this) = workspace.panel::<AssistantPanel>(cx) {
if this.update(cx, |assistant, _| assistant.has_credentials()) {
if this.update(cx, |assistant, cx| {
if !assistant.has_credentials() {
assistant.load_credentials(cx);
};
assistant.has_credentials()
}) {
this
} else {
workspace.focus_panel::<AssistantPanel>(cx);
@ -320,13 +326,10 @@ impl AssistantPanel {
};
let inline_assist_id = post_inc(&mut self.next_inline_assist_id);
let provider = Arc::new(OpenAICompletionProvider::new(
"gpt-4",
cx.background().clone(),
));
let provider = self.completion_provider.clone();
// Retrieve Credentials Authenticates the Provider
// provider.retrieve_credentials(cx);
provider.retrieve_credentials(cx);
let codegen = cx.add_model(|cx| {
Codegen::new(editor.read(cx).buffer().clone(), codegen_kind, provider, cx)

View file

@ -6,7 +6,7 @@ use futures::{channel::mpsc, SinkExt, Stream, StreamExt};
use gpui::{Entity, ModelContext, ModelHandle, Task};
use language::{Rope, TransactionId};
use multi_buffer;
use std::{cmp, future, ops::Range, sync::Arc};
use std::{cmp, future, ops::Range};
pub enum Event {
Finished,
@ -20,7 +20,7 @@ pub enum CodegenKind {
}
pub struct Codegen {
provider: Arc<dyn CompletionProvider>,
provider: Box<dyn CompletionProvider>,
buffer: ModelHandle<MultiBuffer>,
snapshot: MultiBufferSnapshot,
kind: CodegenKind,
@ -40,7 +40,7 @@ impl Codegen {
pub fn new(
buffer: ModelHandle<MultiBuffer>,
kind: CodegenKind,
provider: Arc<dyn CompletionProvider>,
provider: Box<dyn CompletionProvider>,
cx: &mut ModelContext<Self>,
) -> Self {
let snapshot = buffer.read(cx).snapshot(cx);
@ -367,6 +367,8 @@ fn strip_invalid_spans_from_codeblock(
#[cfg(test)]
mod tests {
use std::sync::Arc;
use super::*;
use ai::test::FakeCompletionProvider;
use futures::stream::{self};
@ -412,7 +414,7 @@ mod tests {
let snapshot = buffer.snapshot(cx);
snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(4, 5))
});
let provider = Arc::new(FakeCompletionProvider::new());
let provider = Box::new(FakeCompletionProvider::new());
let codegen = cx.add_model(|cx| {
Codegen::new(
buffer.clone(),
@ -478,7 +480,7 @@ mod tests {
let snapshot = buffer.snapshot(cx);
snapshot.anchor_before(Point::new(1, 6))
});
let provider = Arc::new(FakeCompletionProvider::new());
let provider = Box::new(FakeCompletionProvider::new());
let codegen = cx.add_model(|cx| {
Codegen::new(
buffer.clone(),
@ -544,7 +546,7 @@ mod tests {
let snapshot = buffer.snapshot(cx);
snapshot.anchor_before(Point::new(1, 2))
});
let provider = Arc::new(FakeCompletionProvider::new());
let provider = Box::new(FakeCompletionProvider::new());
let codegen = cx.add_model(|cx| {
Codegen::new(
buffer.clone(),