aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli')
-rw-r--r--crates/ra_cli/src/analysis_bench.rs27
-rw-r--r--crates/ra_cli/src/main.rs15
2 files changed, 29 insertions, 13 deletions
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs
index 1882a9342..a7cc3a2d4 100644
--- a/crates/ra_cli/src/analysis_bench.rs
+++ b/crates/ra_cli/src/analysis_bench.rs
@@ -38,6 +38,7 @@ fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
38pub(crate) enum Op { 38pub(crate) enum Op {
39 Highlight { path: PathBuf }, 39 Highlight { path: PathBuf },
40 Complete(Position), 40 Complete(Position),
41 GotoDef(Position),
41} 42}
42 43
43pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { 44pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
@@ -52,7 +53,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
52 let file_id = { 53 let file_id = {
53 let path = match &op { 54 let path = match &op {
54 Op::Highlight { path } => path, 55 Op::Highlight { path } => path,
55 Op::Complete(pos) => &pos.path, 56 Op::Complete(pos) | Op::GotoDef(pos) => &pos.path,
56 }; 57 };
57 let path = std::env::current_dir()?.join(path).canonicalize()?; 58 let path = std::env::current_dir()?.join(path).canonicalize()?;
58 roots 59 roots
@@ -72,7 +73,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
72 .ok_or_else(|| format!("Can't find {:?}", path))? 73 .ok_or_else(|| format!("Can't find {:?}", path))?
73 }; 74 };
74 75
75 match op { 76 match &op {
76 Op::Highlight { .. } => { 77 Op::Highlight { .. } => {
77 let res = do_work(&mut host, file_id, |analysis| { 78 let res = do_work(&mut host, file_id, |analysis| {
78 analysis.diagnostics(file_id).unwrap(); 79 analysis.diagnostics(file_id).unwrap();
@@ -82,16 +83,30 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
82 println!("\n{}", res); 83 println!("\n{}", res);
83 } 84 }
84 } 85 }
85 Op::Complete(pos) => { 86 Op::Complete(pos) | Op::GotoDef(pos) => {
87 let is_completion = match op {
88 Op::Complete(..) => true,
89 _ => false,
90 };
91
86 let offset = host 92 let offset = host
87 .analysis() 93 .analysis()
88 .file_line_index(file_id)? 94 .file_line_index(file_id)?
89 .offset(LineCol { line: pos.line, col_utf16: pos.column }); 95 .offset(LineCol { line: pos.line, col_utf16: pos.column });
90 let file_postion = FilePosition { file_id, offset }; 96 let file_postion = FilePosition { file_id, offset };
91 97
92 let res = do_work(&mut host, file_id, |analysis| analysis.completions(file_postion)); 98 if is_completion {
93 if verbose { 99 let res =
94 println!("\n{:#?}", res); 100 do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
101 if verbose {
102 println!("\n{:#?}", res);
103 }
104 } else {
105 let res =
106 do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_postion));
107 if verbose {
108 println!("\n{:#?}", res);
109 }
95 } 110 }
96 } 111 }
97 } 112 }
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<()> {
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: Option<String> = matches.opt_value_from_str("--highlight")?; 135 let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?;
136 let complete_path: Option<String> = matches.opt_value_from_str("--complete")?; 136 let complete_path: Option<String> = matches.opt_value_from_str("--complete")?;
137 let op = match (highlight_path, complete_path) { 137 let goto_def_path: Option<String> = matches.opt_value_from_str("--goto-def")?;
138 (Some(path), None) => { 138 let op = match (highlight_path, complete_path, goto_def_path) {
139 let path: String = path; 139 (Some(path), None, None) => analysis_bench::Op::Highlight { path: path.into() },
140 analysis_bench::Op::Highlight { path: path.into() } 140 (None, Some(position), None) => analysis_bench::Op::Complete(position.parse()?),
141 } 141 (None, None, Some(position)) => analysis_bench::Op::GotoDef(position.parse()?),
142 (None, Some(position)) => analysis_bench::Op::Complete(position.parse()?), 142 _ => panic!(
143 _ => panic!("exactly one of `--highlight`, `--complete` must be set"), 143 "exactly one of `--highlight`, `--complete` or `--goto-def` must be set"
144 ),
144 }; 145 };
145 matches.finish().or_else(handle_extra_flags)?; 146 matches.finish().or_else(handle_extra_flags)?;
146 analysis_bench::run(verbose, path.as_ref(), op)?; 147 analysis_bench::run(verbose, path.as_ref(), op)?;