2019-11-22 01:33:08 -06:00
|
|
|
//! Implementation of the LSP for rust-analyzer.
|
|
|
|
//!
|
2020-08-13 10:42:52 -05:00
|
|
|
//! This crate takes Rust-specific analysis results from ide and translates
|
2020-02-18 05:11:32 -06:00
|
|
|
//! into LSP types.
|
2019-11-22 01:33:08 -06: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 05:11:32 -06:00
|
|
|
//!
|
|
|
|
//! The `cli` submodule implements some batch-processing analysis, primarily as
|
|
|
|
//! a debugging aid.
|
2019-06-26 01:12:46 -05:00
|
|
|
#![recursion_limit = "512"]
|
2019-11-22 01:33:08 -06:00
|
|
|
|
2020-02-17 12:03:03 -06:00
|
|
|
pub mod cli;
|
|
|
|
|
2019-11-22 01:33:08 -06:00
|
|
|
#[allow(unused)]
|
2020-04-06 09:58:16 -05:00
|
|
|
macro_rules! eprintln {
|
|
|
|
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
|
2019-11-22 01:33:08 -06:00
|
|
|
}
|
|
|
|
|
2020-06-24 11:57:30 -05:00
|
|
|
mod global_state;
|
2020-06-25 16:44:58 -05:00
|
|
|
mod reload;
|
2020-06-24 11:57:30 -05:00
|
|
|
mod main_loop;
|
2020-06-25 10:22:18 -05:00
|
|
|
mod dispatch;
|
2020-06-24 11:57:30 -05:00
|
|
|
mod handlers;
|
2018-09-01 10:16:08 -05:00
|
|
|
mod caps;
|
2019-01-12 12:00:58 -06:00
|
|
|
mod cargo_target_spec;
|
2020-05-10 06:55:24 -05:00
|
|
|
mod to_proto;
|
|
|
|
mod from_proto;
|
2020-06-24 11:57:30 -05:00
|
|
|
mod semantic_tokens;
|
2019-01-29 20:39:09 -06:00
|
|
|
mod markdown;
|
2020-01-31 12:23:25 -06:00
|
|
|
mod diagnostics;
|
2021-02-12 16:28:48 -06:00
|
|
|
mod line_index;
|
2020-06-25 01:01:03 -05:00
|
|
|
mod lsp_utils;
|
2020-06-25 08:35:42 -05:00
|
|
|
mod thread_pool;
|
2021-07-26 12:16:47 -05:00
|
|
|
mod mem_docs;
|
2020-12-31 06:05:19 -06:00
|
|
|
mod diff;
|
2021-01-10 09:02:02 -06:00
|
|
|
mod op_queue;
|
2020-06-24 11:57:30 -05:00
|
|
|
pub mod lsp_ext;
|
|
|
|
pub mod config;
|
2018-09-01 10:16:08 -05:00
|
|
|
|
2021-03-30 03:59:00 -05:00
|
|
|
#[cfg(test)]
|
2021-05-04 06:02:23 -05:00
|
|
|
mod integrated_benchmarks;
|
2021-03-30 03:59:00 -05:00
|
|
|
|
2020-06-24 17:35:22 -05:00
|
|
|
use std::fmt;
|
2020-02-11 02:46:45 -06:00
|
|
|
|
2021-08-15 05:24:37 -05:00
|
|
|
use serde::de::DeserializeOwned;
|
|
|
|
|
2020-10-30 13:38:29 -05:00
|
|
|
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>;
|
|
|
|
|
2020-02-11 02:46:45 -06:00
|
|
|
pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
|
2021-08-15 05:24:37 -05:00
|
|
|
let res = serde_json::from_value(json.clone())
|
2020-02-11 02:46:45 -06:00
|
|
|
.map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
|
|
|
|
Ok(res)
|
|
|
|
}
|
2020-06-24 17:35:22 -05: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 {}
|