X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Frust-analyzer%2Fcrates%2Frust-analyzer%2Fsrc%2Fhandlers.rs;h=8c3ea77d0611587c2f7f7b94083f5d4764d0cf6b;hb=3baf5f8d9a453767e349c2c080a907ee4100e8df;hp=e79cf3d3fd6e9ffe535e5ff9aee9f007c52ec157;hpb=c8e12cc8bf0de646234524924f39c85d9f3c7c37;p=rust.git diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs index e79cf3d3fd6..8c3ea77d061 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs @@ -10,8 +10,8 @@ use anyhow::Context; use ide::{ AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange, - HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SingleResolve, - SourceChange, TextEdit, + HoverAction, HoverGotoTypeData, Query, RangeInfo, ReferenceCategory, Runnable, RunnableKind, + SingleResolve, SourceChange, TextEdit, }; use ide_db::SymbolKind; use lsp_server::ErrorCode; @@ -1012,6 +1012,8 @@ pub(crate) fn handle_references( let _p = profile::span("handle_references"); let position = from_proto::file_position(&snap, params.text_document_position)?; + let exclude_imports = snap.config.find_all_refs_exclude_imports(); + let refs = match snap.analysis.find_all_refs(position, None)? { None => return Ok(None), Some(refs) => refs, @@ -1032,7 +1034,11 @@ pub(crate) fn handle_references( refs.references .into_iter() .flat_map(|(file_id, refs)| { - refs.into_iter().map(move |(range, _)| FileRange { file_id, range }) + refs.into_iter() + .filter(|&(_, category)| { + !exclude_imports || category != Some(ReferenceCategory::Import) + }) + .map(move |(range, _)| FileRange { file_id, range }) }) .chain(decl) }) @@ -1234,6 +1240,7 @@ pub(crate) fn handle_code_lens( annotate_references: lens_config.refs_adt, annotate_method_references: lens_config.method_refs, annotate_enum_variant_references: lens_config.enum_variant_refs, + location: lens_config.location.into(), }, file_id, )?; @@ -1283,7 +1290,7 @@ pub(crate) fn handle_document_highlight( .into_iter() .map(|ide::HighlightedRange { range, category }| lsp_types::DocumentHighlight { range: to_proto::range(&line_index, range), - kind: category.map(to_proto::document_highlight_kind), + kind: category.and_then(to_proto::document_highlight_kind), }) .collect(); Ok(Some(res)) @@ -1782,6 +1789,7 @@ fn run_rustfmt( let mut command = match snap.config.rustfmt() { RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => { let mut cmd = process::Command::new(toolchain::rustfmt()); + cmd.envs(snap.config.extra_env()); cmd.args(extra_args); // try to chdir to the file so we can respect `rustfmt.toml` // FIXME: use `rustfmt --config-path` once @@ -1839,6 +1847,7 @@ fn run_rustfmt( } RustfmtConfig::CustomCommand { command, args } => { let mut cmd = process::Command::new(command); + cmd.envs(snap.config.extra_env()); cmd.args(args); cmd }