Multiple binaries support for launch.json.

Generate unique names on the LSP side.
This commit is contained in:
vsrs 2020-05-14 16:02:01 +03:00
parent 5f6cdae18f
commit 20fdd14c62
2 changed files with 7 additions and 3 deletions

View file

@ -1011,6 +1011,7 @@ fn to_lsp_runnable(
runnable: Runnable, runnable: Runnable,
) -> Result<lsp_ext::Runnable> { ) -> Result<lsp_ext::Runnable> {
let spec = CargoTargetSpec::for_file(world, file_id)?; let spec = CargoTargetSpec::for_file(world, file_id)?;
let target = spec.as_ref().map(|s| s.target.clone());
let (args, extra_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 line_index = world.analysis().file_line_index(file_id)?;
let label = match &runnable.kind { let label = match &runnable.kind {
@ -1018,7 +1019,9 @@ fn to_lsp_runnable(
RunnableKind::TestMod { path } => format!("test-mod {}", path), RunnableKind::TestMod { path } => format!("test-mod {}", path),
RunnableKind::Bench { test_id } => format!("bench {}", test_id), RunnableKind::Bench { test_id } => format!("bench {}", test_id),
RunnableKind::DocTest { test_id, .. } => format!("doctest {}", test_id), RunnableKind::DocTest { test_id, .. } => format!("doctest {}", test_id),
RunnableKind::Bin => "run binary".to_string(), RunnableKind::Bin => {
target.map_or_else(|| "run binary".to_string(), |t| format!("run binary '{}'", t))
}
}; };
Ok(lsp_ext::Runnable { Ok(lsp_ext::Runnable {
range: to_proto::range(&line_index, runnable.range), range: to_proto::range(&line_index, runnable.range),

View file

@ -88,8 +88,9 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
} }
if (debugConfig.name === "run binary") { if (debugConfig.name === "run binary") {
// A workaround for multiple binaries. It would be better to get proper names on the LSP side. // The LSP side: crates\rust-analyzer\src\main_loop\handlers.rs,
debugConfig.name = `run binary [${path.basename(executable)}]`; // fn to_lsp_runnable(...) with RunnableKind::Bin
debugConfig.name = `run binary '${path.basename(executable)}'`;
} }
if (debugConfig.cwd) { if (debugConfig.cwd) {