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-11-22 10:33:08 +03:00
|
|
|
|
2022-07-20 14:59:42 +02:00
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-09-01 18:16:08 +03:00
|
|
|
mod caps;
|
2019-01-12 13:00:58 -05:00
|
|
|
mod cargo_target_spec;
|
2020-01-31 19:23:25 +01:00
|
|
|
mod diagnostics;
|
2022-06-02 18:14:38 +02:00
|
|
|
mod diff;
|
|
|
|
mod dispatch;
|
|
|
|
mod from_proto;
|
|
|
|
mod global_state;
|
2021-02-13 01:28:48 +03:00
|
|
|
mod line_index;
|
2020-06-25 08:01:03 +02:00
|
|
|
mod lsp_utils;
|
2022-06-02 18:14:38 +02:00
|
|
|
mod main_loop;
|
|
|
|
mod markdown;
|
2021-07-26 20:16:47 +03:00
|
|
|
mod mem_docs;
|
2021-01-10 18:02:02 +03:00
|
|
|
mod op_queue;
|
2022-06-02 18:14:38 +02:00
|
|
|
mod reload;
|
|
|
|
mod semantic_tokens;
|
|
|
|
mod task_pool;
|
|
|
|
mod to_proto;
|
|
|
|
mod version;
|
|
|
|
|
2023-05-15 11:59:03 +02:00
|
|
|
mod handlers {
|
|
|
|
pub(crate) mod notification;
|
|
|
|
pub(crate) mod request;
|
|
|
|
}
|
|
|
|
|
2020-06-24 18:57:30 +02:00
|
|
|
pub mod config;
|
2022-06-02 18:14:38 +02:00
|
|
|
pub mod lsp_ext;
|
2018-09-01 18:16:08 +03:00
|
|
|
|
2021-03-30 11:59:00 +03:00
|
|
|
#[cfg(test)]
|
2021-05-04 14:02:23 +03:00
|
|
|
mod integrated_benchmarks;
|
2021-03-30 11:59:00 +03:00
|
|
|
|
2020-06-25 00:35:22 +02:00
|
|
|
use std::fmt;
|
2020-02-11 09:46:45 +01:00
|
|
|
|
2021-08-15 13:24:37 +03:00
|
|
|
use serde::de::DeserializeOwned;
|
|
|
|
|
2022-06-02 18:14:38 +02:00
|
|
|
pub use crate::{caps::server_capabilities, main_loop::main_loop, version::version};
|
2020-10-30 19:38:29 +01:00
|
|
|
|
|
|
|
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
|
|
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
|
|
|
|
2022-06-01 00:20:28 +02:00
|
|
|
pub fn from_json<T: DeserializeOwned>(what: &'static str, json: &serde_json::Value) -> Result<T> {
|
2021-08-15 13:24:37 +03:00
|
|
|
let res = serde_json::from_value(json.clone())
|
2022-12-23 13:42:58 -05:00
|
|
|
.map_err(|e| format!("Failed to deserialize {what}: {e}; {json}"))?;
|
2020-02-11 09:46:45 +01:00
|
|
|
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 {
|
2022-07-20 15:05:02 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2020-06-25 00:35:22 +02:00
|
|
|
write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for LspError {}
|