diff options
author | Muhammad Mominul Huque <[email protected]> | 2019-06-14 21:42:56 +0100 |
---|---|---|
committer | Muhammad Mominul Huque <[email protected]> | 2019-06-14 21:42:56 +0100 |
commit | 9709bd39ca8a564d517372ee33304d34ac0b09bf (patch) | |
tree | 4d12b93f2aab3a85898099c2308d364501946dbb /crates | |
parent | a931fb1ef633473e272bb3f9ba86968dd90f44a7 (diff) |
Get rid of failure: ra_lsp_server & ra_project_model
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 31 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 11 | ||||
-rw-r--r-- | crates/ra_project_model/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_project_model/src/cargo_workspace.rs | 3 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 6 |
9 files changed, 32 insertions, 33 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index d52e0165f..142467cc9 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -7,8 +7,6 @@ authors = ["rust-analyzer developers"] | |||
7 | [dependencies] | 7 | [dependencies] |
8 | threadpool = "1.7.1" | 8 | threadpool = "1.7.1" |
9 | relative-path = "0.4.0" | 9 | relative-path = "0.4.0" |
10 | failure = "0.1.4" | ||
11 | failure_derive = "0.1.4" | ||
12 | serde_json = "1.0.34" | 10 | serde_json = "1.0.34" |
13 | serde = { version = "1.0.83", features = ["derive"] } | 11 | serde = { version = "1.0.83", features = ["derive"] } |
14 | crossbeam-channel = "0.3.5" | 12 | crossbeam-channel = "0.3.5" |
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index aabde420b..14cfa401f 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -9,5 +9,5 @@ pub mod req; | |||
9 | pub mod init; | 9 | pub mod init; |
10 | mod world; | 10 | mod world; |
11 | 11 | ||
12 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; | 12 | pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; |
13 | pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions}; | 13 | pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions}; |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 3c3e8b5b0..7749d97d6 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -25,7 +25,7 @@ fn main() -> Result<()> { | |||
25 | } | 25 | } |
26 | Err(_) => { | 26 | Err(_) => { |
27 | log::error!("server panicked"); | 27 | log::error!("server panicked"); |
28 | failure::bail!("server panicked") | 28 | Err("server panicked")? |
29 | } | 29 | } |
30 | } | 30 | } |
31 | } | 31 | } |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 0790ea472..fe6b360d4 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -2,11 +2,9 @@ mod handlers; | |||
2 | mod subscriptions; | 2 | mod subscriptions; |
3 | pub(crate) mod pending_requests; | 3 | pub(crate) mod pending_requests; |
4 | 4 | ||
5 | use std::{fmt, path::PathBuf, sync::Arc, time::Instant}; | 5 | use std::{fmt, path::PathBuf, sync::Arc, time::Instant, error::Error}; |
6 | 6 | ||
7 | use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; | 7 | use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; |
8 | use failure::{bail, format_err}; | ||
9 | use failure_derive::Fail; | ||
10 | use gen_lsp_server::{ | 8 | use gen_lsp_server::{ |
11 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, | 9 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, |
12 | }; | 10 | }; |
@@ -32,8 +30,7 @@ use crate::{ | |||
32 | const THREADPOOL_SIZE: usize = 8; | 30 | const THREADPOOL_SIZE: usize = 8; |
33 | const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3; | 31 | const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3; |
34 | 32 | ||
35 | #[derive(Debug, Fail)] | 33 | #[derive(Debug)] |
36 | #[fail(display = "Language Server request failed with {}. ({})", code, message)] | ||
37 | pub struct LspError { | 34 | pub struct LspError { |
38 | pub code: i32, | 35 | pub code: i32, |
39 | pub message: String, | 36 | pub message: String, |
@@ -45,6 +42,14 @@ impl LspError { | |||
45 | } | 42 | } |
46 | } | 43 | } |
47 | 44 | ||
45 | impl fmt::Display for LspError { | ||
46 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
47 | write!(f, "Language Server request failed with {}. ({})", self.code, self.message) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | impl Error for LspError {} | ||
52 | |||
48 | pub fn main_loop( | 53 | pub fn main_loop( |
49 | ws_roots: Vec<PathBuf>, | 54 | ws_roots: Vec<PathBuf>, |
50 | options: InitializationOptions, | 55 | options: InitializationOptions, |
@@ -177,12 +182,12 @@ fn main_loop_inner( | |||
177 | let event = select! { | 182 | let event = select! { |
178 | recv(msg_receiver) -> msg => match msg { | 183 | recv(msg_receiver) -> msg => match msg { |
179 | Ok(msg) => Event::Msg(msg), | 184 | Ok(msg) => Event::Msg(msg), |
180 | Err(RecvError) => bail!("client exited without shutdown"), | 185 | Err(RecvError) => Err("client exited without shutdown")?, |
181 | }, | 186 | }, |
182 | recv(task_receiver) -> task => Event::Task(task.unwrap()), | 187 | recv(task_receiver) -> task => Event::Task(task.unwrap()), |
183 | recv(state.vfs.read().task_receiver()) -> task => match task { | 188 | recv(state.vfs.read().task_receiver()) -> task => match task { |
184 | Ok(task) => Event::Vfs(task), | 189 | Ok(task) => Event::Vfs(task), |
185 | Err(RecvError) => bail!("vfs died"), | 190 | Err(RecvError) => Err("vfs died")?, |
186 | }, | 191 | }, |
187 | recv(libdata_receiver) -> data => Event::Lib(data.unwrap()) | 192 | recv(libdata_receiver) -> data => Event::Lib(data.unwrap()) |
188 | }; | 193 | }; |
@@ -380,7 +385,7 @@ fn on_notification( | |||
380 | let not = match not.cast::<req::DidOpenTextDocument>() { | 385 | let not = match not.cast::<req::DidOpenTextDocument>() { |
381 | Ok(params) => { | 386 | Ok(params) => { |
382 | let uri = params.text_document.uri; | 387 | let uri = params.text_document.uri; |
383 | let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; | 388 | let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; |
384 | if let Some(file_id) = | 389 | if let Some(file_id) = |
385 | state.vfs.write().add_file_overlay(&path, params.text_document.text) | 390 | state.vfs.write().add_file_overlay(&path, params.text_document.text) |
386 | { | 391 | { |
@@ -393,9 +398,9 @@ fn on_notification( | |||
393 | let not = match not.cast::<req::DidChangeTextDocument>() { | 398 | let not = match not.cast::<req::DidChangeTextDocument>() { |
394 | Ok(mut params) => { | 399 | Ok(mut params) => { |
395 | let uri = params.text_document.uri; | 400 | let uri = params.text_document.uri; |
396 | let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; | 401 | let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; |
397 | let text = | 402 | let text = |
398 | params.content_changes.pop().ok_or_else(|| format_err!("empty changes"))?.text; | 403 | params.content_changes.pop().ok_or_else(|| format!("empty changes"))?.text; |
399 | state.vfs.write().change_file_overlay(path.as_path(), text); | 404 | state.vfs.write().change_file_overlay(path.as_path(), text); |
400 | return Ok(()); | 405 | return Ok(()); |
401 | } | 406 | } |
@@ -404,7 +409,7 @@ fn on_notification( | |||
404 | let not = match not.cast::<req::DidCloseTextDocument>() { | 409 | let not = match not.cast::<req::DidCloseTextDocument>() { |
405 | Ok(params) => { | 410 | Ok(params) => { |
406 | let uri = params.text_document.uri; | 411 | let uri = params.text_document.uri; |
407 | let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; | 412 | let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; |
408 | if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) { | 413 | if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) { |
409 | subs.remove_sub(FileId(file_id.0)); | 414 | subs.remove_sub(FileId(file_id.0)); |
410 | } | 415 | } |
@@ -546,7 +551,7 @@ where | |||
546 | RawResponse::err( | 551 | RawResponse::err( |
547 | id, | 552 | id, |
548 | ErrorCode::InternalError as i32, | 553 | ErrorCode::InternalError as i32, |
549 | format!("{}\n{}", e, e.backtrace()), | 554 | e.to_string() |
550 | ) | 555 | ) |
551 | } | 556 | } |
552 | } | 557 | } |
@@ -599,6 +604,6 @@ fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Send | |||
599 | sender.send(not.into()).unwrap(); | 604 | sender.send(not.into()).unwrap(); |
600 | } | 605 | } |
601 | 606 | ||
602 | fn is_canceled(e: &failure::Error) -> bool { | 607 | fn is_canceled(e: &Box<dyn std::error::Error + Send + Sync>) -> bool { |
603 | e.downcast_ref::<Canceled>().is_some() | 608 | e.downcast_ref::<Canceled>().is_some() |
604 | } | 609 | } |
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index f9ce570ca..7822e1c1c 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -11,7 +11,6 @@ use ra_ide_api::{ | |||
11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; | 11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; |
12 | use relative_path::RelativePathBuf; | 12 | use relative_path::RelativePathBuf; |
13 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
14 | use failure::{Error, format_err}; | ||
15 | use gen_lsp_server::ErrorCode; | 14 | use gen_lsp_server::ErrorCode; |
16 | 15 | ||
17 | use crate::{ | 16 | use crate::{ |
@@ -169,13 +168,13 @@ impl WorldSnapshot { | |||
169 | } | 168 | } |
170 | 169 | ||
171 | pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> { | 170 | pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> { |
172 | let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; | 171 | let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; |
173 | let file = self.vfs.read().path2file(&path).ok_or_else(|| { | 172 | let file = self.vfs.read().path2file(&path).ok_or_else(|| { |
174 | // Show warning as this file is outside current workspace | 173 | // Show warning as this file is outside current workspace |
175 | Error::from(LspError { | 174 | LspError { |
176 | code: ErrorCode::InvalidRequest as i32, | 175 | code: ErrorCode::InvalidRequest as i32, |
177 | message: "Rust file outside current workspace is not supported yet.".to_string(), | 176 | message: "Rust file outside current workspace is not supported yet.".to_string(), |
178 | }) | 177 | } |
179 | })?; | 178 | })?; |
180 | Ok(FileId(file.0)) | 179 | Ok(FileId(file.0)) |
181 | } | 180 | } |
@@ -183,7 +182,7 @@ impl WorldSnapshot { | |||
183 | pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> { | 182 | pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> { |
184 | let path = self.vfs.read().file2path(VfsFile(id.0)); | 183 | let path = self.vfs.read().file2path(VfsFile(id.0)); |
185 | let url = Url::from_file_path(&path) | 184 | let url = Url::from_file_path(&path) |
186 | .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; | 185 | .map_err(|_| format!("can't convert path to url: {}", path.display()))?; |
187 | Ok(url) | 186 | Ok(url) |
188 | } | 187 | } |
189 | 188 | ||
@@ -191,7 +190,7 @@ impl WorldSnapshot { | |||
191 | let base = self.vfs.read().root2path(VfsRoot(root.0)); | 190 | let base = self.vfs.read().root2path(VfsRoot(root.0)); |
192 | let path = path.to_path(base); | 191 | let path = path.to_path(base); |
193 | let url = Url::from_file_path(&path) | 192 | let url = Url::from_file_path(&path) |
194 | .map_err(|_| format_err!("can't convert path to url: {}", path.display()))?; | 193 | .map_err(|_| format!("can't convert path to url: {}", path.display()))?; |
195 | Ok(url) | 194 | Ok(url) |
196 | } | 195 | } |
197 | 196 | ||
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml index cf4adf35c..c1a91d950 100644 --- a/crates/ra_project_model/Cargo.toml +++ b/crates/ra_project_model/Cargo.toml | |||
@@ -9,8 +9,6 @@ log = "0.4.5" | |||
9 | rustc-hash = "1.0" | 9 | rustc-hash = "1.0" |
10 | relative-path = "0.4.0" | 10 | relative-path = "0.4.0" |
11 | 11 | ||
12 | failure = "0.1.4" | ||
13 | |||
14 | walkdir = "2.2.7" | 12 | walkdir = "2.2.7" |
15 | 13 | ||
16 | cargo_metadata = "0.7.0" | 14 | cargo_metadata = "0.7.0" |
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 5a1657788..d5ebf2c7a 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -3,7 +3,6 @@ use std::path::{Path, PathBuf}; | |||
3 | use cargo_metadata::{MetadataCommand, CargoOpt}; | 3 | use cargo_metadata::{MetadataCommand, CargoOpt}; |
4 | use ra_arena::{Arena, RawId, impl_arena_id}; | 4 | use ra_arena::{Arena, RawId, impl_arena_id}; |
5 | use rustc_hash::FxHashMap; | 5 | use rustc_hash::FxHashMap; |
6 | use failure::format_err; | ||
7 | use ra_db::Edition; | 6 | use ra_db::Edition; |
8 | 7 | ||
9 | use crate::Result; | 8 | use crate::Result; |
@@ -127,7 +126,7 @@ impl CargoWorkspace { | |||
127 | if let Some(parent) = cargo_toml.parent() { | 126 | if let Some(parent) = cargo_toml.parent() { |
128 | meta.current_dir(parent); | 127 | meta.current_dir(parent); |
129 | } | 128 | } |
130 | let meta = meta.exec().map_err(|e| format_err!("cargo metadata failed: {}", e))?; | 129 | let meta = meta.exec().map_err(|e| format!("cargo metadata failed: {}", e))?; |
131 | let mut pkg_by_id = FxHashMap::default(); | 130 | let mut pkg_by_id = FxHashMap::default(); |
132 | let mut packages = Arena::default(); | 131 | let mut packages = Arena::default(); |
133 | let mut targets = Arena::default(); | 132 | let mut targets = Arena::default(); |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 4ae7f685c..a3af153f1 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -6,9 +6,9 @@ use std::{ | |||
6 | fs::File, | 6 | fs::File, |
7 | io::BufReader, | 7 | io::BufReader, |
8 | path::{Path, PathBuf}, | 8 | path::{Path, PathBuf}, |
9 | error::Error | ||
9 | }; | 10 | }; |
10 | 11 | ||
11 | use failure::bail; | ||
12 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
13 | 13 | ||
14 | use ra_db::{CrateGraph, FileId, Edition}; | 14 | use ra_db::{CrateGraph, FileId, Edition}; |
@@ -24,7 +24,7 @@ pub use crate::{ | |||
24 | }; | 24 | }; |
25 | 25 | ||
26 | // FIXME use proper error enum | 26 | // FIXME use proper error enum |
27 | pub type Result<T> = ::std::result::Result<T, ::failure::Error>; | 27 | pub type Result<T> = ::std::result::Result<T, Box<dyn Error + Send + Sync>>; |
28 | 28 | ||
29 | #[derive(Debug, Clone)] | 29 | #[derive(Debug, Clone)] |
30 | pub enum ProjectWorkspace { | 30 | pub enum ProjectWorkspace { |
@@ -298,5 +298,5 @@ fn find_cargo_toml(path: &Path) -> Result<PathBuf> { | |||
298 | } | 298 | } |
299 | curr = path.parent(); | 299 | curr = path.parent(); |
300 | } | 300 | } |
301 | bail!("can't find Cargo.toml at {}", path.display()) | 301 | Err(format!("can't find Cargo.toml at {}", path.display()))? |
302 | } | 302 | } |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 8b87aa7bd..d6eb824a3 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -38,18 +38,18 @@ impl Sysroot { | |||
38 | .args(&["--print", "sysroot"]) | 38 | .args(&["--print", "sysroot"]) |
39 | .output()?; | 39 | .output()?; |
40 | if !rustc_output.status.success() { | 40 | if !rustc_output.status.success() { |
41 | failure::bail!("failed to locate sysroot") | 41 | Err("failed to locate sysroot")? |
42 | } | 42 | } |
43 | let stdout = String::from_utf8(rustc_output.stdout)?; | 43 | let stdout = String::from_utf8(rustc_output.stdout)?; |
44 | let sysroot_path = Path::new(stdout.trim()); | 44 | let sysroot_path = Path::new(stdout.trim()); |
45 | let src = sysroot_path.join("lib/rustlib/src/rust/src"); | 45 | let src = sysroot_path.join("lib/rustlib/src/rust/src"); |
46 | if !src.exists() { | 46 | if !src.exists() { |
47 | failure::bail!( | 47 | Err(format!( |
48 | "can't load standard library from sysroot\n\ | 48 | "can't load standard library from sysroot\n\ |
49 | {:?}\n\ | 49 | {:?}\n\ |
50 | try running `rustup component add rust-src`", | 50 | try running `rustup component add rust-src`", |
51 | src, | 51 | src, |
52 | ); | 52 | ))?; |
53 | } | 53 | } |
54 | 54 | ||
55 | let mut sysroot = Sysroot { crates: Arena::default() }; | 55 | let mut sysroot = Sysroot { crates: Arena::default() }; |