From 28800c2a3b5571348f67ffaabc5e9bcc0c17185b Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 17 Sep 2025 12:09:15 +0200 Subject: [PATCH] languages: Fix panic in python lsp adapters assuming settings shape (#38309) Fixes ZED-1EV Fixes ZED-S0 Fixes ZED-Q9 Release Notes: - N/A --- crates/languages/src/python.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index d989f4d6dc22d2e58752d6d635b62091d8bd63d6..e0273250c91af8f437bff435d4a0f2f0c6467951 100644 --- a/crates/languages/src/python.rs +++ b/crates/languages/src/python.rs @@ -461,7 +461,7 @@ impl LspAdapter for PyrightLspAdapter { pet_core::python_environment::PythonEnvironment, >(toolchain.as_json.clone()) { - if user_settings.is_null() { + if !user_settings.is_object() { user_settings = Value::Object(serde_json::Map::default()); } let object = user_settings.as_object_mut().unwrap(); @@ -492,9 +492,13 @@ impl LspAdapter for PyrightLspAdapter { // Get or create the python section let python = object .entry("python") - .or_insert(Value::Object(serde_json::Map::default())) - .as_object_mut() - .unwrap(); + .and_modify(|v| { + if !v.is_object() { + *v = Value::Object(serde_json::Map::default()); + } + }) + .or_insert(Value::Object(serde_json::Map::default())); + let python = python.as_object_mut().unwrap(); // Set both pythonPath and defaultInterpreterPath for compatibility python.insert( @@ -1465,7 +1469,7 @@ impl LspAdapter for PyLspAdapter { // If user did not explicitly modify their python venv, use one from picker. if let Some(toolchain) = toolchain { - if user_settings.is_null() { + if !user_settings.is_object() { user_settings = Value::Object(serde_json::Map::default()); } let object = user_settings.as_object_mut().unwrap(); @@ -1787,7 +1791,7 @@ impl LspAdapter for BasedPyrightLspAdapter { pet_core::python_environment::PythonEnvironment, >(toolchain.as_json.clone()) { - if user_settings.is_null() { + if !user_settings.is_object() { user_settings = Value::Object(serde_json::Map::default()); } let object = user_settings.as_object_mut().unwrap();