]> git.lizzy.rs Git - rust.git/blob - crates/rust-analyzer/src/lib.rs
Merge #3285
[rust.git] / crates / rust-analyzer / src / lib.rs
1 //! Implementation of the LSP for rust-analyzer.
2 //!
3 //! This crate takes Rust-specific analysis results from ra_ide and translates
4 //! into LSP types.
5 //!
6 //! It also is the root of all state. `world` module defines the bulk of the
7 //! state, and `main_loop` module defines the rules for modifying it.
8 //!
9 //! The `cli` submodule implements some batch-processing analysis, primarily as
10 //! a debugging aid.
11 #![recursion_limit = "512"]
12
13 pub mod cli;
14
15 #[allow(unused)]
16 macro_rules! println {
17     ($($tt:tt)*) => {
18         compile_error!("stdout is locked, use eprintln")
19     };
20 }
21
22 #[allow(unused)]
23 macro_rules! print {
24     ($($tt:tt)*) => {
25         compile_error!("stdout is locked, use eprint")
26     };
27 }
28
29 mod vfs_glob;
30 mod caps;
31 mod cargo_target_spec;
32 mod conv;
33 mod main_loop;
34 mod markdown;
35 pub mod req;
36 mod config;
37 mod world;
38 mod diagnostics;
39 mod semantic_tokens;
40
41 use serde::de::DeserializeOwned;
42
43 pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
44 pub use crate::{
45     caps::server_capabilities,
46     config::ServerConfig,
47     main_loop::LspError,
48     main_loop::{main_loop, show_message},
49 };
50
51 pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
52     let res = T::deserialize(&json)
53         .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
54     Ok(res)
55 }