aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock6
-rw-r--r--crates/gen_lsp_server/Cargo.toml1
-rw-r--r--crates/gen_lsp_server/examples/01_gen_lsp_server.rs6
-rw-r--r--crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs6
-rw-r--r--crates/gen_lsp_server/src/lib.rs22
-rw-r--r--crates/gen_lsp_server/src/msg.rs8
-rw-r--r--crates/gen_lsp_server/src/stdio.rs5
-rw-r--r--crates/ra_batch/Cargo.toml2
-rw-r--r--crates/ra_batch/src/lib.rs6
-rw-r--r--crates/ra_cli/Cargo.toml1
-rw-r--r--crates/ra_cli/src/main.rs4
-rw-r--r--crates/ra_lsp_server/Cargo.toml2
-rw-r--r--crates/ra_lsp_server/src/lib.rs2
-rw-r--r--crates/ra_lsp_server/src/main.rs2
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs36
-rw-r--r--crates/ra_lsp_server/src/world.rs11
-rw-r--r--crates/ra_project_model/Cargo.toml2
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs3
-rw-r--r--crates/ra_project_model/src/lib.rs6
-rw-r--r--crates/ra_project_model/src/sysroot.rs6
-rw-r--r--crates/ra_syntax/src/lib.rs2
21 files changed, 61 insertions, 78 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2c1c7099e..03b5794fa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -490,7 +490,6 @@ name = "gen_lsp_server"
490version = "0.2.0" 490version = "0.2.0"
491dependencies = [ 491dependencies = [
492 "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 492 "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
493 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
494 "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)", 493 "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
495 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 494 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
496 "lsp-types 0.57.2 (registry+https://github.com/rust-lang/crates.io-index)", 495 "lsp-types 0.57.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1021,7 +1020,6 @@ dependencies = [
1021name = "ra_batch" 1020name = "ra_batch"
1022version = "0.1.0" 1021version = "0.1.0"
1023dependencies = [ 1022dependencies = [
1024 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1025 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 1023 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
1026 "ra_db 0.1.0", 1024 "ra_db 0.1.0",
1027 "ra_hir 0.1.0", 1025 "ra_hir 0.1.0",
@@ -1037,7 +1035,6 @@ name = "ra_cli"
1037version = "0.1.0" 1035version = "0.1.0"
1038dependencies = [ 1036dependencies = [
1039 "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", 1037 "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
1040 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1041 "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)", 1038 "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
1042 "indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 1039 "indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
1043 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 1040 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1129,8 +1126,6 @@ name = "ra_lsp_server"
1129version = "0.1.0" 1126version = "0.1.0"
1130dependencies = [ 1127dependencies = [
1131 "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 1128 "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
1132 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1133 "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1134 "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)", 1129 "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
1135 "gen_lsp_server 0.2.0", 1130 "gen_lsp_server 0.2.0",
1136 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 1131 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1188,7 +1183,6 @@ name = "ra_project_model"
1188version = "0.1.0" 1183version = "0.1.0"
1189dependencies = [ 1184dependencies = [
1190 "cargo_metadata 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", 1185 "cargo_metadata 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
1191 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
1192 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 1186 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
1193 "ra_arena 0.1.0", 1187 "ra_arena 0.1.0",
1194 "ra_db 0.1.0", 1188 "ra_db 0.1.0",
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml
index fa2fefea5..d375606d0 100644
--- a/crates/gen_lsp_server/Cargo.toml
+++ b/crates/gen_lsp_server/Cargo.toml
@@ -10,7 +10,6 @@ description = "Generic LSP server scaffold."
10[dependencies] 10[dependencies]
11lsp-types = "0.57.0" 11lsp-types = "0.57.0"
12log = "0.4.3" 12log = "0.4.3"
13failure = "0.1.4"
14serde_json = "1.0.34" 13serde_json = "1.0.34"
15serde = { version = "1.0.83", features = ["derive"] } 14serde = { version = "1.0.83", features = ["derive"] }
16crossbeam-channel = "0.3.5" 15crossbeam-channel = "0.3.5"
diff --git a/crates/gen_lsp_server/examples/01_gen_lsp_server.rs b/crates/gen_lsp_server/examples/01_gen_lsp_server.rs
index 60c581075..bc497f74a 100644
--- a/crates/gen_lsp_server/examples/01_gen_lsp_server.rs
+++ b/crates/gen_lsp_server/examples/01_gen_lsp_server.rs
@@ -1,3 +1,5 @@
1use std::error::Error;
2
1use crossbeam_channel::{Sender, Receiver}; 3use crossbeam_channel::{Sender, Receiver};
2use lsp_types::{ 4use lsp_types::{
3 ServerCapabilities, InitializeParams, 5 ServerCapabilities, InitializeParams,
@@ -5,7 +7,7 @@ use lsp_types::{
5}; 7};
6use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse}; 8use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse};
7 9
8fn main() -> Result<(), failure::Error> { 10fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
9 let (receiver, sender, io_threads) = stdio_transport(); 11 let (receiver, sender, io_threads) = stdio_transport();
10 run_server(ServerCapabilities::default(), receiver, sender, main_loop)?; 12 run_server(ServerCapabilities::default(), receiver, sender, main_loop)?;
11 io_threads.join()?; 13 io_threads.join()?;
@@ -16,7 +18,7 @@ fn main_loop(
16 _params: InitializeParams, 18 _params: InitializeParams,
17 receiver: &Receiver<RawMessage>, 19 receiver: &Receiver<RawMessage>,
18 sender: &Sender<RawMessage>, 20 sender: &Sender<RawMessage>,
19) -> Result<(), failure::Error> { 21) -> Result<(), Box<dyn Error + Sync + Send>> {
20 for msg in receiver { 22 for msg in receiver {
21 match msg { 23 match msg {
22 RawMessage::Request(req) => { 24 RawMessage::Request(req) => {
diff --git a/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs b/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs
index 27e4f1cbc..1a6174462 100644
--- a/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs
+++ b/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs
@@ -42,6 +42,8 @@
42//! {"jsonrpc": "2.0", "method": "exit", "params": null} 42//! {"jsonrpc": "2.0", "method": "exit", "params": null}
43//! ``` 43//! ```
44 44
45use std::error::Error;
46
45use crossbeam_channel::{Sender, Receiver}; 47use crossbeam_channel::{Sender, Receiver};
46use lsp_types::{ 48use lsp_types::{
47 ServerCapabilities, InitializeParams, 49 ServerCapabilities, InitializeParams,
@@ -52,7 +54,7 @@ use gen_lsp_server::{
52 run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse, RawRequest, 54 run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse, RawRequest,
53}; 55};
54 56
55fn main() -> Result<(), failure::Error> { 57fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
56 // Set up logging. Because `stdio_transport` gets a lock on stdout and stdin, we must have 58 // Set up logging. Because `stdio_transport` gets a lock on stdout and stdin, we must have
57 // our logging only write out to stderr. 59 // our logging only write out to stderr.
58 flexi_logger::Logger::with_str("info").start().unwrap(); 60 flexi_logger::Logger::with_str("info").start().unwrap();
@@ -75,7 +77,7 @@ fn main_loop(
75 _params: InitializeParams, 77 _params: InitializeParams,
76 receiver: &Receiver<RawMessage>, 78 receiver: &Receiver<RawMessage>,
77 sender: &Sender<RawMessage>, 79 sender: &Sender<RawMessage>,
78) -> Result<(), failure::Error> { 80) -> Result<(), Box<dyn Error + Sync + Send>> {
79 info!("starting example main loop"); 81 info!("starting example main loop");
80 for msg in receiver { 82 for msg in receiver {
81 info!("got msg: {:?}", msg); 83 info!("got msg: {:?}", msg);
diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs
index 1cd5a3a7c..7ecef83cb 100644
--- a/crates/gen_lsp_server/src/lib.rs
+++ b/crates/gen_lsp_server/src/lib.rs
@@ -5,11 +5,12 @@
5//! Run with `RUST_LOG=gen_lsp_server=debug` to see all the messages. 5//! Run with `RUST_LOG=gen_lsp_server=debug` to see all the messages.
6//! 6//!
7//! ```no_run 7//! ```no_run
8//! use std::error::Error;
8//! use crossbeam_channel::{Sender, Receiver}; 9//! use crossbeam_channel::{Sender, Receiver};
9//! use lsp_types::{ServerCapabilities, InitializeParams, request::{GotoDefinition, GotoDefinitionResponse}}; 10//! use lsp_types::{ServerCapabilities, InitializeParams, request::{GotoDefinition, GotoDefinitionResponse}};
10//! use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse}; 11//! use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse};
11//! 12//!
12//! fn main() -> Result<(), failure::Error> { 13//! fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
13//! let (receiver, sender, io_threads) = stdio_transport(); 14//! let (receiver, sender, io_threads) = stdio_transport();
14//! run_server( 15//! run_server(
15//! ServerCapabilities::default(), 16//! ServerCapabilities::default(),
@@ -25,7 +26,7 @@
25//! _params: InitializeParams, 26//! _params: InitializeParams,
26//! receiver: &Receiver<RawMessage>, 27//! receiver: &Receiver<RawMessage>,
27//! sender: &Sender<RawMessage>, 28//! sender: &Sender<RawMessage>,
28//! ) -> Result<(), failure::Error> { 29//! ) -> Result<(), Box<dyn Error + Send + Sync>> {
29//! for msg in receiver { 30//! for msg in receiver {
30//! match msg { 31//! match msg {
31//! RawMessage::Request(req) => { 32//! RawMessage::Request(req) => {
@@ -54,7 +55,7 @@
54//! } 55//! }
55//! ``` 56//! ```
56 57
57use failure::{bail, format_err}; 58use std::error::Error;
58 59
59mod msg; 60mod msg;
60mod stdio; 61mod stdio;
@@ -66,7 +67,7 @@ use lsp_types::{
66 InitializeParams, InitializeResult, ServerCapabilities, 67 InitializeParams, InitializeResult, ServerCapabilities,
67}; 68};
68 69
69pub type Result<T> = ::std::result::Result<T, failure::Error>; 70pub type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
70pub use crate::{ 71pub use crate::{
71 msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError}, 72 msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError},
72 stdio::{stdio_transport, Threads}, 73 stdio::{stdio_transport, Threads},
@@ -92,8 +93,8 @@ pub fn run_server(
92 match receiver.recv() { 93 match receiver.recv() {
93 Ok(RawMessage::Notification(n)) => n 94 Ok(RawMessage::Notification(n)) => n
94 .cast::<Exit>() 95 .cast::<Exit>()
95 .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, 96 .map_err(|n| format!("unexpected notification during shutdown: {:?}", n))?,
96 m => bail!("unexpected message during shutdown: {:?}", m), 97 m => Err(format!("unexpected message during shutdown: {:?}", m))?,
97 } 98 }
98 log::info!("lsp server shutdown complete"); 99 log::info!("lsp server shutdown complete");
99 Ok(()) 100 Ok(())
@@ -118,19 +119,18 @@ fn initialize(
118) -> Result<InitializeParams> { 119) -> Result<InitializeParams> {
119 let (id, params) = match receiver.recv() { 120 let (id, params) = match receiver.recv() {
120 Ok(RawMessage::Request(req)) => match req.cast::<Initialize>() { 121 Ok(RawMessage::Request(req)) => match req.cast::<Initialize>() {
121 Err(req) => bail!("expected initialize request, got {:?}", req), 122 Err(req) => Err(format!("expected initialize request, got {:?}", req))?,
122 Ok(req) => req, 123 Ok(req) => req,
123 }, 124 },
124 msg => bail!("expected initialize request, got {:?}", msg), 125 msg => Err(format!("expected initialize request, got {:?}", msg))?,
125 }; 126 };
126 let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps }); 127 let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps });
127 sender.send(RawMessage::Response(resp)).unwrap(); 128 sender.send(RawMessage::Response(resp)).unwrap();
128 match receiver.recv() { 129 match receiver.recv() {
129 Ok(RawMessage::Notification(n)) => { 130 Ok(RawMessage::Notification(n)) => {
130 n.cast::<Initialized>() 131 n.cast::<Initialized>().map_err(|_| "expected initialized notification")?;
131 .map_err(|_| format_err!("expected initialized notification"))?;
132 } 132 }
133 _ => bail!("expected initialized notification"), 133 _ => Err(format!("expected initialized notification"))?,
134 } 134 }
135 Ok(params) 135 Ok(params)
136} 136}
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs
index 1d39ba4bc..2928e4f8b 100644
--- a/crates/gen_lsp_server/src/msg.rs
+++ b/crates/gen_lsp_server/src/msg.rs
@@ -3,7 +3,6 @@ use std::io::{BufRead, Write};
3use lsp_types::{notification::Notification, request::Request}; 3use lsp_types::{notification::Notification, request::Request};
4use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
5use serde_json::{from_str, from_value, to_string, to_value, Value}; 5use serde_json::{from_str, from_value, to_string, to_value, Value};
6use failure::{bail, format_err};
7 6
8use crate::Result; 7use crate::Result;
9 8
@@ -175,7 +174,7 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> {
175 return Ok(None); 174 return Ok(None);
176 } 175 }
177 if !buf.ends_with("\r\n") { 176 if !buf.ends_with("\r\n") {
178 bail!("malformed header: {:?}", buf); 177 Err(format!("malformed header: {:?}", buf))?;
179 } 178 }
180 let buf = &buf[..buf.len() - 2]; 179 let buf = &buf[..buf.len() - 2];
181 if buf.is_empty() { 180 if buf.is_empty() {
@@ -183,13 +182,12 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> {
183 } 182 }
184 let mut parts = buf.splitn(2, ": "); 183 let mut parts = buf.splitn(2, ": ");
185 let header_name = parts.next().unwrap(); 184 let header_name = parts.next().unwrap();
186 let header_value = 185 let header_value = parts.next().ok_or_else(|| format!("malformed header: {:?}", buf))?;
187 parts.next().ok_or_else(|| format_err!("malformed header: {:?}", buf))?;
188 if header_name == "Content-Length" { 186 if header_name == "Content-Length" {
189 size = Some(header_value.parse::<usize>()?); 187 size = Some(header_value.parse::<usize>()?);
190 } 188 }
191 } 189 }
192 let size = size.ok_or_else(|| format_err!("no Content-Length"))?; 190 let size = size.ok_or("no Content-Length")?;
193 let mut buf = buf.into_bytes(); 191 let mut buf = buf.into_bytes();
194 buf.resize(size, 0); 192 buf.resize(size, 0);
195 inp.read_exact(&mut buf)?; 193 inp.read_exact(&mut buf)?;
diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs
index 2d6418400..f8931f2dc 100644
--- a/crates/gen_lsp_server/src/stdio.rs
+++ b/crates/gen_lsp_server/src/stdio.rs
@@ -4,7 +4,6 @@ use std::{
4}; 4};
5 5
6use crossbeam_channel::{bounded, Receiver, Sender}; 6use crossbeam_channel::{bounded, Receiver, Sender};
7use failure::bail;
8use lsp_types::notification::Exit; 7use lsp_types::notification::Exit;
9 8
10use crate::{RawMessage, Result}; 9use crate::{RawMessage, Result};
@@ -48,11 +47,11 @@ impl Threads {
48 pub fn join(self) -> Result<()> { 47 pub fn join(self) -> Result<()> {
49 match self.reader.join() { 48 match self.reader.join() {
50 Ok(r) => r?, 49 Ok(r) => r?,
51 Err(_) => bail!("reader panicked"), 50 Err(_) => Err("reader panicked")?,
52 } 51 }
53 match self.writer.join() { 52 match self.writer.join() {
54 Ok(r) => r, 53 Ok(r) => r,
55 Err(_) => bail!("writer panicked"), 54 Err(_) => Err("writer panicked")?,
56 } 55 }
57 } 56 }
58} 57}
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml
index 3037e27c4..8bf085bbf 100644
--- a/crates/ra_batch/Cargo.toml
+++ b/crates/ra_batch/Cargo.toml
@@ -8,8 +8,6 @@ authors = ["rust-analyzer developers"]
8log = "0.4.5" 8log = "0.4.5"
9rustc-hash = "1.0" 9rustc-hash = "1.0"
10 10
11failure = "0.1.4"
12
13ra_vfs = "0.2.0" 11ra_vfs = "0.2.0"
14ra_syntax = { path = "../ra_syntax" } 12ra_syntax = { path = "../ra_syntax" }
15ra_db = { path = "../ra_db" } 13ra_db = { path = "../ra_db" }
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs
index c59821f44..96b32d9fe 100644
--- a/crates/ra_batch/src/lib.rs
+++ b/crates/ra_batch/src/lib.rs
@@ -1,8 +1,6 @@
1mod vfs_filter; 1mod vfs_filter;
2 2
3use std::sync::Arc; 3use std::{sync::Arc, path::Path, collections::HashSet, error::Error};
4use std::path::Path;
5use std::collections::HashSet;
6 4
7use rustc_hash::FxHashMap; 5use rustc_hash::FxHashMap;
8 6
@@ -14,7 +12,7 @@ use ra_project_model::ProjectWorkspace;
14use ra_vfs::{Vfs, VfsChange}; 12use ra_vfs::{Vfs, VfsChange};
15use vfs_filter::IncludeRustFiles; 13use vfs_filter::IncludeRustFiles;
16 14
17type Result<T> = std::result::Result<T, failure::Error>; 15type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
18 16
19#[salsa::database( 17#[salsa::database(
20 ra_db::SourceDatabaseStorage, 18 ra_db::SourceDatabaseStorage,
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml
index 3117f4fda..57bd0c3d7 100644
--- a/crates/ra_cli/Cargo.toml
+++ b/crates/ra_cli/Cargo.toml
@@ -7,7 +7,6 @@ publish = false
7 7
8[dependencies] 8[dependencies]
9clap = "2.32.0" 9clap = "2.32.0"
10failure = "0.1.4"
11join_to_string = "0.1.1" 10join_to_string = "0.1.1"
12flexi_logger = "0.11.0" 11flexi_logger = "0.11.0"
13indicatif = "0.11.0" 12indicatif = "0.11.0"
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index c9ca13bbc..1db98aec1 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -1,6 +1,6 @@
1mod analysis_stats; 1mod analysis_stats;
2 2
3use std::io::Read; 3use std::{io::Read, error::Error};
4 4
5use clap::{App, Arg, SubCommand}; 5use clap::{App, Arg, SubCommand};
6use ra_ide_api::{file_structure, Analysis}; 6use ra_ide_api::{file_structure, Analysis};
@@ -8,7 +8,7 @@ use ra_syntax::{SourceFile, TreeArc, AstNode};
8use flexi_logger::Logger; 8use flexi_logger::Logger;
9use ra_prof::profile; 9use ra_prof::profile;
10 10
11type Result<T> = ::std::result::Result<T, failure::Error>; 11type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
12 12
13fn main() -> Result<()> { 13fn main() -> Result<()> {
14 Logger::with_env().start()?; 14 Logger::with_env().start()?;
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]
8threadpool = "1.7.1" 8threadpool = "1.7.1"
9relative-path = "0.4.0" 9relative-path = "0.4.0"
10failure = "0.1.4"
11failure_derive = "0.1.4"
12serde_json = "1.0.34" 10serde_json = "1.0.34"
13serde = { version = "1.0.83", features = ["derive"] } 11serde = { version = "1.0.83", features = ["derive"] }
14crossbeam-channel = "0.3.5" 12crossbeam-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;
9pub mod init; 9pub mod init;
10mod world; 10mod world;
11 11
12pub type Result<T> = ::std::result::Result<T, ::failure::Error>; 12pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
13pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions}; 13pub 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..aeb8a2299 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;
2mod subscriptions; 2mod subscriptions;
3pub(crate) mod pending_requests; 3pub(crate) mod pending_requests;
4 4
5use std::{fmt, path::PathBuf, sync::Arc, time::Instant}; 5use std::{fmt, path::PathBuf, sync::Arc, time::Instant, error::Error};
6 6
7use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; 7use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender};
8use failure::{bail, format_err};
9use failure_derive::Fail;
10use gen_lsp_server::{ 8use 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::{
32const THREADPOOL_SIZE: usize = 8; 30const THREADPOOL_SIZE: usize = 8;
33const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3; 31const 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)]
37pub struct LspError { 34pub 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
45impl 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
51impl Error for LspError {}
52
48pub fn main_loop( 53pub 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,8 @@ 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 = params.content_changes.pop().ok_or_else(|| format!("empty changes"))?.text;
398 params.content_changes.pop().ok_or_else(|| format_err!("empty changes"))?.text;
399 state.vfs.write().change_file_overlay(path.as_path(), text); 403 state.vfs.write().change_file_overlay(path.as_path(), text);
400 return Ok(()); 404 return Ok(());
401 } 405 }
@@ -404,7 +408,7 @@ fn on_notification(
404 let not = match not.cast::<req::DidCloseTextDocument>() { 408 let not = match not.cast::<req::DidCloseTextDocument>() {
405 Ok(params) => { 409 Ok(params) => {
406 let uri = params.text_document.uri; 410 let uri = params.text_document.uri;
407 let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; 411 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()) { 412 if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) {
409 subs.remove_sub(FileId(file_id.0)); 413 subs.remove_sub(FileId(file_id.0));
410 } 414 }
@@ -543,11 +547,7 @@ where
543 error: None, 547 error: None,
544 } 548 }
545 } else { 549 } else {
546 RawResponse::err( 550 RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string())
547 id,
548 ErrorCode::InternalError as i32,
549 format!("{}\n{}", e, e.backtrace()),
550 )
551 } 551 }
552 } 552 }
553 }, 553 },
@@ -599,6 +599,6 @@ fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Send
599 sender.send(not.into()).unwrap(); 599 sender.send(not.into()).unwrap();
600} 600}
601 601
602fn is_canceled(e: &failure::Error) -> bool { 602fn is_canceled(e: &Box<dyn std::error::Error + Send + Sync>) -> bool {
603 e.downcast_ref::<Canceled>().is_some() 603 e.downcast_ref::<Canceled>().is_some()
604} 604}
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::{
11use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; 11use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
12use relative_path::RelativePathBuf; 12use relative_path::RelativePathBuf;
13use parking_lot::RwLock; 13use parking_lot::RwLock;
14use failure::{Error, format_err};
15use gen_lsp_server::ErrorCode; 14use gen_lsp_server::ErrorCode;
16 15
17use crate::{ 16use 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"
9rustc-hash = "1.0" 9rustc-hash = "1.0"
10relative-path = "0.4.0" 10relative-path = "0.4.0"
11 11
12failure = "0.1.4"
13
14walkdir = "2.2.7" 12walkdir = "2.2.7"
15 13
16cargo_metadata = "0.7.0" 14cargo_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};
3use cargo_metadata::{MetadataCommand, CargoOpt}; 3use cargo_metadata::{MetadataCommand, CargoOpt};
4use ra_arena::{Arena, RawId, impl_arena_id}; 4use ra_arena::{Arena, RawId, impl_arena_id};
5use rustc_hash::FxHashMap; 5use rustc_hash::FxHashMap;
6use failure::format_err;
7use ra_db::Edition; 6use ra_db::Edition;
8 7
9use crate::Result; 8use 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
11use failure::bail;
12use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
13 13
14use ra_db::{CrateGraph, FileId, Edition}; 14use 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
27pub type Result<T> = ::std::result::Result<T, ::failure::Error>; 27pub type Result<T> = ::std::result::Result<T, Box<dyn Error + Send + Sync>>;
28 28
29#[derive(Debug, Clone)] 29#[derive(Debug, Clone)]
30pub enum ProjectWorkspace { 30pub 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 72ccb61a7..9e0d8aaac 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() };
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 8c0ba6f2d..e46ad12db 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -11,7 +11,7 @@
11//! 11//!
12//! The most interesting modules here are `syntax_node` (which defines concrete 12//! The most interesting modules here are `syntax_node` (which defines concrete
13//! syntax tree) and `ast` (which defines abstract syntax tree on top of the 13//! syntax tree) and `ast` (which defines abstract syntax tree on top of the
14//! CST). The actual parser live in a separate `ra_parser` crate, thought the 14//! CST). The actual parser live in a separate `ra_parser` crate, though the
15//! lexer lives in this crate. 15//! lexer lives in this crate.
16//! 16//!
17//! See `api_walkthrough` test in this file for a quick API tour! 17//! See `api_walkthrough` test in this file for a quick API tour!