3561: feat: add debug code lens r=matklad a=hdevalke Refs #3539 3577: Protect against infinite macro expansion in def collector r=edwin0cheng a=flodiebold Something I noticed while trying to make macro expansion more resilient against errors. There was a test for this, but it wasn't actually working because the first recursive expansion failed. (The comma...) Even with this limit, that test (when fixed) still takes some time to pass because of the exponential growth of the expansions, so I disabled it and added a different one without growth. CC @edwin0cheng Co-authored-by: Hannes De Valkeneer <hannes@de-valkeneer.be> Co-authored-by: hdevalke <2261239+hdevalke@users.noreply.github.com> Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
This commit is contained in:
@@ -19,50 +19,48 @@ impl CargoTargetSpec {
|
||||
pub(crate) fn runnable_args(
|
||||
spec: Option<CargoTargetSpec>,
|
||||
kind: &RunnableKind,
|
||||
) -> Result<Vec<String>> {
|
||||
let mut res = Vec::new();
|
||||
) -> Result<(Vec<String>, Vec<String>)> {
|
||||
let mut args = Vec::new();
|
||||
let mut extra_args = Vec::new();
|
||||
match kind {
|
||||
RunnableKind::Test { test_id } => {
|
||||
res.push("test".to_string());
|
||||
args.push("test".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut res);
|
||||
spec.push_to(&mut args);
|
||||
}
|
||||
res.push("--".to_string());
|
||||
res.push(test_id.to_string());
|
||||
extra_args.push(test_id.to_string());
|
||||
if let TestId::Path(_) = test_id {
|
||||
res.push("--exact".to_string());
|
||||
extra_args.push("--exact".to_string());
|
||||
}
|
||||
res.push("--nocapture".to_string());
|
||||
extra_args.push("--nocapture".to_string());
|
||||
}
|
||||
RunnableKind::TestMod { path } => {
|
||||
res.push("test".to_string());
|
||||
args.push("test".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut res);
|
||||
spec.push_to(&mut args);
|
||||
}
|
||||
res.push("--".to_string());
|
||||
res.push(path.to_string());
|
||||
res.push("--nocapture".to_string());
|
||||
extra_args.push(path.to_string());
|
||||
extra_args.push("--nocapture".to_string());
|
||||
}
|
||||
RunnableKind::Bench { test_id } => {
|
||||
res.push("bench".to_string());
|
||||
args.push("bench".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut res);
|
||||
spec.push_to(&mut args);
|
||||
}
|
||||
res.push("--".to_string());
|
||||
res.push(test_id.to_string());
|
||||
extra_args.push(test_id.to_string());
|
||||
if let TestId::Path(_) = test_id {
|
||||
res.push("--exact".to_string());
|
||||
extra_args.push("--exact".to_string());
|
||||
}
|
||||
res.push("--nocapture".to_string());
|
||||
extra_args.push("--nocapture".to_string());
|
||||
}
|
||||
RunnableKind::Bin => {
|
||||
res.push("run".to_string());
|
||||
args.push("run".to_string());
|
||||
if let Some(spec) = spec {
|
||||
spec.push_to(&mut res);
|
||||
spec.push_to(&mut args);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
Ok((args, extra_args))
|
||||
}
|
||||
|
||||
pub(crate) fn for_file(
|
||||
|
||||
@@ -55,6 +55,9 @@ pub struct ServerConfig {
|
||||
|
||||
/// Cargo feature configurations.
|
||||
pub cargo_features: CargoFeatures,
|
||||
|
||||
/// Enabled if the vscode_lldb extension is available.
|
||||
pub vscode_lldb: bool,
|
||||
}
|
||||
|
||||
impl Default for ServerConfig {
|
||||
@@ -76,6 +79,7 @@ impl Default for ServerConfig {
|
||||
additional_out_dirs: FxHashMap::default(),
|
||||
cargo_features: Default::default(),
|
||||
rustfmt_args: Vec::new(),
|
||||
vscode_lldb: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +189,7 @@ pub fn main_loop(
|
||||
all_targets: config.cargo_watch_all_targets,
|
||||
},
|
||||
rustfmt_args: config.rustfmt_args,
|
||||
vscode_lldb: config.vscode_lldb,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -381,6 +381,7 @@ pub fn handle_runnables(
|
||||
label,
|
||||
bin: "cargo".to_string(),
|
||||
args: check_args,
|
||||
extra_args: Vec::new(),
|
||||
env: FxHashMap::default(),
|
||||
cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
|
||||
});
|
||||
@@ -794,18 +795,35 @@ pub fn handle_code_lens(
|
||||
RunnableKind::Bin => "Run",
|
||||
}
|
||||
.to_string();
|
||||
let r = to_lsp_runnable(&world, file_id, runnable)?;
|
||||
let mut 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()]),
|
||||
arguments: Some(vec![to_value(&r).unwrap()]),
|
||||
}),
|
||||
data: None,
|
||||
};
|
||||
|
||||
lenses.push(lens);
|
||||
|
||||
if world.options.vscode_lldb {
|
||||
if r.args[0] == "run" {
|
||||
r.args[0] = "build".into();
|
||||
} else {
|
||||
r.args.push("--no-run".into());
|
||||
}
|
||||
let debug_lens = CodeLens {
|
||||
range: r.range,
|
||||
command: Some(Command {
|
||||
title: "Debug".into(),
|
||||
command: "rust-analyzer.debugSingle".into(),
|
||||
arguments: Some(vec![to_value(r).unwrap()]),
|
||||
}),
|
||||
data: None,
|
||||
};
|
||||
lenses.push(debug_lens);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle impls
|
||||
@@ -952,7 +970,7 @@ fn to_lsp_runnable(
|
||||
runnable: Runnable,
|
||||
) -> Result<req::Runnable> {
|
||||
let spec = CargoTargetSpec::for_file(world, file_id)?;
|
||||
let args = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
|
||||
let (args, extra_args) = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
|
||||
let line_index = world.analysis().file_line_index(file_id)?;
|
||||
let label = match &runnable.kind {
|
||||
RunnableKind::Test { test_id } => format!("test {}", test_id),
|
||||
@@ -965,6 +983,7 @@ fn to_lsp_runnable(
|
||||
label,
|
||||
bin: "cargo".to_string(),
|
||||
args,
|
||||
extra_args,
|
||||
env: {
|
||||
let mut m = FxHashMap::default();
|
||||
m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
|
||||
@@ -973,6 +992,7 @@ fn to_lsp_runnable(
|
||||
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
|
||||
|
||||
@@ -169,6 +169,7 @@ pub struct Runnable {
|
||||
pub label: String,
|
||||
pub bin: String,
|
||||
pub args: Vec<String>,
|
||||
pub extra_args: Vec<String>,
|
||||
pub env: FxHashMap<String, String>,
|
||||
pub cwd: Option<String>,
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ pub struct Options {
|
||||
pub inlay_hints: InlayHintsOptions,
|
||||
pub rustfmt_args: Vec<String>,
|
||||
pub cargo_watch: CheckOptions,
|
||||
pub vscode_lldb: bool,
|
||||
}
|
||||
|
||||
/// `WorldState` is the primary mutable state of the language server
|
||||
|
||||
Reference in New Issue
Block a user