diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-16 17:31:16 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-16 17:31:16 +0000 |
commit | 10f910df4bf2e3cf923b7823c2873d3b06313699 (patch) | |
tree | 4efa37ee370248da78eb2d63f1b0c9221b4d90f6 /crates/ra_cli/src/main.rs | |
parent | 742b3b5744fbca1a5587e2898cd5b74d55853a47 (diff) | |
parent | ca7e9ab0da4f9a781db1857cd11951d296df24a9 (diff) |
Merge #3172
3172: 1-based columns r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_cli/src/main.rs')
-rw-r--r-- | crates/ra_cli/src/main.rs | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 6a0e447b9..750cbab86 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -132,25 +132,16 @@ fn main() -> Result<()> { | |||
132 | } | 132 | } |
133 | let verbose = matches.contains(["-v", "--verbose"]); | 133 | let verbose = matches.contains(["-v", "--verbose"]); |
134 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); | 134 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); |
135 | let highlight_path = matches.opt_value_from_str("--highlight")?; | 135 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; |
136 | let complete_path = matches.opt_value_from_str("--complete")?; | 136 | let complete_path: Option<String> = matches.opt_value_from_str("--complete")?; |
137 | if highlight_path.is_some() && complete_path.is_some() { | 137 | let goto_def_path: Option<String> = matches.opt_value_from_str("--goto-def")?; |
138 | panic!("either --highlight or --complete must be set, not both") | 138 | let op = match (highlight_path, complete_path, goto_def_path) { |
139 | } | 139 | (Some(path), None, None) => analysis_bench::Op::Highlight { path: path.into() }, |
140 | let op = if let Some(path) = highlight_path { | 140 | (None, Some(position), None) => analysis_bench::Op::Complete(position.parse()?), |
141 | let path: String = path; | 141 | (None, None, Some(position)) => analysis_bench::Op::GotoDef(position.parse()?), |
142 | analysis_bench::Op::Highlight { path: path.into() } | 142 | _ => panic!( |
143 | } else if let Some(path_line_col) = complete_path { | 143 | "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" |
144 | let path_line_col: String = path_line_col; | 144 | ), |
145 | let (path_line, column) = rsplit_at_char(path_line_col.as_str(), ':')?; | ||
146 | let (path, line) = rsplit_at_char(path_line, ':')?; | ||
147 | analysis_bench::Op::Complete { | ||
148 | path: path.into(), | ||
149 | line: line.parse()?, | ||
150 | column: column.parse()?, | ||
151 | } | ||
152 | } else { | ||
153 | panic!("either --highlight or --complete must be set") | ||
154 | }; | 145 | }; |
155 | matches.finish().or_else(handle_extra_flags)?; | 146 | matches.finish().or_else(handle_extra_flags)?; |
156 | analysis_bench::run(verbose, path.as_ref(), op)?; | 147 | analysis_bench::run(verbose, path.as_ref(), op)?; |
@@ -183,8 +174,3 @@ fn read_stdin() -> Result<String> { | |||
183 | std::io::stdin().read_to_string(&mut buff)?; | 174 | std::io::stdin().read_to_string(&mut buff)?; |
184 | Ok(buff) | 175 | Ok(buff) |
185 | } | 176 | } |
186 | |||
187 | fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { | ||
188 | let idx = s.rfind(':').ok_or_else(|| format!("no `{}` in {}", c, s))?; | ||
189 | Ok((&s[..idx], &s[idx + 1..])) | ||
190 | } | ||