]> git.lizzy.rs Git - rust.git/blobdiff - crates/rust-analyzer/src/lib.rs
Merge branch 'Veetaha-feat/sync-branch'
[rust.git] / crates / rust-analyzer / src / lib.rs
index 0dae30e46ec456367a9d702e9063f1e3e60eaa32..d6cd043031a1c6516daea94186c20eb28b08617f 100644 (file)
 pub mod cli;
 
 #[allow(unused)]
-macro_rules! println {
-    ($($tt:tt)*) => {
-        compile_error!("stdout is locked, use eprintln")
-    };
+macro_rules! eprintln {
+    ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
 }
 
-#[allow(unused)]
-macro_rules! print {
-    ($($tt:tt)*) => {
-        compile_error!("stdout is locked, use eprint")
-    };
-}
-
-mod vfs_glob;
+mod global_state;
+mod main_loop;
+mod handlers;
 mod caps;
 mod cargo_target_spec;
-mod conv;
-mod main_loop;
+mod to_proto;
+mod from_proto;
+mod semantic_tokens;
 mod markdown;
-pub mod req;
-mod config;
-mod world;
 mod diagnostics;
+mod line_endings;
+mod request_metrics;
+pub mod lsp_ext;
+pub mod config;
 
 use serde::de::DeserializeOwned;
 
-pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
+pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>;
 pub use crate::{
     caps::server_capabilities,
-    config::ServerConfig,
-    main_loop::LspError,
     main_loop::{main_loop, show_message},
 };
+use std::fmt;
 
 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)
 }
+
+#[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 {}