adam_lsp/lib.rs
1//! # adam-lsp
2//!
3//! A [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) server
4//! for `adam-lang`, built on [`lsp-server`](https://docs.rs/lsp-server) + `lsp-types`. Surfaces
5//! `adam-lang`'s recovered syntax and nonexecuting type diagnostics as
6//! `textDocument/publishDiagnostics`.
7//!
8//! # Explicit modules
9//!
10//! Initialize with `initializationOptions.moduleSources`, an array of records with
11//! string fields `path` (an explicit [`adam_lang::ModulePath`]), `uri` (the absolute
12//! source URI), and `text` (the complete source). Both paths and URIs must be unique.
13//! Include importing roots as well as definitions:
14//!
15//! ```json
16//! {"moduleSources":[
17//! {"path":"constraints","uri":"file:///repo/constraints.adm2","text":"sheet ordered(a: f64, b: f64) {}"},
18//! {"path":"app","uri":"file:///repo/app.adm2","text":"use constraints::ordered; sheet app { cell x: f64; cell y: f64; relationship ordered(a: x, b: y); }"}
19//! ]}
20//! ```
21//!
22//! Send the same complete object in `workspace/didChangeConfiguration.settings`
23//! to replace the snapshot. `{"moduleSourcesError":"read failure"}` blocks checking
24//! with visible configuration diagnostics until a valid snapshot arrives; it never
25//! substitutes empty source text. Invalid snapshots retain the last valid ownership
26//! mapping and report errors. An empty `moduleSources` array explicitly removes it.
27//! Only initialization permits absent module options for source-only hosts.
28//! Refresh settings must explicitly contain `moduleSources` or `moduleSourcesError`;
29//! missing, null, unrelated or misspelled refresh data reports a configuration
30//! error without discarding the registered mapping.
31//!
32//! Open-document text overrides the registered revision by exact URI, including
33//! through configuration refreshes. Closing restores the supplied revision. Changes
34//! conservatively recheck every registered definition and republish every supplied
35//! and open URI, clearing removed-file diagnostics. Labels retain real file owners
36//! and become cross-file related information with UTF-16 ranges. Unregistered open
37//! files use the source-only convenience checker with the same standard/Euclid
38//! libraries. The server does no filesystem loading, discovery, root instantiation
39//! or automatic language migration.
40//!
41//! Independent module dependency groups are checked separately using structural
42//! imports and qualified component uses, including conditional/default branches.
43//! A rejected source retains its syntax diagnostic; successfully inserted peers
44//! are still checked. Failed groups also receive an explicit incomplete-check
45//! status because earlier checker phases can prevent later analysis. Errors in
46//! another group never turn a known invalid module into a clean publication.
47//!
48//! # Example
49//!
50//! ```rust,no_run
51//! fn main() -> anyhow::Result<()> {
52//! adam_lsp::run()
53//! }
54//! ```
55
56pub mod diagnostics;
57mod dispatch;
58mod modules;
59
60pub use dispatch::{run, serve};