1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! LSP adapter for [`increparse`]: a framework-agnostic bridge between the
//! Language Server Protocol and incremental multi-pass parsing.
//!
//! The crate depends only on [`lsp_types`] — no server framework, no async
//! runtime, no I/O. You keep your server loop (`lsp-server`, `tower-lsp`,
//! `async-lsp`, a hand-rolled loop) and use this crate for the plumbing that
//! is easy to get wrong:
//!
//! * **Position encoding** — LSP positions are `(line, character)` pairs in
//! UTF-8, UTF-16, or UTF-32 code units (negotiated via the
//! `positionEncoding` capability); increparse spans are byte offsets.
//! [`LineIndex`] converts between the two, correctly, across multibyte
//! text.
//! * **[`Document`]** — one open file: its text, its [`Session`], the client
//! version, and the negotiated encoding. `didOpen`/`didChange` events go
//! in; a run report comes out. Incremental change events are translated
//! into byte-range [`Edit`]s so the tree reuses everything the edit did
//! not touch.
//! * **Diagnostics** — walk the settled tree, hand [`Failed`](increparse::Status)
//! regions to your language-specific hook, and get back publishable
//! `Diagnostic`s with correctly converted ranges.
//!
//! # Examples
//!
//! ```
//! use increparse::{Engine, Outcome, Pass, Schedule, SerialExecutor, Span, Status};
//! use increparse_lsp::{Document, PositionEncoding};
//! use lsp_types::Uri;
//!
//! #[derive(Clone, Debug, PartialEq, Eq)]
//! enum Ctx { File }
//!
//! struct Accept;
//! impl Pass for Accept {
//! type Ctx = Ctx;
//! fn parse(&self, _source: &str, _span: Span, _ctx: &Ctx) -> Outcome<Ctx> {
//! Outcome::Done
//! }
//! }
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let uri: Uri = "file:///hello.txt".parse()?;
//! let mut doc = Document::open(uri, 0, "".into(), "héllo wörld".into(), PositionEncoding::Utf16, Ctx::File);
//!
//! let engine = Engine::with((Accept,));
//!
//! // The client edits "héllo" -> "héy": a same-length replace at byte 3.
//! // Translate the client's change events into `Edit`s via
//! // `Document::apply_changes`, then inspect the report:
//! let text = doc.text().to_string();
//! let report = engine.run(
//! &text,
//! doc.session_mut().tree_mut(),
//! &SerialExecutor,
//! &increparse::CancelToken::new(),
//! );
//! assert!(report.reached_fixpoint);
//! # Ok(())
//! # }
//! ```
//!
//! A complete (small) server lives in `examples/mini_lang_server.rs`.
pub use ;
pub use Document;
pub use PositionEncoding;
pub use LineIndex;
pub use ;
pub use ;
/// The types you almost always want, in one glob (includes the core
/// prelude).