Zed Improved. Aiming to improve upon Zed and make a truly delightful code editor.
https://zed.dev
![]() # Fix Python Virtual Environment Detection in Zed ## Problem Zed was not properly detecting Python virtual environments when a project didn't contain a `pyrightconfig.json` file. This caused Pyright (the Python language server) to report `reportMissingImports` errors for packages installed in virtual environments, even though the virtual environment was correctly set up and worked fine in other editors. The issue was that while Zed's `PythonToolchainProvider` correctly detected virtual environments, this information wasn't being communicated to Pyright in a format it could understand. ## Root Cause The main issue was in how Zed communicated virtual environment configuration to Pyright through the Language Server Protocol (LSP). When Pyright requests workspace configuration, it expects virtual environment settings (`venvPath` and `venv`) at the root level of the configuration object - the same format used in `pyrightconfig.json` files. However, Zed was attempting to place these settings in various nested locations that Pyright wasn't checking. ## Solution The fix involves several coordinated changes to ensure Pyright receives virtual environment configuration in all the ways it might expect: ### 1. Enhanced Workspace Configuration (`workspace_configuration` method) - When a virtual environment is detected, Zed now sets `venvPath` and `venv` at the root level of the configuration object, matching the exact format of a `pyrightconfig.json` file - Uses relative path `"."` when the virtual environment is located in the workspace root - Also sets `python.pythonPath` and `python.defaultInterpreterPath` for compatibility with different Pyright versions ### 2. Environment Variables for All Language Server Binaries - Updated `check_if_user_installed`, `fetch_server_binary`, `check_if_version_installed`, and `cached_server_binary` methods to include shell environment variables - This ensures environment variables like `VIRTUAL_ENV` are available to Pyright, helping with automatic virtual environment detection ### 3. Initialization Options - Added minimal initialization options to enable Pyright's automatic path searching and import completion features - Sets `autoSearchPaths: true` and `useLibraryCodeForTypes: true` to improve Pyright's ability to find packages ## Key Changes The workspace configuration now properly formats virtual environment configuration: - Root level: `venvPath` and `venv` (matches pyrightconfig.json format) - Python section: `pythonPath` and `defaultInterpreterPath` for interpreter paths ## Impact - Users no longer need to create a `pyrightconfig.json` file for virtual environment detection - Python projects with virtual environments in standard locations (`.venv`, `venv`, etc.) will work out of the box - Import resolution for packages installed in virtual environments now works correctly - Maintains compatibility with manual `pyrightconfig.json` configuration for complex setups ## Testing The changes were tested with Python projects using virtual environments without `pyrightconfig.json` files. Pyright now correctly resolves imports from packages installed in the virtual environment, eliminating the `reportMissingImports` errors. ## Release Notes - Fixed Python virtual environment detection when no `pyrightconfig.json` is present - Pyright now correctly resolves imports from packages installed in virtual environments (`.venv`, `venv`, etc.) - Python projects with virtual environments no longer show false `reportMissingImports` errors - Improved Python development experience with automatic virtual environment configuration --------- Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> |
||
---|---|---|
.cargo | ||
.cloudflare | ||
.config | ||
.github | ||
.zed | ||
assets | ||
crates | ||
docs | ||
extensions | ||
legal | ||
nix | ||
script | ||
tooling | ||
.clinerules | ||
.cursorrules | ||
.git-blame-ignore-revs | ||
.gitattributes | ||
.gitignore | ||
.mailmap | ||
.prettierrc | ||
.rules | ||
.windsurfrules | ||
Cargo.lock | ||
Cargo.toml | ||
CLAUDE.md | ||
clippy.toml | ||
CODE_OF_CONDUCT.md | ||
compose.yml | ||
CONTRIBUTING.md | ||
Cross.toml | ||
debug.plist | ||
default.nix | ||
docker-compose.sql | ||
Dockerfile-collab | ||
Dockerfile-collab.dockerignore | ||
Dockerfile-cross | ||
Dockerfile-cross.dockerignore | ||
Dockerfile-distros | ||
Dockerfile-distros.dockerignore | ||
flake.lock | ||
flake.nix | ||
LICENSE-AGPL | ||
LICENSE-APACHE | ||
LICENSE-GPL | ||
livekit.yaml | ||
Procfile | ||
Procfile.postgrest | ||
README.md | ||
renovate.json | ||
rust-toolchain.toml | ||
shell.nix | ||
typos.toml |
Zed
Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Installation
On macOS and Linux you can download Zed directly or install Zed via your local package manager.
Other platforms are not yet available:
- Windows (tracking issue)
- Web (tracking issue)
Developing Zed
- Building Zed for macOS
- Building Zed for Linux
- Building Zed for Windows
- Running Collaboration Locally
Contributing
See CONTRIBUTING.md for ways you can contribute to Zed.
Also... we're hiring! Check out our jobs page for open roles.
Licensing
License information for third party dependencies must be correctly provided for CI to pass.
We use cargo-about
to automatically comply with open source licenses. If CI is failing, check the following:
- Is it showing a
no license specified
error for a crate you've created? If so, addpublish = false
under[package]
in your crate's Cargo.toml. - Is the error
failed to satisfy license requirements
for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to theaccepted
array inscript/licenses/zed-licenses.toml
. - Is
cargo-about
unable to find the license for a dependency? If so, add a clarification field at the end ofscript/licenses/zed-licenses.toml
, as specified in the cargo-about book.