mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Merge #1404
1404: Fight down failures! r=matklad a=mominul issue #1400 Now only `ra_tools` crate depends on `failure`, should I also fight those? 😁 Co-authored-by: Muhammad Mominul Huque <mominul2082@gmail.com>
This commit is contained in:
commit
257a15b939
21 changed files with 61 additions and 78 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -490,7 +490,6 @@ name = "gen_lsp_server"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
|
||||||
"flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lsp-types 0.57.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lsp-types 0.57.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1021,7 +1020,6 @@ dependencies = [
|
||||||
name = "ra_batch"
|
name = "ra_batch"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"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)",
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ra_db 0.1.0",
|
"ra_db 0.1.0",
|
||||||
"ra_hir 0.1.0",
|
"ra_hir 0.1.0",
|
||||||
|
@ -1037,7 +1035,6 @@ name = "ra_cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"failure 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)",
|
"flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1129,8 +1126,6 @@ name = "ra_lsp_server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"gen_lsp_server 0.2.0",
|
"gen_lsp_server 0.2.0",
|
||||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1188,7 +1183,6 @@ name = "ra_project_model"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_metadata 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ra_arena 0.1.0",
|
"ra_arena 0.1.0",
|
||||||
"ra_db 0.1.0",
|
"ra_db 0.1.0",
|
||||||
|
|
|
@ -10,7 +10,6 @@ description = "Generic LSP server scaffold."
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lsp-types = "0.57.0"
|
lsp-types = "0.57.0"
|
||||||
log = "0.4.3"
|
log = "0.4.3"
|
||||||
failure = "0.1.4"
|
|
||||||
serde_json = "1.0.34"
|
serde_json = "1.0.34"
|
||||||
serde = { version = "1.0.83", features = ["derive"] }
|
serde = { version = "1.0.83", features = ["derive"] }
|
||||||
crossbeam-channel = "0.3.5"
|
crossbeam-channel = "0.3.5"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
use crossbeam_channel::{Sender, Receiver};
|
use crossbeam_channel::{Sender, Receiver};
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
ServerCapabilities, InitializeParams,
|
ServerCapabilities, InitializeParams,
|
||||||
|
@ -5,7 +7,7 @@ use lsp_types::{
|
||||||
};
|
};
|
||||||
use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse};
|
use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse};
|
||||||
|
|
||||||
fn main() -> Result<(), failure::Error> {
|
fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||||
let (receiver, sender, io_threads) = stdio_transport();
|
let (receiver, sender, io_threads) = stdio_transport();
|
||||||
run_server(ServerCapabilities::default(), receiver, sender, main_loop)?;
|
run_server(ServerCapabilities::default(), receiver, sender, main_loop)?;
|
||||||
io_threads.join()?;
|
io_threads.join()?;
|
||||||
|
@ -16,7 +18,7 @@ fn main_loop(
|
||||||
_params: InitializeParams,
|
_params: InitializeParams,
|
||||||
receiver: &Receiver<RawMessage>,
|
receiver: &Receiver<RawMessage>,
|
||||||
sender: &Sender<RawMessage>,
|
sender: &Sender<RawMessage>,
|
||||||
) -> Result<(), failure::Error> {
|
) -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||||
for msg in receiver {
|
for msg in receiver {
|
||||||
match msg {
|
match msg {
|
||||||
RawMessage::Request(req) => {
|
RawMessage::Request(req) => {
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
//! {"jsonrpc": "2.0", "method": "exit", "params": null}
|
//! {"jsonrpc": "2.0", "method": "exit", "params": null}
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
use crossbeam_channel::{Sender, Receiver};
|
use crossbeam_channel::{Sender, Receiver};
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
ServerCapabilities, InitializeParams,
|
ServerCapabilities, InitializeParams,
|
||||||
|
@ -52,7 +54,7 @@ use gen_lsp_server::{
|
||||||
run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse, RawRequest,
|
run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse, RawRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() -> Result<(), failure::Error> {
|
fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||||
// Set up logging. Because `stdio_transport` gets a lock on stdout and stdin, we must have
|
// Set up logging. Because `stdio_transport` gets a lock on stdout and stdin, we must have
|
||||||
// our logging only write out to stderr.
|
// our logging only write out to stderr.
|
||||||
flexi_logger::Logger::with_str("info").start().unwrap();
|
flexi_logger::Logger::with_str("info").start().unwrap();
|
||||||
|
@ -75,7 +77,7 @@ fn main_loop(
|
||||||
_params: InitializeParams,
|
_params: InitializeParams,
|
||||||
receiver: &Receiver<RawMessage>,
|
receiver: &Receiver<RawMessage>,
|
||||||
sender: &Sender<RawMessage>,
|
sender: &Sender<RawMessage>,
|
||||||
) -> Result<(), failure::Error> {
|
) -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||||
info!("starting example main loop");
|
info!("starting example main loop");
|
||||||
for msg in receiver {
|
for msg in receiver {
|
||||||
info!("got msg: {:?}", msg);
|
info!("got msg: {:?}", msg);
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
//! Run with `RUST_LOG=gen_lsp_server=debug` to see all the messages.
|
//! Run with `RUST_LOG=gen_lsp_server=debug` to see all the messages.
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
|
//! use std::error::Error;
|
||||||
//! use crossbeam_channel::{Sender, Receiver};
|
//! use crossbeam_channel::{Sender, Receiver};
|
||||||
//! use lsp_types::{ServerCapabilities, InitializeParams, request::{GotoDefinition, GotoDefinitionResponse}};
|
//! use lsp_types::{ServerCapabilities, InitializeParams, request::{GotoDefinition, GotoDefinitionResponse}};
|
||||||
//! use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse};
|
//! use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse};
|
||||||
//!
|
//!
|
||||||
//! fn main() -> Result<(), failure::Error> {
|
//! fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
//! let (receiver, sender, io_threads) = stdio_transport();
|
//! let (receiver, sender, io_threads) = stdio_transport();
|
||||||
//! run_server(
|
//! run_server(
|
||||||
//! ServerCapabilities::default(),
|
//! ServerCapabilities::default(),
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
//! _params: InitializeParams,
|
//! _params: InitializeParams,
|
||||||
//! receiver: &Receiver<RawMessage>,
|
//! receiver: &Receiver<RawMessage>,
|
||||||
//! sender: &Sender<RawMessage>,
|
//! sender: &Sender<RawMessage>,
|
||||||
//! ) -> Result<(), failure::Error> {
|
//! ) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
//! for msg in receiver {
|
//! for msg in receiver {
|
||||||
//! match msg {
|
//! match msg {
|
||||||
//! RawMessage::Request(req) => {
|
//! RawMessage::Request(req) => {
|
||||||
|
@ -54,7 +55,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use failure::{bail, format_err};
|
use std::error::Error;
|
||||||
|
|
||||||
mod msg;
|
mod msg;
|
||||||
mod stdio;
|
mod stdio;
|
||||||
|
@ -66,7 +67,7 @@ use lsp_types::{
|
||||||
InitializeParams, InitializeResult, ServerCapabilities,
|
InitializeParams, InitializeResult, ServerCapabilities,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
pub type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError},
|
msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError},
|
||||||
stdio::{stdio_transport, Threads},
|
stdio::{stdio_transport, Threads},
|
||||||
|
@ -92,8 +93,8 @@ pub fn run_server(
|
||||||
match receiver.recv() {
|
match receiver.recv() {
|
||||||
Ok(RawMessage::Notification(n)) => n
|
Ok(RawMessage::Notification(n)) => n
|
||||||
.cast::<Exit>()
|
.cast::<Exit>()
|
||||||
.map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?,
|
.map_err(|n| format!("unexpected notification during shutdown: {:?}", n))?,
|
||||||
m => bail!("unexpected message during shutdown: {:?}", m),
|
m => Err(format!("unexpected message during shutdown: {:?}", m))?,
|
||||||
}
|
}
|
||||||
log::info!("lsp server shutdown complete");
|
log::info!("lsp server shutdown complete");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -118,19 +119,18 @@ fn initialize(
|
||||||
) -> Result<InitializeParams> {
|
) -> Result<InitializeParams> {
|
||||||
let (id, params) = match receiver.recv() {
|
let (id, params) = match receiver.recv() {
|
||||||
Ok(RawMessage::Request(req)) => match req.cast::<Initialize>() {
|
Ok(RawMessage::Request(req)) => match req.cast::<Initialize>() {
|
||||||
Err(req) => bail!("expected initialize request, got {:?}", req),
|
Err(req) => Err(format!("expected initialize request, got {:?}", req))?,
|
||||||
Ok(req) => req,
|
Ok(req) => req,
|
||||||
},
|
},
|
||||||
msg => bail!("expected initialize request, got {:?}", msg),
|
msg => Err(format!("expected initialize request, got {:?}", msg))?,
|
||||||
};
|
};
|
||||||
let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps });
|
let resp = RawResponse::ok::<Initialize>(id, &InitializeResult { capabilities: caps });
|
||||||
sender.send(RawMessage::Response(resp)).unwrap();
|
sender.send(RawMessage::Response(resp)).unwrap();
|
||||||
match receiver.recv() {
|
match receiver.recv() {
|
||||||
Ok(RawMessage::Notification(n)) => {
|
Ok(RawMessage::Notification(n)) => {
|
||||||
n.cast::<Initialized>()
|
n.cast::<Initialized>().map_err(|_| "expected initialized notification")?;
|
||||||
.map_err(|_| format_err!("expected initialized notification"))?;
|
|
||||||
}
|
}
|
||||||
_ => bail!("expected initialized notification"),
|
_ => Err(format!("expected initialized notification"))?,
|
||||||
}
|
}
|
||||||
Ok(params)
|
Ok(params)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::io::{BufRead, Write};
|
||||||
use lsp_types::{notification::Notification, request::Request};
|
use lsp_types::{notification::Notification, request::Request};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{from_str, from_value, to_string, to_value, Value};
|
use serde_json::{from_str, from_value, to_string, to_value, Value};
|
||||||
use failure::{bail, format_err};
|
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
|
@ -175,7 +174,7 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
if !buf.ends_with("\r\n") {
|
if !buf.ends_with("\r\n") {
|
||||||
bail!("malformed header: {:?}", buf);
|
Err(format!("malformed header: {:?}", buf))?;
|
||||||
}
|
}
|
||||||
let buf = &buf[..buf.len() - 2];
|
let buf = &buf[..buf.len() - 2];
|
||||||
if buf.is_empty() {
|
if buf.is_empty() {
|
||||||
|
@ -183,13 +182,12 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> {
|
||||||
}
|
}
|
||||||
let mut parts = buf.splitn(2, ": ");
|
let mut parts = buf.splitn(2, ": ");
|
||||||
let header_name = parts.next().unwrap();
|
let header_name = parts.next().unwrap();
|
||||||
let header_value =
|
let header_value = parts.next().ok_or_else(|| format!("malformed header: {:?}", buf))?;
|
||||||
parts.next().ok_or_else(|| format_err!("malformed header: {:?}", buf))?;
|
|
||||||
if header_name == "Content-Length" {
|
if header_name == "Content-Length" {
|
||||||
size = Some(header_value.parse::<usize>()?);
|
size = Some(header_value.parse::<usize>()?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let size = size.ok_or_else(|| format_err!("no Content-Length"))?;
|
let size = size.ok_or("no Content-Length")?;
|
||||||
let mut buf = buf.into_bytes();
|
let mut buf = buf.into_bytes();
|
||||||
buf.resize(size, 0);
|
buf.resize(size, 0);
|
||||||
inp.read_exact(&mut buf)?;
|
inp.read_exact(&mut buf)?;
|
||||||
|
|
|
@ -4,7 +4,6 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
use failure::bail;
|
|
||||||
use lsp_types::notification::Exit;
|
use lsp_types::notification::Exit;
|
||||||
|
|
||||||
use crate::{RawMessage, Result};
|
use crate::{RawMessage, Result};
|
||||||
|
@ -48,11 +47,11 @@ impl Threads {
|
||||||
pub fn join(self) -> Result<()> {
|
pub fn join(self) -> Result<()> {
|
||||||
match self.reader.join() {
|
match self.reader.join() {
|
||||||
Ok(r) => r?,
|
Ok(r) => r?,
|
||||||
Err(_) => bail!("reader panicked"),
|
Err(_) => Err("reader panicked")?,
|
||||||
}
|
}
|
||||||
match self.writer.join() {
|
match self.writer.join() {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(_) => bail!("writer panicked"),
|
Err(_) => Err("writer panicked")?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ authors = ["rust-analyzer developers"]
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
rustc-hash = "1.0"
|
rustc-hash = "1.0"
|
||||||
|
|
||||||
failure = "0.1.4"
|
|
||||||
|
|
||||||
ra_vfs = "0.2.0"
|
ra_vfs = "0.2.0"
|
||||||
ra_syntax = { path = "../ra_syntax" }
|
ra_syntax = { path = "../ra_syntax" }
|
||||||
ra_db = { path = "../ra_db" }
|
ra_db = { path = "../ra_db" }
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
mod vfs_filter;
|
mod vfs_filter;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::{sync::Arc, path::Path, collections::HashSet, error::Error};
|
||||||
use std::path::Path;
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
|
@ -14,7 +12,7 @@ use ra_project_model::ProjectWorkspace;
|
||||||
use ra_vfs::{Vfs, VfsChange};
|
use ra_vfs::{Vfs, VfsChange};
|
||||||
use vfs_filter::IncludeRustFiles;
|
use vfs_filter::IncludeRustFiles;
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, failure::Error>;
|
type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
|
||||||
|
|
||||||
#[salsa::database(
|
#[salsa::database(
|
||||||
ra_db::SourceDatabaseStorage,
|
ra_db::SourceDatabaseStorage,
|
||||||
|
|
|
@ -7,7 +7,6 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.32.0"
|
clap = "2.32.0"
|
||||||
failure = "0.1.4"
|
|
||||||
join_to_string = "0.1.1"
|
join_to_string = "0.1.1"
|
||||||
flexi_logger = "0.11.0"
|
flexi_logger = "0.11.0"
|
||||||
indicatif = "0.11.0"
|
indicatif = "0.11.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mod analysis_stats;
|
mod analysis_stats;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::{io::Read, error::Error};
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use ra_ide_api::{file_structure, Analysis};
|
use ra_ide_api::{file_structure, Analysis};
|
||||||
|
@ -8,7 +8,7 @@ use ra_syntax::{SourceFile, TreeArc, AstNode};
|
||||||
use flexi_logger::Logger;
|
use flexi_logger::Logger;
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
|
|
||||||
type Result<T> = ::std::result::Result<T, failure::Error>;
|
type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
Logger::with_env().start()?;
|
Logger::with_env().start()?;
|
||||||
|
|
|
@ -7,8 +7,6 @@ authors = ["rust-analyzer developers"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
threadpool = "1.7.1"
|
threadpool = "1.7.1"
|
||||||
relative-path = "0.4.0"
|
relative-path = "0.4.0"
|
||||||
failure = "0.1.4"
|
|
||||||
failure_derive = "0.1.4"
|
|
||||||
serde_json = "1.0.34"
|
serde_json = "1.0.34"
|
||||||
serde = { version = "1.0.83", features = ["derive"] }
|
serde = { version = "1.0.83", features = ["derive"] }
|
||||||
crossbeam-channel = "0.3.5"
|
crossbeam-channel = "0.3.5"
|
||||||
|
|
|
@ -9,5 +9,5 @@ pub mod req;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
mod world;
|
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};
|
pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions};
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
log::error!("server panicked");
|
log::error!("server panicked");
|
||||||
failure::bail!("server panicked")
|
Err("server panicked")?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,9 @@ mod handlers;
|
||||||
mod subscriptions;
|
mod subscriptions;
|
||||||
pub(crate) mod pending_requests;
|
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 crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender};
|
||||||
use failure::{bail, format_err};
|
|
||||||
use failure_derive::Fail;
|
|
||||||
use gen_lsp_server::{
|
use gen_lsp_server::{
|
||||||
handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
|
handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
|
||||||
};
|
};
|
||||||
|
@ -32,8 +30,7 @@ use crate::{
|
||||||
const THREADPOOL_SIZE: usize = 8;
|
const THREADPOOL_SIZE: usize = 8;
|
||||||
const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3;
|
const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3;
|
||||||
|
|
||||||
#[derive(Debug, Fail)]
|
#[derive(Debug)]
|
||||||
#[fail(display = "Language Server request failed with {}. ({})", code, message)]
|
|
||||||
pub struct LspError {
|
pub struct LspError {
|
||||||
pub code: i32,
|
pub code: i32,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
|
@ -45,6 +42,14 @@ impl 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(
|
pub fn main_loop(
|
||||||
ws_roots: Vec<PathBuf>,
|
ws_roots: Vec<PathBuf>,
|
||||||
options: InitializationOptions,
|
options: InitializationOptions,
|
||||||
|
@ -177,12 +182,12 @@ fn main_loop_inner(
|
||||||
let event = select! {
|
let event = select! {
|
||||||
recv(msg_receiver) -> msg => match msg {
|
recv(msg_receiver) -> msg => match msg {
|
||||||
Ok(msg) => Event::Msg(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(task_receiver) -> task => Event::Task(task.unwrap()),
|
||||||
recv(state.vfs.read().task_receiver()) -> task => match task {
|
recv(state.vfs.read().task_receiver()) -> task => match task {
|
||||||
Ok(task) => Event::Vfs(task),
|
Ok(task) => Event::Vfs(task),
|
||||||
Err(RecvError) => bail!("vfs died"),
|
Err(RecvError) => Err("vfs died")?,
|
||||||
},
|
},
|
||||||
recv(libdata_receiver) -> data => Event::Lib(data.unwrap())
|
recv(libdata_receiver) -> data => Event::Lib(data.unwrap())
|
||||||
};
|
};
|
||||||
|
@ -380,7 +385,7 @@ fn on_notification(
|
||||||
let not = match not.cast::<req::DidOpenTextDocument>() {
|
let not = match not.cast::<req::DidOpenTextDocument>() {
|
||||||
Ok(params) => {
|
Ok(params) => {
|
||||||
let uri = params.text_document.uri;
|
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) =
|
if let Some(file_id) =
|
||||||
state.vfs.write().add_file_overlay(&path, params.text_document.text)
|
state.vfs.write().add_file_overlay(&path, params.text_document.text)
|
||||||
{
|
{
|
||||||
|
@ -393,9 +398,8 @@ fn on_notification(
|
||||||
let not = match not.cast::<req::DidChangeTextDocument>() {
|
let not = match not.cast::<req::DidChangeTextDocument>() {
|
||||||
Ok(mut params) => {
|
Ok(mut params) => {
|
||||||
let uri = params.text_document.uri;
|
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 =
|
let text = params.content_changes.pop().ok_or_else(|| format!("empty changes"))?.text;
|
||||||
params.content_changes.pop().ok_or_else(|| format_err!("empty changes"))?.text;
|
|
||||||
state.vfs.write().change_file_overlay(path.as_path(), text);
|
state.vfs.write().change_file_overlay(path.as_path(), text);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -404,7 +408,7 @@ fn on_notification(
|
||||||
let not = match not.cast::<req::DidCloseTextDocument>() {
|
let not = match not.cast::<req::DidCloseTextDocument>() {
|
||||||
Ok(params) => {
|
Ok(params) => {
|
||||||
let uri = params.text_document.uri;
|
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()) {
|
if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) {
|
||||||
subs.remove_sub(FileId(file_id.0));
|
subs.remove_sub(FileId(file_id.0));
|
||||||
}
|
}
|
||||||
|
@ -543,11 +547,7 @@ where
|
||||||
error: None,
|
error: None,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RawResponse::err(
|
RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string())
|
||||||
id,
|
|
||||||
ErrorCode::InternalError as i32,
|
|
||||||
format!("{}\n{}", e, e.backtrace()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -599,6 +599,6 @@ fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Send
|
||||||
sender.send(not.into()).unwrap();
|
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()
|
e.downcast_ref::<Canceled>().is_some()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ use ra_ide_api::{
|
||||||
use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
|
use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
|
||||||
use relative_path::RelativePathBuf;
|
use relative_path::RelativePathBuf;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use failure::{Error, format_err};
|
|
||||||
use gen_lsp_server::ErrorCode;
|
use gen_lsp_server::ErrorCode;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -169,13 +168,13 @@ impl WorldSnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uri_to_file_id(&self, uri: &Url) -> Result<FileId> {
|
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(|| {
|
let file = self.vfs.read().path2file(&path).ok_or_else(|| {
|
||||||
// Show warning as this file is outside current workspace
|
// Show warning as this file is outside current workspace
|
||||||
Error::from(LspError {
|
LspError {
|
||||||
code: ErrorCode::InvalidRequest as i32,
|
code: ErrorCode::InvalidRequest as i32,
|
||||||
message: "Rust file outside current workspace is not supported yet.".to_string(),
|
message: "Rust file outside current workspace is not supported yet.".to_string(),
|
||||||
})
|
}
|
||||||
})?;
|
})?;
|
||||||
Ok(FileId(file.0))
|
Ok(FileId(file.0))
|
||||||
}
|
}
|
||||||
|
@ -183,7 +182,7 @@ impl WorldSnapshot {
|
||||||
pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> {
|
pub fn file_id_to_uri(&self, id: FileId) -> Result<Url> {
|
||||||
let path = self.vfs.read().file2path(VfsFile(id.0));
|
let path = self.vfs.read().file2path(VfsFile(id.0));
|
||||||
let url = Url::from_file_path(&path)
|
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)
|
Ok(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +190,7 @@ impl WorldSnapshot {
|
||||||
let base = self.vfs.read().root2path(VfsRoot(root.0));
|
let base = self.vfs.read().root2path(VfsRoot(root.0));
|
||||||
let path = path.to_path(base);
|
let path = path.to_path(base);
|
||||||
let url = Url::from_file_path(&path)
|
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)
|
Ok(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ log = "0.4.5"
|
||||||
rustc-hash = "1.0"
|
rustc-hash = "1.0"
|
||||||
relative-path = "0.4.0"
|
relative-path = "0.4.0"
|
||||||
|
|
||||||
failure = "0.1.4"
|
|
||||||
|
|
||||||
walkdir = "2.2.7"
|
walkdir = "2.2.7"
|
||||||
|
|
||||||
cargo_metadata = "0.7.0"
|
cargo_metadata = "0.7.0"
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::path::{Path, PathBuf};
|
||||||
use cargo_metadata::{MetadataCommand, CargoOpt};
|
use cargo_metadata::{MetadataCommand, CargoOpt};
|
||||||
use ra_arena::{Arena, RawId, impl_arena_id};
|
use ra_arena::{Arena, RawId, impl_arena_id};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use failure::format_err;
|
|
||||||
use ra_db::Edition;
|
use ra_db::Edition;
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
@ -127,7 +126,7 @@ impl CargoWorkspace {
|
||||||
if let Some(parent) = cargo_toml.parent() {
|
if let Some(parent) = cargo_toml.parent() {
|
||||||
meta.current_dir(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 pkg_by_id = FxHashMap::default();
|
||||||
let mut packages = Arena::default();
|
let mut packages = Arena::default();
|
||||||
let mut targets = Arena::default();
|
let mut targets = Arena::default();
|
||||||
|
|
|
@ -6,9 +6,9 @@ use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::BufReader,
|
io::BufReader,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
error::Error
|
||||||
};
|
};
|
||||||
|
|
||||||
use failure::bail;
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use ra_db::{CrateGraph, FileId, Edition};
|
use ra_db::{CrateGraph, FileId, Edition};
|
||||||
|
@ -24,7 +24,7 @@ pub use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME use proper error enum
|
// 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)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ProjectWorkspace {
|
pub enum ProjectWorkspace {
|
||||||
|
@ -298,5 +298,5 @@ fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
|
||||||
}
|
}
|
||||||
curr = path.parent();
|
curr = path.parent();
|
||||||
}
|
}
|
||||||
bail!("can't find Cargo.toml at {}", path.display())
|
Err(format!("can't find Cargo.toml at {}", path.display()))?
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,18 +38,18 @@ impl Sysroot {
|
||||||
.args(&["--print", "sysroot"])
|
.args(&["--print", "sysroot"])
|
||||||
.output()?;
|
.output()?;
|
||||||
if !rustc_output.status.success() {
|
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 stdout = String::from_utf8(rustc_output.stdout)?;
|
||||||
let sysroot_path = Path::new(stdout.trim());
|
let sysroot_path = Path::new(stdout.trim());
|
||||||
let src = sysroot_path.join("lib/rustlib/src/rust/src");
|
let src = sysroot_path.join("lib/rustlib/src/rust/src");
|
||||||
if !src.exists() {
|
if !src.exists() {
|
||||||
failure::bail!(
|
Err(format!(
|
||||||
"can't load standard library from sysroot\n\
|
"can't load standard library from sysroot\n\
|
||||||
{:?}\n\
|
{:?}\n\
|
||||||
try running `rustup component add rust-src`",
|
try running `rustup component add rust-src`",
|
||||||
src,
|
src,
|
||||||
);
|
))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut sysroot = Sysroot { crates: Arena::default() };
|
let mut sysroot = Sysroot { crates: Arena::default() };
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
//!
|
//!
|
||||||
//! The most interesting modules here are `syntax_node` (which defines concrete
|
//! The most interesting modules here are `syntax_node` (which defines concrete
|
||||||
//! syntax tree) and `ast` (which defines abstract syntax tree on top of the
|
//! syntax tree) and `ast` (which defines abstract syntax tree on top of the
|
||||||
//! CST). The actual parser live in a separate `ra_parser` crate, thought the
|
//! CST). The actual parser live in a separate `ra_parser` crate, though the
|
||||||
//! lexer lives in this crate.
|
//! lexer lives in this crate.
|
||||||
//!
|
//!
|
||||||
//! See `api_walkthrough` test in this file for a quick API tour!
|
//! See `api_walkthrough` test in this file for a quick API tour!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue