|
2 | 2 |
|
3 | 3 | use std::{env, path::Path, str::FromStr, sync::Arc, time::Instant}; |
4 | 4 |
|
5 | | -use anyhow::{format_err, Result}; |
| 5 | +use anyhow::{bail, format_err, Result}; |
6 | 6 | use ra_db::{ |
7 | 7 | salsa::{Database, Durability}, |
8 | 8 | FileId, |
@@ -30,19 +30,18 @@ pub struct Position { |
30 | 30 | impl FromStr for Position { |
31 | 31 | type Err = anyhow::Error; |
32 | 32 | fn from_str(s: &str) -> Result<Self> { |
33 | | - let (path_line, column) = rsplit_at_char(s, ':')?; |
34 | | - let (path, line) = rsplit_at_char(path_line, ':')?; |
35 | | - let path = env::current_dir().unwrap().join(path); |
36 | | - let path = AbsPathBuf::assert(path); |
37 | | - Ok(Position { path, line: line.parse()?, column: column.parse()? }) |
| 33 | + let mut split = s.rsplitn(3, ':'); |
| 34 | + match (split.next(), split.next(), split.next()) { |
| 35 | + (Some(column), Some(line), Some(path)) => { |
| 36 | + let path = env::current_dir().unwrap().join(path); |
| 37 | + let path = AbsPathBuf::assert(path); |
| 38 | + Ok(Position { path, line: line.parse()?, column: column.parse()? }) |
| 39 | + } |
| 40 | + _ => bail!("position should be in file:line:column format: {:?}", s), |
| 41 | + } |
38 | 42 | } |
39 | 43 | } |
40 | 44 |
|
41 | | -fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { |
42 | | - let idx = s.rfind(c).ok_or_else(|| format_err!("no `{}` in {}", c, s))?; |
43 | | - Ok((&s[..idx], &s[idx + 1..])) |
44 | | -} |
45 | | - |
46 | 45 | pub fn analysis_bench( |
47 | 46 | verbosity: Verbosity, |
48 | 47 | path: &Path, |
|
0 commit comments