1667: Show backtraces in lens runnables r=matklad a=SomeoneToIgnore



Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
bors[bot] 2019-08-12 10:33:59 +00:00
commit cce31580e1

View file

@ -9,7 +9,7 @@ use lsp_types::{
TextEdit, WorkspaceEdit,
};
use ra_ide_api::{
AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind,
AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, Runnable, RunnableKind,
};
use ra_prof::profile;
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@ -325,27 +325,7 @@ pub fn handle_runnables(
continue;
}
}
let args = runnable_args(&world, file_id, &runnable.kind)?;
let r = req::Runnable {
range: runnable.range.conv_with(&line_index),
label: match &runnable.kind {
RunnableKind::Test { name } => format!("test {}", name),
RunnableKind::TestMod { path } => format!("test-mod {}", path),
RunnableKind::Bench { name } => format!("bench {}", name),
RunnableKind::Bin => "run binary".to_string(),
},
bin: "cargo".to_string(),
args,
env: {
let mut m = FxHashMap::default();
m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
m
},
cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
};
res.push(r);
res.push(to_lsp_runnable(&world, file_id, runnable)?);
}
let mut check_args = vec!["check".to_string()];
let label;
@ -693,34 +673,20 @@ pub fn handle_code_lens(
let line_index = world.analysis().file_line_index(file_id)?;
let mut lenses: Vec<CodeLens> = Default::default();
let workspace_root = world.workspace_root_for(file_id);
// Gather runnables
for runnable in world.analysis().runnables(file_id)? {
let title = match &runnable.kind {
RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("Run Test"),
RunnableKind::Bench { .. } => Some("Run Bench"),
RunnableKind::Bin => Some("Run"),
};
if let Some(title) = title {
let args = runnable_args(&world, file_id, &runnable.kind)?;
let range = runnable.range.conv_with(&line_index);
// This represents the actual command that will be run.
let r: req::Runnable = req::Runnable {
range,
label: Default::default(),
bin: "cargo".into(),
args,
env: Default::default(),
cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
};
RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "Run Test",
RunnableKind::Bench { .. } => "Run Bench",
RunnableKind::Bin => "Run",
}
.to_string();
let r = to_lsp_runnable(&world, file_id, runnable)?;
let lens = CodeLens {
range,
range: r.range,
command: Some(Command {
title: title.into(),
title,
command: "rust-analyzer.runSingle".into(),
arguments: Some(vec![to_value(r).unwrap()]),
}),
@ -729,7 +695,6 @@ pub fn handle_code_lens(
lenses.push(lens);
}
}
// Handle impls
lenses.extend(
@ -856,6 +821,32 @@ pub fn publish_decorations(
Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? })
}
fn to_lsp_runnable(
world: &WorldSnapshot,
file_id: FileId,
runnable: Runnable,
) -> Result<req::Runnable> {
let args = runnable_args(world, file_id, &runnable.kind)?;
let line_index = world.analysis().file_line_index(file_id)?;
let label = match &runnable.kind {
RunnableKind::Test { name } => format!("test {}", name),
RunnableKind::TestMod { path } => format!("test-mod {}", path),
RunnableKind::Bench { name } => format!("bench {}", name),
RunnableKind::Bin => "run binary".to_string(),
};
Ok(req::Runnable {
range: runnable.range.conv_with(&line_index),
label,
bin: "cargo".to_string(),
args,
env: {
let mut m = FxHashMap::default();
m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
m
},
cwd: world.workspace_root_for(file_id).map(|root| root.to_string_lossy().to_string()),
})
}
fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result<Vec<Decoration>> {
let line_index = world.analysis().file_line_index(file_id)?;
let res = world