]> git.lizzy.rs Git - rust.git/blob - crates/rust-analyzer/src/lib.rs
Merge #4396
[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! eprintln {
17     ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
18 }
19
20 mod vfs_glob;
21 mod caps;
22 mod cargo_target_spec;
23 mod to_proto;
24 mod from_proto;
25 mod main_loop;
26 mod markdown;
27 pub mod lsp_ext;
28 pub mod config;
29 mod world;
30 mod diagnostics;
31 mod semantic_tokens;
32
33 use serde::de::DeserializeOwned;
34
35 pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
36 pub use crate::{
37     caps::server_capabilities,
38     main_loop::LspError,
39     main_loop::{main_loop, show_message},
40 };
41
42 pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
43     let res = T::deserialize(&json)
44         .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
45     Ok(res)
46 }