Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(debugger): evaluate console input as expressions under CodeLLDB (#1375)

l0ng-ai8021a8cccaad
diff --git a/crates/ide-dap/src/lib.rs b/crates/ide-dap/src/lib.rs
index 1be662390..36601c40b 100644
--- a/crates/ide-dap/src/lib.rs
+++ b/crates/ide-dap/src/lib.rs
@@ -651,8 +651,19 @@ impl DebugManager {
{
arguments["project"] = json!(real);
}
- if config.adapter == "codelldb" && arguments.get("sourceLanguages").is_none() {
- arguments["sourceLanguages"] = json!(["rust"]);
+ if config.adapter == "codelldb" {
+ if arguments.get("sourceLanguages").is_none() {
+ arguments["sourceLanguages"] = json!(["rust"]);
+ }
+ // The Debug Console and Evaluate Expression take expressions, as with every other
+ // debugger; LLDB commands still run with a leading backtick.
+ match arguments.get_mut("_adapterSettings") {
+ None => arguments["_adapterSettings"] = json!({"consoleMode": "evaluate"}),
+ Some(Value::Object(settings)) => {
+ settings.entry("consoleMode").or_insert_with(|| json!("evaluate"));
+ }
+ Some(_) => {}
+ }
}
let port = debug_server.map(|s| s.port);
self.start_session(id, owner, config.name, config.adapter, None, config.request, arguments, spec, port).await
diff --git a/crates/ide-dap/src/tests.rs b/crates/ide-dap/src/tests.rs
index 996c6f68e..b7316019d 100644
--- a/crates/ide-dap/src/tests.rs
+++ b/crates/ide-dap/src/tests.rs
@@ -698,6 +698,37 @@ async fn js_debug_launch_gets_port_and_workspace_folder() {
assert_eq!(launch["type"], "pwa-node");
}
+/// CodeLLDB treats console input as LLDB commands unless told otherwise: Evaluate Expression
+/// and the Debug Console send expressions, so its console evaluates them. A launch
+/// configuration that picks a console mode keeps it.
+#[tokio::test]
+async fn codelldb_console_evaluates_expressions() {
+ let launch_with = |extra: Value| async move {
+ let h = harness(Script::default());
+ let config = LaunchConfig {
+ name: "demo".into(),
+ adapter: "codelldb".into(),
+ request: "launch".into(),
+ program: Some("/p/target/debug/demo".into()),
+ args: vec![],
+ cwd: Some("/p".into()),
+ env: BTreeMap::new(),
+ extra_json: Some(extra.to_string()),
+ };
+ h.start(config).await.unwrap();
+ h.request("launch")["arguments"].clone()
+ };
+ let launch = launch_with(json!({})).await;
+ assert_eq!(launch["_adapterSettings"]["consoleMode"], "evaluate");
+ assert_eq!(launch["sourceLanguages"], json!(["rust"]));
+
+ let launch =
+ launch_with(json!({"_adapterSettings": {"consoleMode": "commands", "showDisassembly": "never"}})).await;
+ assert_eq!(launch["_adapterSettings"], json!({"consoleMode": "commands", "showDisassembly": "never"}));
+ let launch = launch_with(json!({"_adapterSettings": {"showDisassembly": "never"}})).await;
+ assert_eq!(launch["_adapterSettings"], json!({"consoleMode": "evaluate", "showDisassembly": "never"}));
+}
+
/// An adapter that is already listening (java-debug inside jdtls): the client
/// connects over TCP to the `debugServer` port instead of spawning anything.
#[tokio::test]