1 //! Implementation of the LSP for rust-analyzer.
3 //! This crate takes Rust-specific analysis results from ide and translates
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.
9 //! The `cli` submodule implements some batch-processing analysis, primarily as
11 #![recursion_limit = "512"]
16 macro_rules! eprintln {
17 ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
26 mod cargo_target_spec;
42 mod integrated_benchmarks;
44 use serde::de::DeserializeOwned;
47 pub use crate::{caps::server_capabilities, main_loop::main_loop};
49 pub type Error = Box<dyn std::error::Error + Send + Sync>;
50 pub type Result<T, E = Error> = std::result::Result<T, E>;
52 pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
53 let res = serde_path_to_error::deserialize(&json)
54 .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
65 fn new(code: i32, message: String) -> LspError {
66 LspError { code, message }
70 impl fmt::Display for LspError {
71 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
72 write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
76 impl std::error::Error for LspError {}