buzl.uk


Python virtual environments in Zed

Published on

#coding #python #zed #editor

I’ve been using Zed as my main editor for over a month now. The reason I switched from VSCode was that VSCode was too slow when I was working with multiple windows open. Switching back and forth between windows was creating a lag that was unbearable. I saw Zed as a lightweight and crazy fast alternative, and I wanted to give it a try. There were some problems however…

Python

Working with virtual environments right out of the box was not possible. Because Zed uses Microsoft’s Pyright language server, we have to add configurations for it based on its documentation. Usually, I name the virtual environment directory as env. So, keep that in mind when you’re changing the settings for yourself. Here’s what I did add in my settings.json file:

...
"lsp": {
    "pyright": {
        "settings": {
            "python": {
                "pythonPath": "env/bin/python",
                "venvPath": "."
            }
        }
    }
}
...

Both pythonPath and venvPath were necessary in my case.

Extra configurations

Besides setting options in the language server, we can directly add some extra configuration to Pyright using a pyrightconfig.json file in the root directory of your project. Here’s an example of what I’m using:

{
    "reportUnusedImport": true,
    "reportUnusedClass": true,
    "reportUnusedFunction": true,
    "reportUnusedVariable": true
}

I am using these settings to get warnings for unused things in my code. It’s a good way to keep your code small and clean. If you’re curious about other settings I’m using, check out my dotfiles for Zed. Thanks for reading!

kaangiray26

Webmentions