diff options
Diffstat (limited to 'crates/ra_cli')
-rw-r--r-- | crates/ra_cli/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_cli/src/analysis_bench.rs | 3 | ||||
-rw-r--r-- | crates/ra_cli/src/load_cargo.rs | 7 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 18 |
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" | |||
13 | pico-args = "0.3.0" | 13 | pico-args = "0.3.0" |
14 | rand = { version = "0.7.0", features = ["small_rng"] } | 14 | rand = { version = "0.7.0", features = ["small_rng"] } |
15 | rustc-hash = "1.0" | 15 | rustc-hash = "1.0" |
16 | anyhow = "1.0" | ||
16 | 17 | ||
17 | hir = { path = "../ra_hir", package = "ra_hir" } | 18 | hir = { path = "../ra_hir", package = "ra_hir" } |
18 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } | 19 | hir_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 | ||
3 | use std::{path::Path, sync::Arc, time::Instant}; | 3 | use std::{path::Path, sync::Arc, time::Instant}; |
4 | 4 | ||
5 | use anyhow::format_err; | ||
5 | use ra_db::{ | 6 | use 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 | ||
3 | use std::{collections::HashSet, error::Error, path::Path}; | 3 | use std::{collections::HashSet, path::Path}; |
4 | |||
5 | use rustc_hash::FxHashMap; | ||
6 | 4 | ||
7 | use crossbeam_channel::{unbounded, Receiver}; | 5 | use crossbeam_channel::{unbounded, Receiver}; |
8 | use ra_db::{CrateGraph, FileId, SourceRootId}; | 6 | use ra_db::{CrateGraph, FileId, SourceRootId}; |
@@ -10,8 +8,9 @@ use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; | |||
10 | use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; | 8 | use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; |
11 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; | 9 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; |
12 | use ra_vfs_glob::RustPackageFilterBuilder; | 10 | use ra_vfs_glob::RustPackageFilterBuilder; |
11 | use rustc_hash::FxHashMap; | ||
13 | 12 | ||
14 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; | 13 | use anyhow::Result; |
15 | 14 | ||
16 | fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { | 15 | fn 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; | |||
5 | mod analysis_bench; | 5 | mod analysis_bench; |
6 | mod progress_report; | 6 | mod progress_report; |
7 | 7 | ||
8 | use std::{error::Error, fmt::Write, io::Read, path::PathBuf, str::FromStr}; | 8 | use std::{fmt::Write, io::Read, path::PathBuf, str::FromStr}; |
9 | 9 | ||
10 | use pico_args::Arguments; | 10 | use pico_args::Arguments; |
11 | use ra_ide::{file_structure, Analysis}; | 11 | use ra_ide::{file_structure, Analysis}; |
12 | use ra_prof::profile; | 12 | use ra_prof::profile; |
13 | use ra_syntax::{AstNode, SourceFile}; | 13 | use ra_syntax::{AstNode, SourceFile}; |
14 | 14 | ||
15 | type Result<T, E = Box<dyn Error + Send + Sync>> = std::result::Result<T, E>; | 15 | use anyhow::{bail, format_err, Result}; |
16 | 16 | ||
17 | fn main() -> Result<()> { | 17 | fn main() -> Result<()> { |
18 | env_logger::try_init()?; | 18 | env_logger::try_init()?; |
@@ -118,7 +118,7 @@ pub(crate) struct Position { | |||
118 | } | 118 | } |
119 | 119 | ||
120 | impl FromStr for Position { | 120 | impl 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 | ||
129 | fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { | 129 | fn 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 | ||