authenticate with completion provider on new inline assists
This commit is contained in:
parent
78f47f179a
commit
b5fe0d72ee
2 changed files with 17 additions and 12 deletions
|
@ -259,7 +259,13 @@ impl AssistantPanel {
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
let this = if let Some(this) = workspace.panel::<AssistantPanel>(cx) {
|
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
|
this
|
||||||
} else {
|
} else {
|
||||||
workspace.focus_panel::<AssistantPanel>(cx);
|
workspace.focus_panel::<AssistantPanel>(cx);
|
||||||
|
@ -320,13 +326,10 @@ impl AssistantPanel {
|
||||||
};
|
};
|
||||||
|
|
||||||
let inline_assist_id = post_inc(&mut self.next_inline_assist_id);
|
let inline_assist_id = post_inc(&mut self.next_inline_assist_id);
|
||||||
let provider = Arc::new(OpenAICompletionProvider::new(
|
let provider = self.completion_provider.clone();
|
||||||
"gpt-4",
|
|
||||||
cx.background().clone(),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Retrieve Credentials Authenticates the Provider
|
// Retrieve Credentials Authenticates the Provider
|
||||||
// provider.retrieve_credentials(cx);
|
provider.retrieve_credentials(cx);
|
||||||
|
|
||||||
let codegen = cx.add_model(|cx| {
|
let codegen = cx.add_model(|cx| {
|
||||||
Codegen::new(editor.read(cx).buffer().clone(), codegen_kind, provider, cx)
|
Codegen::new(editor.read(cx).buffer().clone(), codegen_kind, provider, cx)
|
||||||
|
|
|
@ -6,7 +6,7 @@ use futures::{channel::mpsc, SinkExt, Stream, StreamExt};
|
||||||
use gpui::{Entity, ModelContext, ModelHandle, Task};
|
use gpui::{Entity, ModelContext, ModelHandle, Task};
|
||||||
use language::{Rope, TransactionId};
|
use language::{Rope, TransactionId};
|
||||||
use multi_buffer;
|
use multi_buffer;
|
||||||
use std::{cmp, future, ops::Range, sync::Arc};
|
use std::{cmp, future, ops::Range};
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Finished,
|
Finished,
|
||||||
|
@ -20,7 +20,7 @@ pub enum CodegenKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Codegen {
|
pub struct Codegen {
|
||||||
provider: Arc<dyn CompletionProvider>,
|
provider: Box<dyn CompletionProvider>,
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
snapshot: MultiBufferSnapshot,
|
snapshot: MultiBufferSnapshot,
|
||||||
kind: CodegenKind,
|
kind: CodegenKind,
|
||||||
|
@ -40,7 +40,7 @@ impl Codegen {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
kind: CodegenKind,
|
kind: CodegenKind,
|
||||||
provider: Arc<dyn CompletionProvider>,
|
provider: Box<dyn CompletionProvider>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let snapshot = buffer.read(cx).snapshot(cx);
|
let snapshot = buffer.read(cx).snapshot(cx);
|
||||||
|
@ -367,6 +367,8 @@ fn strip_invalid_spans_from_codeblock(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use ai::test::FakeCompletionProvider;
|
use ai::test::FakeCompletionProvider;
|
||||||
use futures::stream::{self};
|
use futures::stream::{self};
|
||||||
|
@ -412,7 +414,7 @@ mod tests {
|
||||||
let snapshot = buffer.snapshot(cx);
|
let snapshot = buffer.snapshot(cx);
|
||||||
snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(4, 5))
|
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| {
|
let codegen = cx.add_model(|cx| {
|
||||||
Codegen::new(
|
Codegen::new(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
|
@ -478,7 +480,7 @@ mod tests {
|
||||||
let snapshot = buffer.snapshot(cx);
|
let snapshot = buffer.snapshot(cx);
|
||||||
snapshot.anchor_before(Point::new(1, 6))
|
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| {
|
let codegen = cx.add_model(|cx| {
|
||||||
Codegen::new(
|
Codegen::new(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
|
@ -544,7 +546,7 @@ mod tests {
|
||||||
let snapshot = buffer.snapshot(cx);
|
let snapshot = buffer.snapshot(cx);
|
||||||
snapshot.anchor_before(Point::new(1, 2))
|
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| {
|
let codegen = cx.add_model(|cx| {
|
||||||
Codegen::new(
|
Codegen::new(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue