mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Apply suggestions from code review
This commit is contained in:
parent
9b4256dc4d
commit
b7db9f058a
@ -17,6 +17,7 @@ use crate::{
|
|||||||
runnables::runnable,
|
runnables::runnable,
|
||||||
FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
|
FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
|
||||||
};
|
};
|
||||||
|
use test_utils::mark;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct HoverConfig {
|
pub struct HoverConfig {
|
||||||
@ -202,10 +203,9 @@ fn runnable_action(
|
|||||||
ModuleDef::Function(it) => {
|
ModuleDef::Function(it) => {
|
||||||
let src = it.source(sema.db);
|
let src = it.source(sema.db);
|
||||||
if src.file_id != file_id.into() {
|
if src.file_id != file_id.into() {
|
||||||
// Don't try to find runnables in a macro generated code.
|
mark::hit!(hover_macro_generated_struct_fn_doc_comment);
|
||||||
// See tests below:
|
mark::hit!(hover_macro_generated_struct_fn_doc_attr);
|
||||||
// test_hover_macro_generated_struct_fn_doc_comment
|
|
||||||
// test_hover_macro_generated_struct_fn_doc_attr
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1121,6 +1121,8 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_macro_generated_struct_fn_doc_comment() {
|
fn test_hover_macro_generated_struct_fn_doc_comment() {
|
||||||
|
mark::check!(hover_macro_generated_struct_fn_doc_comment);
|
||||||
|
|
||||||
check_hover_result(
|
check_hover_result(
|
||||||
r#"
|
r#"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
@ -1147,6 +1149,8 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hover_macro_generated_struct_fn_doc_attr() {
|
fn test_hover_macro_generated_struct_fn_doc_attr() {
|
||||||
|
mark::check!(hover_macro_generated_struct_fn_doc_attr);
|
||||||
|
|
||||||
check_hover_result(
|
check_hover_result(
|
||||||
r#"
|
r#"
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
|
@ -408,7 +408,7 @@ pub fn handle_runnables(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.push(to_proto::runnable(&snap, file_id, &runnable)?);
|
res.push(to_proto::runnable(&snap, file_id, runnable)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add `cargo check` and `cargo test` for the whole package
|
// Add `cargo check` and `cargo test` for the whole package
|
||||||
@ -818,7 +818,7 @@ pub fn handle_code_lens(
|
|||||||
|
|
||||||
let action = runnable.action();
|
let action = runnable.action();
|
||||||
let range = to_proto::range(&line_index, runnable.nav.range());
|
let range = to_proto::range(&line_index, runnable.nav.range());
|
||||||
let r = to_proto::runnable(&snap, file_id, &runnable)?;
|
let r = to_proto::runnable(&snap, file_id, runnable)?;
|
||||||
if snap.config.lens.run {
|
if snap.config.lens.run {
|
||||||
let lens = CodeLens {
|
let lens = CodeLens {
|
||||||
range,
|
range,
|
||||||
@ -830,7 +830,7 @@ pub fn handle_code_lens(
|
|||||||
|
|
||||||
if action.debugee && snap.config.lens.debug {
|
if action.debugee && snap.config.lens.debug {
|
||||||
let debug_lens =
|
let debug_lens =
|
||||||
CodeLens { range, command: Some(debug_single_command(r)), data: None };
|
CodeLens { range, command: Some(debug_single_command(&r)), data: None };
|
||||||
lenses.push(debug_lens);
|
lenses.push(debug_lens);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1142,7 +1142,7 @@ fn run_single_command(runnable: &lsp_ext::Runnable, title: &str) -> Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_single_command(runnable: lsp_ext::Runnable) -> Command {
|
fn debug_single_command(runnable: &lsp_ext::Runnable) -> Command {
|
||||||
Command {
|
Command {
|
||||||
title: "Debug".into(),
|
title: "Debug".into(),
|
||||||
command: "rust-analyzer.debugSingle".into(),
|
command: "rust-analyzer.debugSingle".into(),
|
||||||
@ -1183,26 +1183,25 @@ fn show_impl_command_link(
|
|||||||
fn to_runnable_action(
|
fn to_runnable_action(
|
||||||
snap: &GlobalStateSnapshot,
|
snap: &GlobalStateSnapshot,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
runnable: &Runnable,
|
runnable: Runnable,
|
||||||
) -> Option<lsp_ext::CommandLinkGroup> {
|
) -> Option<lsp_ext::CommandLinkGroup> {
|
||||||
let cargo_spec = CargoTargetSpec::for_file(&snap, file_id).ok()?;
|
let cargo_spec = CargoTargetSpec::for_file(&snap, file_id).ok()?;
|
||||||
if should_skip_target(runnable, cargo_spec.as_ref()) {
|
if should_skip_target(&runnable, cargo_spec.as_ref()) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let action: &'static _ = runnable.action();
|
||||||
to_proto::runnable(snap, file_id, runnable).ok().map(|r| {
|
to_proto::runnable(snap, file_id, runnable).ok().map(|r| {
|
||||||
let mut group = lsp_ext::CommandLinkGroup::default();
|
let mut group = lsp_ext::CommandLinkGroup::default();
|
||||||
|
|
||||||
let action = runnable.action();
|
|
||||||
if snap.config.hover.run {
|
if snap.config.hover.run {
|
||||||
let run_command = run_single_command(&r, action.run_title);
|
let run_command = run_single_command(&r, action.run_title);
|
||||||
group.commands.push(to_command_link(run_command, r.label.clone()));
|
group.commands.push(to_command_link(run_command, r.label.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if snap.config.hover.debug {
|
if snap.config.hover.debug {
|
||||||
let hint = r.label.clone();
|
let dbg_command = debug_single_command(&r);
|
||||||
let dbg_command = debug_single_command(r);
|
group.commands.push(to_command_link(dbg_command, r.label));
|
||||||
group.commands.push(to_command_link(dbg_command, hint));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group
|
group
|
||||||
@ -1222,7 +1221,7 @@ fn prepare_hover_actions(
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(|it| match it {
|
.filter_map(|it| match it {
|
||||||
HoverAction::Implementaion(position) => show_impl_command_link(snap, position),
|
HoverAction::Implementaion(position) => show_impl_command_link(snap, position),
|
||||||
HoverAction::Runnable(r) => to_runnable_action(snap, file_id, r),
|
HoverAction::Runnable(r) => to_runnable_action(snap, file_id, r.clone()),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@ -1232,10 +1231,7 @@ fn should_skip_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>)
|
|||||||
RunnableKind::Bin => {
|
RunnableKind::Bin => {
|
||||||
// Do not suggest binary run on other target than binary
|
// Do not suggest binary run on other target than binary
|
||||||
match &cargo_spec {
|
match &cargo_spec {
|
||||||
Some(spec) => match spec.target_kind {
|
Some(spec) => spec.target_kind != TargetKind::Bin,
|
||||||
TargetKind::Bin => false,
|
|
||||||
_ => true,
|
|
||||||
},
|
|
||||||
None => true,
|
None => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -656,14 +656,14 @@ pub(crate) fn resolved_code_action(
|
|||||||
pub(crate) fn runnable(
|
pub(crate) fn runnable(
|
||||||
snap: &GlobalStateSnapshot,
|
snap: &GlobalStateSnapshot,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
runnable: &Runnable,
|
runnable: Runnable,
|
||||||
) -> Result<lsp_ext::Runnable> {
|
) -> Result<lsp_ext::Runnable> {
|
||||||
let spec = CargoTargetSpec::for_file(snap, file_id)?;
|
let spec = CargoTargetSpec::for_file(snap, file_id)?;
|
||||||
let target = spec.as_ref().map(|s| s.target.clone());
|
let target = spec.as_ref().map(|s| s.target.clone());
|
||||||
let (cargo_args, executable_args) =
|
let (cargo_args, executable_args) =
|
||||||
CargoTargetSpec::runnable_args(spec, &runnable.kind, &runnable.cfg_exprs)?;
|
CargoTargetSpec::runnable_args(spec, &runnable.kind, &runnable.cfg_exprs)?;
|
||||||
let label = runnable.label(target);
|
let label = runnable.label(target);
|
||||||
let location = location_link(snap, None, runnable.nav.clone())?;
|
let location = location_link(snap, None, runnable.nav)?;
|
||||||
|
|
||||||
Ok(lsp_ext::Runnable {
|
Ok(lsp_ext::Runnable {
|
||||||
label,
|
label,
|
||||||
|
Loading…
Reference in New Issue
Block a user