1use std::sync::atomic::AtomicBool;
2use std::sync::Arc;
3
4use anyhow::Result;
5use assistant_slash_command::{
6 ArgumentCompletion, SlashCommand, SlashCommandOutput, SlashCommandOutputSection,
7};
8use chrono::Local;
9use gpui::{AppContext, Task, WeakView};
10use language::LspAdapterDelegate;
11use ui::prelude::*;
12use workspace::Workspace;
13
14pub(crate) struct NowSlashCommand;
15
16impl SlashCommand for NowSlashCommand {
17 fn name(&self) -> String {
18 "now".into()
19 }
20
21 fn description(&self) -> String {
22 "insert the current date and time".into()
23 }
24
25 fn menu_text(&self) -> String {
26 "Insert Current Date and Time".into()
27 }
28
29 fn requires_argument(&self) -> bool {
30 false
31 }
32
33 fn complete_argument(
34 self: Arc<Self>,
35 _query: String,
36 _cancel: Arc<AtomicBool>,
37 _workspace: Option<WeakView<Workspace>>,
38 _cx: &mut AppContext,
39 ) -> Task<Result<Vec<ArgumentCompletion>>> {
40 Task::ready(Ok(Vec::new()))
41 }
42
43 fn run(
44 self: Arc<Self>,
45 _argument: Option<&str>,
46 _workspace: WeakView<Workspace>,
47 _delegate: Arc<dyn LspAdapterDelegate>,
48 _cx: &mut WindowContext,
49 ) -> Task<Result<SlashCommandOutput>> {
50 let now = Local::now();
51 let text = format!("Today is {now}.", now = now.to_rfc2822());
52 let range = 0..text.len();
53
54 Task::ready(Ok(SlashCommandOutput {
55 text,
56 sections: vec![SlashCommandOutputSection {
57 range,
58 icon: IconName::CountdownTimer,
59 label: now.to_rfc2822().into(),
60 }],
61 run_commands_in_text: false,
62 }))
63 }
64}