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
12 #![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
17 macro_rules! eprintln {
18 ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
22 mod cargo_target_spec;
45 mod integrated_benchmarks;
49 use serde::de::DeserializeOwned;
51 pub use crate::{caps::server_capabilities, main_loop::main_loop, version::version};
53 pub type Error = Box<dyn std::error::Error + Send + Sync>;
54 pub type Result<T, E = Error> = std::result::Result<T, E>;
56 pub fn from_json<T: DeserializeOwned>(what: &'static str, json: &serde_json::Value) -> Result<T> {
57 let res = serde_json::from_value(json.clone())
58 .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
69 fn new(code: i32, message: String) -> LspError {
70 LspError { code, message }
74 impl fmt::Display for LspError {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
80 impl std::error::Error for LspError {}