zeph_commands/handlers/
lsp.rs1use std::future::Future;
7use std::pin::Pin;
8
9use crate::context::CommandContext;
10use crate::{CommandError, CommandHandler, CommandOutput, SlashCategory};
11
12pub struct LspCommand;
14
15impl CommandHandler<CommandContext<'_>> for LspCommand {
16 fn name(&self) -> &'static str {
17 "/lsp"
18 }
19
20 fn description(&self) -> &'static str {
21 "Show LSP context status"
22 }
23
24 fn category(&self) -> SlashCategory {
25 SlashCategory::Debugging
26 }
27
28 fn feature_gate(&self) -> Option<&'static str> {
29 Some("lsp-context")
30 }
31
32 fn requires_auth(&self) -> bool {
33 true
34 }
35
36 fn handle<'a>(
37 &'a self,
38 ctx: &'a mut CommandContext<'_>,
39 _args: &'a str,
40 ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>> {
41 use tracing::Instrument as _;
42 let span = tracing::info_span!("commands.lsp.handle");
43 Box::pin(
44 async move {
45 let result = ctx.agent.lsp_status().await?;
46 Ok(CommandOutput::message_or_silent(result))
47 }
48 .instrument(span),
49 )
50 }
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56 use crate::handlers::test_helpers::{MockDebug, MockMessages, MockSession, make_ctx};
57 use crate::sink::NullSink;
58 use std::assert_matches;
59
60 #[test]
61 fn lsp_name_and_description() {
62 assert_eq!(LspCommand.name(), "/lsp");
63 assert!(!LspCommand.description().is_empty());
64 }
65
66 #[tokio::test]
67 async fn lsp_returns_silent_when_agent_returns_empty() {
68 let mut sink = NullSink;
70 let mut debug = MockDebug;
71 let mut messages = MockMessages;
72 let session = MockSession;
73 let mut agent = crate::NullAgent;
74 let mut ctx = make_ctx(&mut sink, &mut debug, &mut messages, &session, &mut agent);
75 let out = LspCommand.handle(&mut ctx, "").await.unwrap();
76 assert_matches!(out, CommandOutput::Silent);
77 }
78}