aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-17 17:19:25 +0000
committerAleksey Kladov <[email protected]>2020-02-17 17:19:25 +0000
commit2d1b3da5fb69d932c65884a361ec10d81e8a51d8 (patch)
tree8bb0a64574c42deb666494e7f1c158b9cae9e8b3 /crates/ra_cli
parent8e86d12771c0d77dce82cf80671d4cf9383057c9 (diff)
Use anyhow
Diffstat (limited to 'crates/ra_cli')
-rw-r--r--crates/ra_cli/Cargo.toml1
-rw-r--r--crates/ra_cli/src/analysis_bench.rs3
-rw-r--r--crates/ra_cli/src/load_cargo.rs7
-rw-r--r--crates/ra_cli/src/main.rs18
4 files changed, 15 insertions, 14 deletions
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml
index 03494a809..ce88a76b1 100644
--- a/crates/ra_cli/Cargo.toml
+++ b/crates/ra_cli/Cargo.toml
@@ -13,6 +13,7 @@ log = "0.4.5"
13pico-args = "0.3.0" 13pico-args = "0.3.0"
14rand = { version = "0.7.0", features = ["small_rng"] } 14rand = { version = "0.7.0", features = ["small_rng"] }
15rustc-hash = "1.0" 15rustc-hash = "1.0"
16anyhow = "1.0"
16 17
17hir = { path = "../ra_hir", package = "ra_hir" } 18hir = { path = "../ra_hir", package = "ra_hir" }
18hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } 19hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs
index 3dc8dc691..91fc55fe2 100644
--- a/crates/ra_cli/src/analysis_bench.rs
+++ b/crates/ra_cli/src/analysis_bench.rs
@@ -2,6 +2,7 @@
2 2
3use std::{path::Path, sync::Arc, time::Instant}; 3use std::{path::Path, sync::Arc, time::Instant};
4 4
5use anyhow::format_err;
5use ra_db::{ 6use ra_db::{
6 salsa::{Database, Durability}, 7 salsa::{Database, Durability},
7 FileId, SourceDatabaseExt, 8 FileId, SourceDatabaseExt,
@@ -39,7 +40,7 @@ pub(crate) fn run(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Result<
39 } 40 }
40 None 41 None
41 }) 42 })
42 .ok_or_else(|| format!("Can't find {:?}", path))? 43 .ok_or_else(|| format_err!("Can't find {}", path.display()))?
43 }; 44 };
44 45
45 match &what { 46 match &what {
diff --git a/crates/ra_cli/src/load_cargo.rs b/crates/ra_cli/src/load_cargo.rs
index 2d6433f18..b9a4e6aba 100644
--- a/crates/ra_cli/src/load_cargo.rs
+++ b/crates/ra_cli/src/load_cargo.rs
@@ -1,8 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::{collections::HashSet, error::Error, path::Path}; 3use std::{collections::HashSet, path::Path};
4
5use rustc_hash::FxHashMap;
6 4
7use crossbeam_channel::{unbounded, Receiver}; 5use crossbeam_channel::{unbounded, Receiver};
8use ra_db::{CrateGraph, FileId, SourceRootId}; 6use ra_db::{CrateGraph, FileId, SourceRootId};
@@ -10,8 +8,9 @@ use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags};
10use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; 8use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace};
11use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; 9use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch};
12use ra_vfs_glob::RustPackageFilterBuilder; 10use ra_vfs_glob::RustPackageFilterBuilder;
11use rustc_hash::FxHashMap;
13 12
14type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; 13use anyhow::Result;
15 14
16fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { 15fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId {
17 FileId(f.0) 16 FileId(f.0)
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs
index 66258c860..4cf062f47 100644
--- a/crates/ra_cli/src/main.rs
+++ b/crates/ra_cli/src/main.rs
@@ -5,14 +5,14 @@ mod analysis_stats;
5mod analysis_bench; 5mod analysis_bench;
6mod progress_report; 6mod progress_report;
7 7
8use std::{error::Error, fmt::Write, io::Read, path::PathBuf, str::FromStr}; 8use std::{fmt::Write, io::Read, path::PathBuf, str::FromStr};
9 9
10use pico_args::Arguments; 10use pico_args::Arguments;
11use ra_ide::{file_structure, Analysis}; 11use ra_ide::{file_structure, Analysis};
12use ra_prof::profile; 12use ra_prof::profile;
13use ra_syntax::{AstNode, SourceFile}; 13use ra_syntax::{AstNode, SourceFile};
14 14
15type Result<T, E = Box<dyn Error + Send + Sync>> = std::result::Result<T, E>; 15use anyhow::{bail, format_err, Result};
16 16
17fn main() -> Result<()> { 17fn main() -> Result<()> {
18 env_logger::try_init()?; 18 env_logger::try_init()?;
@@ -118,7 +118,7 @@ pub(crate) struct Position {
118} 118}
119 119
120impl FromStr for Position { 120impl FromStr for Position {
121 type Err = Box<dyn std::error::Error + Send + Sync>; 121 type Err = anyhow::Error;
122 fn from_str(s: &str) -> Result<Self> { 122 fn from_str(s: &str) -> Result<Self> {
123 let (path_line, column) = rsplit_at_char(s, ':')?; 123 let (path_line, column) = rsplit_at_char(s, ':')?;
124 let (path, line) = rsplit_at_char(path_line, ':')?; 124 let (path, line) = rsplit_at_char(path_line, ':')?;
@@ -127,7 +127,7 @@ impl FromStr for Position {
127} 127}
128 128
129fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { 129fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
130 let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?; 130 let idx = s.rfind(c).ok_or_else(|| format_err!("no `{}` in {}", c, s))?;
131 Ok((&s[..idx], &s[idx + 1..])) 131 Ok((&s[..idx], &s[idx + 1..]))
132} 132}
133 133
@@ -143,12 +143,12 @@ impl Command {
143 matches.contains(["-v", "--verbose"]), 143 matches.contains(["-v", "--verbose"]),
144 matches.contains(["-q", "--quiet"]), 144 matches.contains(["-q", "--quiet"]),
145 ) { 145 ) {
146 (true, _, true) => Err("Invalid flags: -q conflicts with -vv")?, 146 (true, _, true) => bail!("Invalid flags: -q conflicts with -vv"),
147 (true, _, false) => Verbosity::Spammy, 147 (true, _, false) => Verbosity::Spammy,
148 (false, false, false) => Verbosity::Normal, 148 (false, false, false) => Verbosity::Normal,
149 (false, false, true) => Verbosity::Quiet, 149 (false, false, true) => Verbosity::Quiet,
150 (false, true, false) => Verbosity::Verbose, 150 (false, true, false) => Verbosity::Verbose,
151 (false, true, true) => Err("Invalid flags: -q conflicts with -v")?, 151 (false, true, true) => bail!("Invalid flags: -q conflicts with -v"),
152 }; 152 };
153 153
154 let command = match subcommand.as_str() { 154 let command = match subcommand.as_str() {
@@ -242,7 +242,7 @@ ARGS:
242 let path = { 242 let path = {
243 let mut trailing = matches.free()?; 243 let mut trailing = matches.free()?;
244 if trailing.len() != 1 { 244 if trailing.len() != 1 {
245 Err("Invalid flags")?; 245 bail!("Invalid flags");
246 } 246 }
247 trailing.pop().unwrap().into() 247 trailing.pop().unwrap().into()
248 }; 248 };
@@ -318,9 +318,9 @@ fn handle_extra_flags(e: pico_args::Error) -> Result<()> {
318 write!(&mut invalid_flags, "{}, ", flag)?; 318 write!(&mut invalid_flags, "{}, ", flag)?;
319 } 319 }
320 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); 320 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2);
321 Err(format!("Invalid flags: {}", invalid_flags).into()) 321 bail!("Invalid flags: {}", invalid_flags);
322 } else { 322 } else {
323 Err(e.to_string().into()) 323 bail!(e);
324 } 324 }
325} 325}
326 326