jsona_cli/commands/
lsp.rs

1use crate::App;
2
3use clap::Subcommand;
4use jsona_util::environment::{native::NativeEnvironment, Environment};
5
6impl<E: Environment> App<E> {
7    pub async fn execute_lsp(&self, cmd: LspCommand) -> Result<(), anyhow::Error> {
8        let server = jsona_lsp::create_server();
9        let world = jsona_lsp::create_world(NativeEnvironment::new());
10
11        match cmd {
12            LspCommand::Tcp { address } => {
13                server
14                    .listen_tcp(world, &address, async_ctrlc::CtrlC::new().unwrap())
15                    .await
16            }
17            LspCommand::Stdio {} => {
18                server
19                    .listen_stdio(world, async_ctrlc::CtrlC::new().unwrap())
20                    .await
21            }
22        }
23    }
24}
25
26#[derive(Debug, Clone, Subcommand)]
27pub enum LspCommand {
28    /// Run the language server and listen on a TCP address.
29    Tcp {
30        /// The address to listen on.
31        #[clap(long, default_value = "0.0.0.0:9182")]
32        address: String,
33    },
34    /// Run the language server over the standard input and output.
35    Stdio {},
36}