From 39c92b38726a4ca0e0e48198cbd5bdd82bbf2fb5 Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Thu, 12 Mar 2020 22:31:47 +0100 Subject: fixup! feat: add debug code lens autodetect vscode-lldb --- crates/rust-analyzer/src/config.rs | 4 +++ crates/rust-analyzer/src/main_loop.rs | 1 + crates/rust-analyzer/src/main_loop/handlers.rs | 34 ++++++++++++++------------ crates/rust-analyzer/src/world.rs | 1 + 4 files changed, 24 insertions(+), 16 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index a8bf29ddf..cfca06f56 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -51,6 +51,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 { @@ -70,6 +73,7 @@ impl Default for ServerConfig { additional_out_dirs: FxHashMap::default(), cargo_features: Default::default(), rustfmt_args: Vec::new(), + vscode_lldb: false, } } } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 4f7aac754..b4add046f 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -185,6 +185,7 @@ pub fn main_loop( all_targets: config.cargo_watch_all_targets, }, rustfmt_args: config.rustfmt_args, + vscode_lldb: config.vscode_lldb, } }; diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index f9715e675..571a896f3 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs @@ -805,23 +805,25 @@ pub fn handle_code_lens( }), data: None, }; - 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(lens); - lenses.push(debug_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 diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 9ef368529..a4fda9f80 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -37,6 +37,7 @@ pub struct Options { pub max_inlay_hint_length: Option, pub rustfmt_args: Vec, pub cargo_watch: CheckOptions, + pub vscode_lldb: bool, } /// `WorldState` is the primary mutable state of the language server -- cgit v1.2.3