aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_cli/src/analysis_bench.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_cli/src/analysis_bench.rs')
-rw-r--r--crates/ra_cli/src/analysis_bench.rs27
1 files changed, 21 insertions, 6 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 }