From 2ba918775cba8d0b1166f7a14a8e114c2fd73f0d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Feb 2020 18:17:35 +0100 Subject: Refactor position parsing --- crates/ra_cli/src/main.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'crates/ra_cli/src/main.rs') diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 6a0e447b9..749317475 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -133,22 +133,15 @@ fn main() -> Result<()> { let verbose = matches.contains(["-v", "--verbose"]); let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); let highlight_path = matches.opt_value_from_str("--highlight")?; - let complete_path = matches.opt_value_from_str("--complete")?; + let complete_path: Option = matches.opt_value_from_str("--complete")?; if highlight_path.is_some() && complete_path.is_some() { panic!("either --highlight or --complete must be set, not both") } let op = if let Some(path) = highlight_path { let path: String = path; analysis_bench::Op::Highlight { path: path.into() } - } else if let Some(path_line_col) = complete_path { - let path_line_col: String = path_line_col; - let (path_line, column) = rsplit_at_char(path_line_col.as_str(), ':')?; - let (path, line) = rsplit_at_char(path_line, ':')?; - analysis_bench::Op::Complete { - path: path.into(), - line: line.parse()?, - column: column.parse()?, - } + } else if let Some(position) = complete_path { + analysis_bench::Op::Complete(position.parse()?) } else { panic!("either --highlight or --complete must be set") }; @@ -183,8 +176,3 @@ fn read_stdin() -> Result { std::io::stdin().read_to_string(&mut buff)?; Ok(buff) } - -fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { - let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?; - Ok((&s[..idx], &s[idx + 1..])) -} -- cgit v1.2.3 From 6a3ec2dfa51d92930e028c2ea5af199dbcc813f8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Feb 2020 18:20:22 +0100 Subject: Refactor arg parsing --- crates/ra_cli/src/main.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'crates/ra_cli/src/main.rs') diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 749317475..9c23cf001 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -132,18 +132,15 @@ fn main() -> Result<()> { } let verbose = matches.contains(["-v", "--verbose"]); let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); - let highlight_path = matches.opt_value_from_str("--highlight")?; + let highlight_path: Option = matches.opt_value_from_str("--highlight")?; let complete_path: Option = matches.opt_value_from_str("--complete")?; - if highlight_path.is_some() && complete_path.is_some() { - panic!("either --highlight or --complete must be set, not both") - } - let op = if let Some(path) = highlight_path { - let path: String = path; - analysis_bench::Op::Highlight { path: path.into() } - } else if let Some(position) = complete_path { - analysis_bench::Op::Complete(position.parse()?) - } else { - panic!("either --highlight or --complete must be set") + let op = match (highlight_path, complete_path) { + (Some(path), None) => { + let path: String = path; + analysis_bench::Op::Highlight { path: path.into() } + } + (None, Some(position)) => analysis_bench::Op::Complete(position.parse()?), + _ => panic!("exactly one of `--highlight`, `--complete` must be set"), }; matches.finish().or_else(handle_extra_flags)?; analysis_bench::run(verbose, path.as_ref(), op)?; -- cgit v1.2.3 From 0f79ec76d6fd29d851e05c9140192e4505097185 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Feb 2020 18:24:06 +0100 Subject: Support goto def in bences --- crates/ra_cli/src/main.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'crates/ra_cli/src/main.rs') diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 9c23cf001..750cbab86 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -134,13 +134,14 @@ fn main() -> Result<()> { let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); let highlight_path: Option = matches.opt_value_from_str("--highlight")?; let complete_path: Option = matches.opt_value_from_str("--complete")?; - let op = match (highlight_path, complete_path) { - (Some(path), None) => { - let path: String = path; - analysis_bench::Op::Highlight { path: path.into() } - } - (None, Some(position)) => analysis_bench::Op::Complete(position.parse()?), - _ => panic!("exactly one of `--highlight`, `--complete` must be set"), + let goto_def_path: Option = matches.opt_value_from_str("--goto-def")?; + let op = match (highlight_path, complete_path, goto_def_path) { + (Some(path), None, None) => analysis_bench::Op::Highlight { path: path.into() }, + (None, Some(position), None) => analysis_bench::Op::Complete(position.parse()?), + (None, None, Some(position)) => analysis_bench::Op::GotoDef(position.parse()?), + _ => panic!( + "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" + ), }; matches.finish().or_else(handle_extra_flags)?; analysis_bench::run(verbose, path.as_ref(), op)?; -- cgit v1.2.3