Skip to main content

jlens_lsp/
lib.rs

1//! # jlens-lsp
2//!
3//! A language server ([LSP](https://microsoft.github.io/language-server-protocol/)) for JSONata
4//! expressions, built on the [`jlens_schema::LanguageService`]: completion of fields, variables
5//! and functions, diagnostics (syntax errors, annotation problems, fields the schema does not
6//! have), hover and signature help.
7//!
8//! Which schema, variables and host functions apply to which files is configured in a
9//! `jlens.json` at the root of each workspace folder, mapping path patterns to settings:
10//!
11//! ```json
12//! {
13//!   "rules/**/*.jsonata": {
14//!     "schema": "schemas/order.schema.json",
15//!     "variables": {"minimum": {"type": "number"}},
16//!     "functions": [{"name": "shipping", "signature": "<ns:n>", "summary": "Shipping cost"}]
17//!   }
18//! }
19//! ```
20//!
21//! The [`config`] module reads these files; `jlens check` uses it too. The `jlens lsp` command of
22//! `jlens-cli` runs [`run_stdio`]. Embedders can run [`run`] on
23//! another [`lsp_server::Connection`], such as an in-memory one.
24
25pub mod config;
26mod server;
27mod text;
28mod uri;
29
30pub use server::{Error, run};
31
32/// Runs the server over standard input and output, until the client asks it to exit.
33pub fn run_stdio() -> Result<(), Error> {
34    let (connection, io_threads) = lsp_server::Connection::stdio();
35    run(&connection)?;
36    drop(connection);
37    io_threads.join()?;
38    Ok(())
39}