Nathaniel Knight

Reflections, diversions, and opinions from a progressive ex-physicist programmer dad with a sore back.

Setting Helix up as a Python IDE

This article describes how to get the Helix text editor set up to be a half-decent Python IDE. You'll need to know a little bit about the command line, but if you're using Helix you'll probably be fine.

Instructions

To assess how well Helix can support a particular language with the tools you already have, you can run:

hx --health python

Which will show you something like:

Configured language servers:
   pylsp: 'pylsp' not found in $PATH
Configured debug adapter: None
Configured formatter: None
Highlight queries: ✓
Textobject queries: ✓
Indent queries: 

Helix needs us to install a Python Language Server. Rather than putting tools in our global Python environment or re-installing everything for each project, we'll use Pipx to install it in its own virtualenv (npx is an analogous tool). If you don't have it installed, you can probably find instructions here.

With Pipx installed, first we'll install the Python LSP Server

pipx install python-lsp-server

Because it aims to support multiple tools for things like typechecking and formatting, pylsp uses plugins to support those features, which need to be installed as separate packages. Luckily, Pipx supports this fairly well with its inject command. For example, to add support for [Black] and [Ruff], we can run:

pipx inject python-lsp-server python-lsp-ruff python-lsp-black

Helix also requires a little bit of configuration in its languages file so that it can tell pylsp which plugins to use (on Mac OS and Linux, this file should be at ~/.config/helix/languages/toml):

[language-server.pylsp.config.pylsp]
plugins.ruff.enabled = true
plugins.black.enabled = true

With that, Helix should be a reasonably fully featured Python IDE.

Why do we need to do all this?

Rather than building plugins for each programming language, Helix embraces the Language Server Protocol. Helix doesn't know about refactoring, type inference, etc. It just knows how to speak LSP, and relies on a separate tool (a "language server") to provide all those nice features.

The downside of this approach is that the responsibility for providing a language server falls to the user. The benefit is that Helix, despite being a relatively new project, has out-of-the box integration with over 200 languages, from common ones like Python and TypeScript to more niche languages like Gleam, Ada, and Unison.

As I've been learning Helix I've been dreading the point where I had to do some customization to get some of the features I'm used to in an editor like VS Code. I'm not very fond of configuring text editors, having lost a great many focused hours to wrangling VimScript and Emacs Lisp so I wasn't looking forward to learning how Helix handles this, but I admit: setting Helix up this way was much easier than I was afraid it might be.