aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/lib.rs
blob: 958c70fe5fac47f989a98cd29688999c7986cdb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Implementation of the LSP for rust-analyzer.
//!
//! This crate takes Rust-specific analysis results from ra_ide and
//! translates into LSP types.
//!
//! It also is the root of all state. `world` module defines the bulk of the
//! state, and `main_loop` module defines the rules for modifying it.
#![recursion_limit = "512"]

pub mod cli;

#[allow(unused)]
macro_rules! println {
    ($($tt:tt)*) => {
        compile_error!("stdout is locked, use eprintln")
    };
}

#[allow(unused)]
macro_rules! print {
    ($($tt:tt)*) => {
        compile_error!("stdout is locked, use eprint")
    };
}

mod vfs_glob;
mod caps;
mod cargo_target_spec;
mod conv;
mod main_loop;
mod markdown;
pub mod req;
mod config;
mod world;
mod diagnostics;

use serde::de::DeserializeOwned;

pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
pub use crate::{
    caps::server_capabilities,
    config::ServerConfig,
    main_loop::LspError,
    main_loop::{main_loop, show_message},
};

pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
    let res = T::deserialize(&json)
        .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
    Ok(res)
}