Compare commits

...

1 Commits

Author SHA1 Message Date
Cole Miller
923d6b5e14 Scaffold out support for adding open tabs as context with @tabs
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
2025-05-02 11:49:55 -04:00
2 changed files with 60 additions and 1 deletions

View File

@@ -80,24 +80,28 @@ enum ContextPickerMode {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum ContextPickerAction {
AddSelections,
AddTabs,
}
impl ContextPickerAction {
pub fn keyword(&self) -> &'static str {
match self {
Self::AddSelections => "selection",
Self::AddTabs => "tabs",
}
}
pub fn label(&self) -> &'static str {
match self {
Self::AddSelections => "Selection",
Self::AddTabs => "Tabs",
}
}
pub fn icon(&self) -> IconName {
match self {
Self::AddSelections => IconName::Context,
Self::AddTabs => IconName::Tab,
}
}
}
@@ -363,6 +367,10 @@ impl ContextPicker {
cx.emit(DismissEvent);
}
ContextPickerAction::AddTabs => {
add_tabs_as_context();
cx.emit(DismissEvent);
}
},
}
@@ -561,6 +569,8 @@ fn available_context_picker_entries(
));
}
entries.push(ContextPickerEntry::Action(ContextPickerAction::AddTabs));
if thread_store.is_some() {
entries.push(ContextPickerEntry::Mode(ContextPickerMode::Thread));
}
@@ -675,6 +685,10 @@ fn selection_ranges(
})
}
fn add_tabs_as_context() {
// FIXME
}
pub(crate) fn insert_fold_for_mention(
excerpt_id: ExcerptId,
crease_start: text::Anchor,
@@ -882,6 +896,10 @@ impl MentionLink {
format!("[@{}]({}:{})", rules.title, Self::RULES, rules.prompt_id.0)
}
pub fn for_tabs() -> String {
format!("[@tabs](tabs)")
}
pub fn try_parse(link: &str, workspace: &Entity<Workspace>, cx: &App) -> Option<Self> {
fn extract_project_path_from_link(
path: &str,
@@ -943,5 +961,6 @@ impl MentionLink {
}
_ => None,
}
// FIXME support tabs
}
}

View File

@@ -276,7 +276,10 @@ impl ContextPickerCompletionProvider {
confirm: Some(Arc::new(|_, _, _| true)),
}),
ContextPickerEntry::Action(action) => {
let (new_text, on_action) = match action {
let (new_text, on_action): (
_,
Arc<dyn Fn(CompletionIntent, &mut Window, &mut App) -> bool + Send + Sync>,
) = match action {
ContextPickerAction::AddSelections => {
let selections = selection_ranges(workspace, cx);
@@ -369,6 +372,10 @@ impl ContextPickerCompletionProvider {
(new_text, callback)
}
ContextPickerAction::AddTabs => {
let callback = Arc::new(|_, _: &mut Window, _: &mut App| false);
(MentionLink::for_tabs(), callback)
}
};
Some(Completion {
@@ -656,6 +663,39 @@ impl ContextPickerCompletionProvider {
)),
})
}
// fn completion_for_tabs(
// excerpt_id: ExcerptId,
// source_range: Range<Anchor>,
// editor: Entity<Editor>,
// context_store: Entity<ContextStore>,
// cx: &mut App,
// ) -> Option<Completion> {
// let new_text = MentionLink::for_tabs();
// let label = CodeLabel::plain("Tabs".into(), None);
// let confirm = confirm_completion_callback(
// IconName::Tab.path().into(),
// "Tabs".into(),
// excerpt_id,
// source_range.start,
// new_text.len(),
// editor,
// move |cx| {
// // FIXME
// },
// );
// let completion = Completion {
// replace_range: source_range.clone(),
// new_text,
// label,
// documentation: None,
// source: CompletionSource::Custom,
// icon_path: Some(IconName::Tab.path().into()),
// insert_text_mode: None,
// confirm: Some(confirm),
// };
// Some(completion)
// }
}
fn build_code_label_for_full_path(file_name: &str, directory: Option<&str>, cx: &App) -> CodeLabel {