Skip to main content

bock_lsp/
lib.rs

1//! Bock Language Server Protocol implementation.
2//!
3//! Provides an LSP server over stdio that editors can connect to for
4//! diagnostics, hover, go-to-definition, and other Bock tooling features.
5//!
6//! This crate exposes [`BockLanguageServer`] and a [`run_stdio`] entry point
7//! used by `bock-cli` to launch the server.
8
9mod diagnostics;
10mod goto_definition;
11mod hover;
12mod pipeline;
13mod server;
14mod type_display;
15
16pub use diagnostics::{severity_to_lsp, span_to_range, to_lsp_diagnostic};
17pub use goto_definition::{find_definition, position_to_offset, DefinitionResult};
18pub use hover::{hover, HoverResult};
19pub use pipeline::{check_document, CheckResult};
20pub use server::BockLanguageServer;
21pub use type_display::format_type;
22
23use tower_lsp::{LspService, Server};
24
25/// Launch the Bock LSP server over stdio.
26///
27/// Blocks the current thread until the client disconnects. Intended to be
28/// invoked from an async runtime by `bock lsp`.
29pub async fn run_stdio() {
30    let stdin = tokio::io::stdin();
31    let stdout = tokio::io::stdout();
32    let (service, socket) = LspService::new(BockLanguageServer::new);
33    Server::new(stdin, stdout, socket).serve(service).await;
34}