mz_deploy/lsp/run.rs
1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! LSP server entry point.
11//!
12//! Sets up the `tower-lsp` service with [`Backend`] and runs the server
13//! over stdin/stdout.
14
15use crate::cli::CliError;
16use std::path::PathBuf;
17use tower_lsp::{LspService, Server};
18
19use super::server::Backend;
20
21/// Run the LSP server over stdio.
22///
23/// This is the entry point called from the `lsp` subcommand. It blocks until
24/// the client disconnects.
25pub async fn run(root: PathBuf) -> Result<(), CliError> {
26 let stdin = tokio::io::stdin();
27 let stdout = tokio::io::stdout();
28
29 let (service, socket) =
30 LspService::build(|client| Backend::new_with_root(client, root)).finish();
31
32 Server::new(stdin, stdout, socket).serve(service).await;
33 Ok(())
34}