mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-13 09:05:00 +00:00
Support goto def in bences
This commit is contained in:
parent
6a3ec2dfa5
commit
0f79ec76d6
@ -38,6 +38,7 @@ fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> {
|
||||
pub(crate) enum Op {
|
||||
Highlight { path: PathBuf },
|
||||
Complete(Position),
|
||||
GotoDef(Position),
|
||||
}
|
||||
|
||||
pub(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<()> {
|
||||
let file_id = {
|
||||
let path = match &op {
|
||||
Op::Highlight { path } => path,
|
||||
Op::Complete(pos) => &pos.path,
|
||||
Op::Complete(pos) | Op::GotoDef(pos) => &pos.path,
|
||||
};
|
||||
let path = std::env::current_dir()?.join(path).canonicalize()?;
|
||||
roots
|
||||
@ -72,7 +73,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
|
||||
.ok_or_else(|| format!("Can't find {:?}", path))?
|
||||
};
|
||||
|
||||
match op {
|
||||
match &op {
|
||||
Op::Highlight { .. } => {
|
||||
let res = do_work(&mut host, file_id, |analysis| {
|
||||
analysis.diagnostics(file_id).unwrap();
|
||||
@ -82,16 +83,30 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
|
||||
println!("\n{}", res);
|
||||
}
|
||||
}
|
||||
Op::Complete(pos) => {
|
||||
Op::Complete(pos) | Op::GotoDef(pos) => {
|
||||
let is_completion = match op {
|
||||
Op::Complete(..) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
let offset = host
|
||||
.analysis()
|
||||
.file_line_index(file_id)?
|
||||
.offset(LineCol { line: pos.line, col_utf16: pos.column });
|
||||
let file_postion = FilePosition { file_id, offset };
|
||||
|
||||
let res = do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
|
||||
if verbose {
|
||||
println!("\n{:#?}", res);
|
||||
if is_completion {
|
||||
let res =
|
||||
do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
|
||||
if verbose {
|
||||
println!("\n{:#?}", res);
|
||||
}
|
||||
} else {
|
||||
let res =
|
||||
do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_postion));
|
||||
if verbose {
|
||||
println!("\n{:#?}", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,13 +134,14 @@ fn main() -> Result<()> {
|
||||
let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default();
|
||||
let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?;
|
||||
let complete_path: Option<String> = 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<String> = 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)?;
|
||||
|
Loading…
Reference in New Issue
Block a user