mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Merge #1667
1667: Show backtraces in lens runnables r=matklad a=SomeoneToIgnore Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
commit
cce31580e1
1 changed files with 43 additions and 52 deletions
|
@ -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,42 +673,27 @@ 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"),
|
||||
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: r.range,
|
||||
command: Some(Command {
|
||||
title,
|
||||
command: "rust-analyzer.runSingle".into(),
|
||||
arguments: Some(vec![to_value(r).unwrap()]),
|
||||
}),
|
||||
data: None,
|
||||
};
|
||||
|
||||
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()),
|
||||
};
|
||||
|
||||
let lens = CodeLens {
|
||||
range,
|
||||
command: Some(Command {
|
||||
title: title.into(),
|
||||
command: "rust-analyzer.runSingle".into(),
|
||||
arguments: Some(vec![to_value(r).unwrap()]),
|
||||
}),
|
||||
data: None,
|
||||
};
|
||||
|
||||
lenses.push(lens);
|
||||
}
|
||||
lenses.push(lens);
|
||||
}
|
||||
|
||||
// Handle impls
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue