78 lines
1.7 KiB
Rust
Raw Normal View History

2019-11-22 10:33:08 +03:00
//! Implementation of the LSP for rust-analyzer.
//!
2020-08-13 17:42:52 +02:00
//! This crate takes Rust-specific analysis results from ide and translates
2020-02-18 12:11:32 +01:00
//! into LSP types.
2019-11-22 10:33:08 +03:00
//!
//! 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.
2020-02-18 12:11:32 +01:00
//!
//! The `cli` submodule implements some batch-processing analysis, primarily as
//! a debugging aid.
2019-06-26 09:12:46 +03:00
#![recursion_limit = "512"]
2019-11-22 10:33:08 +03:00
2020-02-17 19:03:03 +01:00
pub mod cli;
2019-11-22 10:33:08 +03:00
#[allow(unused)]
2020-04-06 16:58:16 +02:00
macro_rules! eprintln {
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
2019-11-22 10:33:08 +03:00
}
2020-06-24 18:57:30 +02:00
mod global_state;
mod reload;
2020-06-24 18:57:30 +02:00
mod main_loop;
mod dispatch;
2020-06-24 18:57:30 +02:00
mod handlers;
2018-09-01 18:16:08 +03:00
mod caps;
mod cargo_target_spec;
mod to_proto;
mod from_proto;
2020-06-24 18:57:30 +02:00
mod semantic_tokens;
mod markdown;
mod diagnostics;
2021-02-13 01:28:48 +03:00
mod line_index;
mod lsp_utils;
2020-06-25 15:35:42 +02:00
mod thread_pool;
mod mem_docs;
mod diff;
mod op_queue;
2020-06-24 18:57:30 +02:00
pub mod lsp_ext;
pub mod config;
2018-09-01 18:16:08 +03:00
#[cfg(test)]
mod integrated_benchmarks;
2020-06-25 00:35:22 +02:00
use std::fmt;
use serde::de::DeserializeOwned;
pub use crate::{caps::server_capabilities, main_loop::main_loop};
pub type Error = Box<dyn std::error::Error + Send + Sync>;
pub type Result<T, E = Error> = std::result::Result<T, E>;
pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
let res = serde_json::from_value(json.clone())
.map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
Ok(res)
}
2020-06-25 00:35:22 +02:00
#[derive(Debug)]
struct LspError {
code: i32,
message: String,
}
impl LspError {
fn new(code: i32, message: String) -> LspError {
LspError { code, message }
}
}
impl fmt::Display for LspError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
}
}
impl std::error::Error for LspError {}