Add ability to attach rules as context (#29109)
Release Notes: - agent: Added support for adding rules as context.
This commit is contained in:
parent
3b31860d52
commit
7aa0fa1543
18 changed files with 694 additions and 112 deletions
|
@ -16,6 +16,7 @@ use release_channel::ReleaseChannel;
|
|||
use rope::Rope;
|
||||
use settings::Settings;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::time::Duration;
|
||||
use theme::ThemeSettings;
|
||||
use ui::{
|
||||
|
@ -75,7 +76,7 @@ pub fn open_prompt_library(
|
|||
language_registry: Arc<LanguageRegistry>,
|
||||
inline_assist_delegate: Box<dyn InlineAssistDelegate>,
|
||||
make_completion_provider: Arc<dyn Fn() -> Box<dyn CompletionProvider>>,
|
||||
prompt_to_focus: Option<PromptId>,
|
||||
prompt_to_select: Option<PromptId>,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<WindowHandle<PromptLibrary>>> {
|
||||
let store = PromptStore::global(cx);
|
||||
|
@ -90,8 +91,8 @@ pub fn open_prompt_library(
|
|||
if let Some(existing_window) = existing_window {
|
||||
existing_window
|
||||
.update(cx, |prompt_library, window, cx| {
|
||||
if let Some(prompt_to_focus) = prompt_to_focus {
|
||||
prompt_library.load_prompt(prompt_to_focus, true, window, cx);
|
||||
if let Some(prompt_to_select) = prompt_to_select {
|
||||
prompt_library.load_prompt(prompt_to_select, true, window, cx);
|
||||
}
|
||||
window.activate_window()
|
||||
})
|
||||
|
@ -126,18 +127,15 @@ pub fn open_prompt_library(
|
|||
},
|
||||
|window, cx| {
|
||||
cx.new(|cx| {
|
||||
let mut prompt_library = PromptLibrary::new(
|
||||
PromptLibrary::new(
|
||||
store,
|
||||
language_registry,
|
||||
inline_assist_delegate,
|
||||
make_completion_provider,
|
||||
prompt_to_select,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
if let Some(prompt_to_focus) = prompt_to_focus {
|
||||
prompt_library.load_prompt(prompt_to_focus, true, window, cx);
|
||||
}
|
||||
prompt_library
|
||||
)
|
||||
})
|
||||
},
|
||||
)
|
||||
|
@ -221,7 +219,8 @@ impl PickerDelegate for PromptPickerDelegate {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Picker<Self>>,
|
||||
) -> Task<()> {
|
||||
let search = self.store.read(cx).search(query, cx);
|
||||
let cancellation_flag = Arc::new(AtomicBool::default());
|
||||
let search = self.store.read(cx).search(query, cancellation_flag, cx);
|
||||
let prev_prompt_id = self.matches.get(self.selected_index).map(|mat| mat.id);
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
let (matches, selected_index) = cx
|
||||
|
@ -353,13 +352,26 @@ impl PromptLibrary {
|
|||
language_registry: Arc<LanguageRegistry>,
|
||||
inline_assist_delegate: Box<dyn InlineAssistDelegate>,
|
||||
make_completion_provider: Arc<dyn Fn() -> Box<dyn CompletionProvider>>,
|
||||
prompt_to_select: Option<PromptId>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let (selected_index, matches) = if let Some(prompt_to_select) = prompt_to_select {
|
||||
let matches = store.read(cx).all_prompt_metadata();
|
||||
let selected_index = matches
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, metadata)| metadata.id == prompt_to_select)
|
||||
.map_or(0, |(ix, _)| ix);
|
||||
(selected_index, matches)
|
||||
} else {
|
||||
(0, vec![])
|
||||
};
|
||||
|
||||
let delegate = PromptPickerDelegate {
|
||||
store: store.clone(),
|
||||
selected_index: 0,
|
||||
matches: Vec::new(),
|
||||
selected_index,
|
||||
matches,
|
||||
};
|
||||
|
||||
let picker = cx.new(|cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue