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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! # lspresso
//!
//! Use existing test helpers and benchmarking tools to validate and performance and correctness!
//!
//! 
//!
//! ```no_run
//! # use std::{process::Command, time::Duration};
//! use lspresso::{Client, capabilities, gen_lsp_types::*};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut client = Client::spawn_initialized(
//! Command::new("my-lsp"),
//! // use capabilities captured from real editors
//! // emacs, helix, neovim, and vscode are supported
//! capabilities::vscode::latest(),
//! )?
//! // default 15s, set to a reasonable upper bound so test timeouts are short
//! .with_timeout(Duration::from_secs(15));
//! let uri: Uri = "hi.json".parse()?;
//!
//! // convenience methods provide a simpler API
//! client.did_open(uri.clone(), "{}", LanguageKind::JSON)?;
//!
//! // for example, `Client::diagnostics` pulls when the server supports it and
//! // waits for pushed diagnostics otherwise
//! let diags = client.diagnostics(&uri)?;
//! assert_eq!(diags, vec![]);
//!
//! // if you need lower level control, import the `Protocol` trait
//! // each method is prefixed with `protocol_` to differentiate from the
//! // convenience layer
//! use lspresso::Protocol as _;
//!
//! // pull diagnostics
//! let diags = client.protocol_diagnostic(DocumentDiagnosticParams {
//! text_document: TextDocumentIdentifier { uri: uri.clone() },
//! identifier: Some("my-lsp".into()),
//! previous_result_id: Some("diagnostics-1".into()),
//! work_done_progress_params: WorkDoneProgressParams {
//! work_done_token: Some(ProgressToken::String("work-done-1".into())),
//! },
//! partial_result_params: PartialResultParams {
//! partial_result_token: Some(ProgressToken::String("partial-1".into())),
//! },
//! })?;
//!
//! // push diagnostics wait for a notification or the timeout
//! let published =
//! client.wait_for_notification_where::<PublishDiagnosticsNotification>(|p| p.uri == uri)?;
//! assert!(published.diagnostics.is_empty());
//!
//! # Ok(())
//! # }
//! ```
//!
//! ## Benchmarking
//!
//! Use existing benchmarking tools like criterion with `Client::timings`.
//! `Timings::server` is time spent in the language server. `request` and `response` are worth a look too since large messages take time
//!
//! ```no_run
//! # use std::{process::Command, time::Duration};
//! # use criterion::{Criterion, criterion_group, criterion_main};
//! # use lspresso::{Client, capabilities, gen_lsp_types::*};
//! fn bench_diagnostics(c: &mut Criterion) {
//! let mut client =
//! Client::spawn_initialized(Command::new("my-lsp"), capabilities::vscode::latest())
//! .unwrap();
//! let uri: Uri = "bench.json".parse().unwrap();
//! client
//! .did_open(uri.clone(), r#"{"a": [1, 2, 3]}"#, LanguageKind::JSON)
//! .unwrap();
//!
//! c.bench_function("diagnostics", |b| {
//! b.iter_custom(|iters| {
//! let before = client.timings();
//! for _ in 0..iters {
//! client.diagnostics(&uri).unwrap();
//! }
//! client.timings().since(before).server
//! });
//! });
//!
//! // peak RSS over the session
//! let rss = client.rss_bytes().expect("the server is running");
//! println!("server RSS: {} MiB", rss / (1024 * 1024));
//! }
//!
//! criterion_group!(benches, bench_diagnostics);
//! criterion_main!(benches);
//! ```
//!
//! ## limitations
//!
//! - server to client requests get a canned response. They could be scriptable and assertable
//! - stdout is supported but not node ipc or tcp
pub use capabilities;
pub use ;
pub use server_command;
pub use ;
pub use gen_lsp_types;
pub use Protocol;