1 //! Implementation of the LSP for rust-analyzer.
3 //! This crate takes Rust-specific analysis results from ra_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)*) };
24 mod cargo_target_spec;
35 use serde::de::DeserializeOwned;
37 pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>;
39 caps::server_capabilities,
40 main_loop::{main_loop, show_message},
44 pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
45 let res = T::deserialize(&json)
46 .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
57 fn new(code: i32, message: String) -> LspError {
58 LspError { code, message }
62 impl fmt::Display for LspError {
63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
68 impl std::error::Error for LspError {}