mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +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,
|
TextEdit, WorkspaceEdit,
|
||||||
};
|
};
|
||||||
use ra_ide_api::{
|
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_prof::profile;
|
||||||
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
|
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
|
||||||
|
@ -325,27 +325,7 @@ pub fn handle_runnables(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
res.push(to_lsp_runnable(&world, file_id, runnable)?);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
let mut check_args = vec!["check".to_string()];
|
let mut check_args = vec!["check".to_string()];
|
||||||
let label;
|
let label;
|
||||||
|
@ -693,34 +673,20 @@ pub fn handle_code_lens(
|
||||||
let line_index = world.analysis().file_line_index(file_id)?;
|
let line_index = world.analysis().file_line_index(file_id)?;
|
||||||
|
|
||||||
let mut lenses: Vec<CodeLens> = Default::default();
|
let mut lenses: Vec<CodeLens> = Default::default();
|
||||||
let workspace_root = world.workspace_root_for(file_id);
|
|
||||||
|
|
||||||
// Gather runnables
|
// Gather runnables
|
||||||
for runnable in world.analysis().runnables(file_id)? {
|
for runnable in world.analysis().runnables(file_id)? {
|
||||||
let title = match &runnable.kind {
|
let title = match &runnable.kind {
|
||||||
RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("▶️Run Test"),
|
RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️Run Test",
|
||||||
RunnableKind::Bench { .. } => Some("Run Bench"),
|
RunnableKind::Bench { .. } => "Run Bench",
|
||||||
RunnableKind::Bin => Some("️Run"),
|
RunnableKind::Bin => "Run",
|
||||||
};
|
}
|
||||||
|
.to_string();
|
||||||
if let Some(title) = title {
|
let r = to_lsp_runnable(&world, file_id, runnable)?;
|
||||||
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 {
|
let lens = CodeLens {
|
||||||
range,
|
range: r.range,
|
||||||
command: Some(Command {
|
command: Some(Command {
|
||||||
title: title.into(),
|
title,
|
||||||
command: "rust-analyzer.runSingle".into(),
|
command: "rust-analyzer.runSingle".into(),
|
||||||
arguments: Some(vec![to_value(r).unwrap()]),
|
arguments: Some(vec![to_value(r).unwrap()]),
|
||||||
}),
|
}),
|
||||||
|
@ -729,7 +695,6 @@ pub fn handle_code_lens(
|
||||||
|
|
||||||
lenses.push(lens);
|
lenses.push(lens);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Handle impls
|
// Handle impls
|
||||||
lenses.extend(
|
lenses.extend(
|
||||||
|
@ -856,6 +821,32 @@ pub fn publish_decorations(
|
||||||
Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? })
|
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>> {
|
fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result<Vec<Decoration>> {
|
||||||
let line_index = world.analysis().file_line_index(file_id)?;
|
let line_index = world.analysis().file_line_index(file_id)?;
|
||||||
let res = world
|
let res = world
|
||||||
|
|
Loading…
Reference in a new issue