Auto-fix clippy::collapsible_if violations (#36428)
Release Notes: - N/A
This commit is contained in:
@@ -338,31 +338,31 @@ impl LspAdapter for PythonLspAdapter {
|
||||
let interpreter_path = toolchain.path.to_string();
|
||||
|
||||
// Detect if this is a virtual environment
|
||||
if let Some(interpreter_dir) = Path::new(&interpreter_path).parent() {
|
||||
if let Some(venv_dir) = interpreter_dir.parent() {
|
||||
// Check if this looks like a virtual environment
|
||||
if venv_dir.join("pyvenv.cfg").exists()
|
||||
|| venv_dir.join("bin/activate").exists()
|
||||
|| venv_dir.join("Scripts/activate.bat").exists()
|
||||
{
|
||||
// Set venvPath and venv at the root level
|
||||
// This matches the format of a pyrightconfig.json file
|
||||
if let Some(parent) = venv_dir.parent() {
|
||||
// Use relative path if the venv is inside the workspace
|
||||
let venv_path = if parent == adapter.worktree_root_path() {
|
||||
".".to_string()
|
||||
} else {
|
||||
parent.to_string_lossy().into_owned()
|
||||
};
|
||||
object.insert("venvPath".to_string(), Value::String(venv_path));
|
||||
}
|
||||
if let Some(interpreter_dir) = Path::new(&interpreter_path).parent()
|
||||
&& let Some(venv_dir) = interpreter_dir.parent()
|
||||
{
|
||||
// Check if this looks like a virtual environment
|
||||
if venv_dir.join("pyvenv.cfg").exists()
|
||||
|| venv_dir.join("bin/activate").exists()
|
||||
|| venv_dir.join("Scripts/activate.bat").exists()
|
||||
{
|
||||
// Set venvPath and venv at the root level
|
||||
// This matches the format of a pyrightconfig.json file
|
||||
if let Some(parent) = venv_dir.parent() {
|
||||
// Use relative path if the venv is inside the workspace
|
||||
let venv_path = if parent == adapter.worktree_root_path() {
|
||||
".".to_string()
|
||||
} else {
|
||||
parent.to_string_lossy().into_owned()
|
||||
};
|
||||
object.insert("venvPath".to_string(), Value::String(venv_path));
|
||||
}
|
||||
|
||||
if let Some(venv_name) = venv_dir.file_name() {
|
||||
object.insert(
|
||||
"venv".to_owned(),
|
||||
Value::String(venv_name.to_string_lossy().into_owned()),
|
||||
);
|
||||
}
|
||||
if let Some(venv_name) = venv_dir.file_name() {
|
||||
object.insert(
|
||||
"venv".to_owned(),
|
||||
Value::String(venv_name.to_string_lossy().into_owned()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1519,31 +1519,31 @@ impl LspAdapter for BasedPyrightLspAdapter {
|
||||
let interpreter_path = toolchain.path.to_string();
|
||||
|
||||
// Detect if this is a virtual environment
|
||||
if let Some(interpreter_dir) = Path::new(&interpreter_path).parent() {
|
||||
if let Some(venv_dir) = interpreter_dir.parent() {
|
||||
// Check if this looks like a virtual environment
|
||||
if venv_dir.join("pyvenv.cfg").exists()
|
||||
|| venv_dir.join("bin/activate").exists()
|
||||
|| venv_dir.join("Scripts/activate.bat").exists()
|
||||
{
|
||||
// Set venvPath and venv at the root level
|
||||
// This matches the format of a pyrightconfig.json file
|
||||
if let Some(parent) = venv_dir.parent() {
|
||||
// Use relative path if the venv is inside the workspace
|
||||
let venv_path = if parent == adapter.worktree_root_path() {
|
||||
".".to_string()
|
||||
} else {
|
||||
parent.to_string_lossy().into_owned()
|
||||
};
|
||||
object.insert("venvPath".to_string(), Value::String(venv_path));
|
||||
}
|
||||
if let Some(interpreter_dir) = Path::new(&interpreter_path).parent()
|
||||
&& let Some(venv_dir) = interpreter_dir.parent()
|
||||
{
|
||||
// Check if this looks like a virtual environment
|
||||
if venv_dir.join("pyvenv.cfg").exists()
|
||||
|| venv_dir.join("bin/activate").exists()
|
||||
|| venv_dir.join("Scripts/activate.bat").exists()
|
||||
{
|
||||
// Set venvPath and venv at the root level
|
||||
// This matches the format of a pyrightconfig.json file
|
||||
if let Some(parent) = venv_dir.parent() {
|
||||
// Use relative path if the venv is inside the workspace
|
||||
let venv_path = if parent == adapter.worktree_root_path() {
|
||||
".".to_string()
|
||||
} else {
|
||||
parent.to_string_lossy().into_owned()
|
||||
};
|
||||
object.insert("venvPath".to_string(), Value::String(venv_path));
|
||||
}
|
||||
|
||||
if let Some(venv_name) = venv_dir.file_name() {
|
||||
object.insert(
|
||||
"venv".to_owned(),
|
||||
Value::String(venv_name.to_string_lossy().into_owned()),
|
||||
);
|
||||
}
|
||||
if let Some(venv_name) = venv_dir.file_name() {
|
||||
object.insert(
|
||||
"venv".to_owned(),
|
||||
Value::String(venv_name.to_string_lossy().into_owned()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user