taplo_cli/commands/
lsp.rs1use taplo_common::environment::{native::NativeEnvironment, Environment};
2
3use crate::{
4 args::{LspCommand, LspCommandIo},
5 Taplo,
6};
7
8impl<E: Environment> Taplo<E> {
9 pub async fn execute_lsp(&mut self, cmd: LspCommand) -> Result<(), anyhow::Error> {
10 self.schemas
11 .cache()
12 .set_cache_path(cmd.general.cache_path.clone());
13
14 let config = self.load_config(&cmd.general).await?;
15
16 let server = taplo_lsp::create_server();
17 let world = taplo_lsp::create_world(NativeEnvironment::new());
18 world.set_default_config(config);
19
20 match cmd.io {
21 LspCommandIo::Tcp { address } => {
22 server
23 .listen_tcp(world, &address, async_ctrlc::CtrlC::new().unwrap())
24 .await
25 }
26 LspCommandIo::Stdio {} => {
27 server
28 .listen_stdio(world, async_ctrlc::CtrlC::new().unwrap())
29 .await
30 }
31 }
32 }
33}