Skip to content

Commit

Permalink
python: Adjust binary path based on OS (#22587)
Browse files Browse the repository at this point in the history
Closes #ISSUE

- #21452 

Describe the bug / provide steps to reproduce it

Language server error: pylsp

failed to spawn command. path:
"C:\Users\AppData\Local\Zed\languages\pylsp\pylsp-venv\bin\pylsp",
working directory: "D:\Coding\Python", args: []
-- stderr--

Environment
- Windows 11
- python

Release Notes:

- Windows: Fixed the path building used to run `pip` commands in the
venv generated on Windows 11.

---------

Co-authored-by: Marshall Bowers <[email protected]>
  • Loading branch information
TorratDev and maxdeviant authored Jan 3, 2025
1 parent e6fe12d commit 53cfb57
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/languages/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,12 @@ impl PyLspAdapter {
}
}

const BINARY_DIR: &str = if cfg!(target_os = "windows") {
"Scripts"
} else {
"bin"
};

#[async_trait(?Send)]
impl LspAdapter for PyLspAdapter {
fn name(&self) -> LanguageServerName {
Expand Down Expand Up @@ -811,7 +817,7 @@ impl LspAdapter for PyLspAdapter {
delegate: &dyn LspAdapterDelegate,
) -> Result<LanguageServerBinary> {
let venv = self.base_venv(delegate).await.map_err(|e| anyhow!(e))?;
let pip_path = venv.join("bin").join("pip3");
let pip_path = venv.join(BINARY_DIR).join("pip3");
ensure!(
util::command::new_smol_command(pip_path.as_path())
.arg("install")
Expand Down Expand Up @@ -842,7 +848,7 @@ impl LspAdapter for PyLspAdapter {
.success(),
"pylsp-mypy installation failed"
);
let pylsp = venv.join("bin").join("pylsp");
let pylsp = venv.join(BINARY_DIR).join("pylsp");
Ok(LanguageServerBinary {
path: pylsp,
env: None,
Expand All @@ -856,7 +862,7 @@ impl LspAdapter for PyLspAdapter {
delegate: &dyn LspAdapterDelegate,
) -> Option<LanguageServerBinary> {
let venv = self.base_venv(delegate).await.ok()?;
let pylsp = venv.join("bin").join("pylsp");
let pylsp = venv.join(BINARY_DIR).join("pylsp");
Some(LanguageServerBinary {
path: pylsp,
env: None,
Expand Down

0 comments on commit 53cfb57

Please sign in to comment.