]> git.lizzy.rs Git - rust.git/commitdiff
Get rid of failure: ra_lsp_server & ra_project_model
authorMuhammad Mominul Huque <mominul2082@gmail.com>
Fri, 14 Jun 2019 20:42:56 +0000 (02:42 +0600)
committerMuhammad Mominul Huque <mominul2082@gmail.com>
Fri, 14 Jun 2019 20:42:56 +0000 (02:42 +0600)
Cargo.lock
crates/ra_lsp_server/Cargo.toml
crates/ra_lsp_server/src/lib.rs
crates/ra_lsp_server/src/main.rs
crates/ra_lsp_server/src/main_loop.rs
crates/ra_lsp_server/src/world.rs
crates/ra_project_model/Cargo.toml
crates/ra_project_model/src/cargo_workspace.rs
crates/ra_project_model/src/lib.rs
crates/ra_project_model/src/sysroot.rs

index 08690c8c3aa293309023f8a7cb7abae730543b30..990672a0ac3343c7ce49c1617483e5dfe9f335c7 100644 (file)
@@ -1128,8 +1128,6 @@ name = "ra_lsp_server"
 version = "0.1.0"
 dependencies = [
  "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "gen_lsp_server 0.2.0",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1187,7 +1185,6 @@ name = "ra_project_model"
 version = "0.1.0"
 dependencies = [
  "cargo_metadata 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_arena 0.1.0",
  "ra_db 0.1.0",
index d52e0165fb3c66f568b764ad784c4500ae3f3557..142467cc9039291f0d5254bd8447bf0fb780b55c 100644 (file)
@@ -7,8 +7,6 @@ authors = ["rust-analyzer developers"]
 [dependencies]
 threadpool = "1.7.1"
 relative-path = "0.4.0"
-failure = "0.1.4"
-failure_derive = "0.1.4"
 serde_json = "1.0.34"
 serde = { version = "1.0.83", features = ["derive"] }
 crossbeam-channel = "0.3.5"
index aabde420b45929e86162b8dc450cf96561aae800..14cfa401f5c18b3e3ce93ce48b33cc518198fd09 100644 (file)
@@ -9,5 +9,5 @@
 pub mod init;
 mod world;
 
-pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
+pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
 pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions};
index 3c3e8b5b0effe14bbb6aab309cb25360d9322e30..7749d97d6edbf8009cf08595fbadb9e37b6c08a0 100644 (file)
@@ -25,7 +25,7 @@ fn main() -> Result<()> {
         }
         Err(_) => {
             log::error!("server panicked");
-            failure::bail!("server panicked")
+            Err("server panicked")?
         }
     }
 }
index 0790ea472ec64be82f1d33bca4edf58af47b70ca..fe6b360d40a722965531b6005077c46f7ff1daf8 100644 (file)
@@ -2,11 +2,9 @@
 mod subscriptions;
 pub(crate) mod pending_requests;
 
-use std::{fmt, path::PathBuf, sync::Arc, time::Instant};
+use std::{fmt, path::PathBuf, sync::Arc, time::Instant, error::Error};
 
 use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender};
-use failure::{bail, format_err};
-use failure_derive::Fail;
 use gen_lsp_server::{
     handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
 };
@@ -32,8 +30,7 @@
 const THREADPOOL_SIZE: usize = 8;
 const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3;
 
-#[derive(Debug, Fail)]
-#[fail(display = "Language Server request failed with {}. ({})", code, message)]
+#[derive(Debug)]
 pub struct LspError {
     pub code: i32,
     pub message: String,
@@ -45,6 +42,14 @@ pub fn new(code: i32, message: String) -> LspError {
     }
 }
 
+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 Error for LspError {}
+
 pub fn main_loop(
     ws_roots: Vec<PathBuf>,
     options: InitializationOptions,
@@ -177,12 +182,12 @@ fn main_loop_inner(
         let event = select! {
             recv(msg_receiver) -> msg => match msg {
                 Ok(msg) => Event::Msg(msg),
-                Err(RecvError) => bail!("client exited without shutdown"),
+                Err(RecvError) => Err("client exited without shutdown")?,
             },
             recv(task_receiver) -> task => Event::Task(task.unwrap()),
             recv(state.vfs.read().task_receiver()) -> task => match task {
                 Ok(task) => Event::Vfs(task),
-                Err(RecvError) => bail!("vfs died"),
+                Err(RecvError) => Err("vfs died")?,
             },
             recv(libdata_receiver) -> data => Event::Lib(data.unwrap())
         };
@@ -380,7 +385,7 @@ fn on_notification(
     let not = match not.cast::<req::DidOpenTextDocument>() {
         Ok(params) => {
             let uri = params.text_document.uri;
-            let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
+            let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
             if let Some(file_id) =
                 state.vfs.write().add_file_overlay(&path, params.text_document.text)
             {
@@ -393,9 +398,9 @@ fn on_notification(
     let not = match not.cast::<req::DidChangeTextDocument>() {
         Ok(mut params) => {
             let uri = params.text_document.uri;
-            let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
+            let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
             let text =
-                params.content_changes.pop().ok_or_else(|| format_err!("empty changes"))?.text;
+                params.content_changes.pop().ok_or_else(|| format!("empty changes"))?.text;
             state.vfs.write().change_file_overlay(path.as_path(), text);
             return Ok(());
         }
@@ -404,7 +409,7 @@ fn on_notification(
     let not = match not.cast::<req::DidCloseTextDocument>() {
         Ok(params) => {
             let uri = params.text_document.uri;
-            let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
+            let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
             if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) {
                 subs.remove_sub(FileId(file_id.0));
             }
@@ -546,7 +551,7 @@ fn result_to_task<R>(id: u64, result: Result<R::Result>) -> Task
                     RawResponse::err(
                         id,
                         ErrorCode::InternalError as i32,
-                        format!("{}\n{}", e, e.backtrace()),
+                        e.to_string()
                     )
                 }
             }
@@ -599,6 +604,6 @@ fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Send
     sender.send(not.into()).unwrap();
 }
 
-fn is_canceled(e: &failure::Error) -> bool {
+fn is_canceled(e: &Box<dyn std::error::Error + Send + Sync>) -> bool {
     e.downcast_ref::<Canceled>().is_some()
 }
index f9ce570ca34320c7eade7a181ef16358a71f1396..7822e1c1c5c29dc6489fbcc7a4a1968ea91f1abd 100644 (file)
@@ -11,7 +11,6 @@
 use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
 use relative_path::RelativePathBuf;
 use parking_lot::RwLock;
-use failure::{Error, format_err};
 use gen_lsp_server::ErrorCode;
 
 use crate::{
@@ -169,13 +168,13 @@ pub fn analysis(&self) -> &Analysis {
     }
 
     pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
-        let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?;
+        let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
         let file = self.vfs.read().path2file(&path).ok_or_else(|| {
             // Show warning as this file is outside current workspace
-            Error::from(LspError {
+            LspError {
                 code: ErrorCode::InvalidRequest as i32,
                 message: "Rust file outside current workspace is not supported yet.".to_string(),
-            })
+            }
         })?;
         Ok(FileId(file.0))
     }
@@ -183,7 +182,7 @@ pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
     pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> {
         let path = self.vfs.read().file2path(VfsFile(id.0));
         let url = Url::from_file_path(&path)
-            .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
+            .map_err(|_| format!("can't convert path to url: {}", path.display()))?;
         Ok(url)
     }
 
@@ -191,7 +190,7 @@ pub fn path_to_uri(&self, root: SourceRootId, path: &RelativePathBuf) -> Result<
         let base = self.vfs.read().root2path(VfsRoot(root.0));
         let path = path.to_path(base);
         let url = Url::from_file_path(&path)
-            .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?;
+            .map_err(|_| format!("can't convert path to url: {}", path.display()))?;
         Ok(url)
     }
 
index cf4adf35cd5d3b631082f6d37dd62e55efea4c96..c1a91d9502b11edde389f2750a0d01f65ee4b80e 100644 (file)
@@ -9,8 +9,6 @@ log = "0.4.5"
 rustc-hash = "1.0"
 relative-path = "0.4.0"
 
-failure = "0.1.4"
-
 walkdir = "2.2.7"
 
 cargo_metadata = "0.7.0"
index 5a165778881491fad19c40c6f5ffdfc3a7dc35d9..d5ebf2c7a84a61db312000fe07b5d3e56af236a3 100644 (file)
@@ -3,7 +3,6 @@
 use cargo_metadata::{MetadataCommand, CargoOpt};
 use ra_arena::{Arena, RawId, impl_arena_id};
 use rustc_hash::FxHashMap;
-use failure::format_err;
 use ra_db::Edition;
 
 use crate::Result;
@@ -127,7 +126,7 @@ pub fn from_cargo_metadata(cargo_toml: &Path) -> Result<CargoWorkspace> {
         if let Some(parent) = cargo_toml.parent() {
             meta.current_dir(parent);
         }
-        let meta = meta.exec().map_err(|e| format_err!("cargo metadata failed: {}", e))?;
+        let meta = meta.exec().map_err(|e| format!("cargo metadata failed: {}", e))?;
         let mut pkg_by_id = FxHashMap::default();
         let mut packages = Arena::default();
         let mut targets = Arena::default();
index 4ae7f685c7184617837739f60d7960898f717714..a3af153f1aa02dd36451136f98a8af492d40f9d0 100644 (file)
@@ -6,9 +6,9 @@
     fs::File,
     io::BufReader,
     path::{Path, PathBuf},
+    error::Error
 };
 
-use failure::bail;
 use rustc_hash::FxHashMap;
 
 use ra_db::{CrateGraph, FileId, Edition};
@@ -24,7 +24,7 @@
 };
 
 // FIXME use proper error enum
-pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
+pub type Result<T> = ::std::result::Result<T, Box<dyn Error + Send + Sync>>;
 
 #[derive(Debug, Clone)]
 pub enum ProjectWorkspace {
@@ -298,5 +298,5 @@ fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
         }
         curr = path.parent();
     }
-    bail!("can't find Cargo.toml at {}", path.display())
+    Err(format!("can't find Cargo.toml at {}", path.display()))?
 }
index 8b87aa7bdafd755f410c7b9f54740f7cd698a40e..d6eb824a3449a0d3986f306595478cab5af76ef2 100644 (file)
@@ -38,18 +38,18 @@ pub fn discover(cargo_toml: &Path) -> Result<Sysroot> {
             .args(&["--print", "sysroot"])
             .output()?;
         if !rustc_output.status.success() {
-            failure::bail!("failed to locate sysroot")
+            Err("failed to locate sysroot")?
         }
         let stdout = String::from_utf8(rustc_output.stdout)?;
         let sysroot_path = Path::new(stdout.trim());
         let src = sysroot_path.join("lib/rustlib/src/rust/src");
         if !src.exists() {
-            failure::bail!(
+            Err(format!(
                 "can't load standard library from sysroot\n\
                  {:?}\n\
                  try running `rustup component add rust-src`",
                 src,
-            );
+            ))?;
         }
 
         let mut sysroot = Sysroot { crates: Arena::default() };