Post
More spelling in Helix: Codebook

Back in 20231, I wrote about using ltex-ls as a spell-checker in Helix. It was workable and powerful, but I found it slow and hard to configure.

A few months I was able to upgrade this to something leaner and faster: Codebook. It’s based on Spellbook, which (mildly ironically) was written during a push a year or so back for inbuilt spelling support in Helix that never quite came to pass.

I highly recommend it. Codebook is a code spell-checker, so it recognises coding idioms like snake_case_names and camelCaseNames, and uses tree-sitter so it’s sensitive to what the purpose of each token is — so it doesn’t flag keywords as bad spellings, for example. Codebook works great for markdown, too.

After the fold is my configuration for a few (programming) languages in British English.

Installing

To install Codebook, use cargo:

cargo install codebook-lsp

Running the same command will also update Codebook to the latest version.

What’s installed?

You can run cargo install --list to see what you have installed, in case you forget whether you installed codebook with cargo, brew or something else.

Configuring

Codebook relies on two configuration files:

  1. ~/.config/codebook/codebook.toml — stores global configuration.
  2. codebook.toml in your project root — stores project local configuration. For me that’s usually things like Go packages names.

Adding dictionaries is easy, unlike my experience with ltex-ls. Just add the following to ~/.config/codebook/codebook.toml:

dictionaries = ["en_us", "en_gb"]

Both global and project-specific codebook.toml files also contain the list of words that you’ve added to Codebook. Handily, they are kept in alphabetical order, which helps if you keep them in git. I keep most of my ~/.config files in git so this is a real help.

To configure Helix, in ~/.config/helix/languages.toml, I make use of Helix’s support for multiple language servers per language to add codebook:

# Add the Codebook language server
[language-server.codebook]
command = "codebook-lsp"
args = ["serve"]
config = {}

# Examples of enabling it for different languages:
[[language]]
name = "python"
language-servers = [ "pyright", "ruff", "codebook" ]

[[language]]
name="rust"
language-servers = [ "rust-analyzer", "codebook" ]

[[language]]
name = "go"
language-servers = [ "gopls", "codebook" ]

[[language]]
name = "markdown"
language-servers = [ "codebook" ]

Alongside this, I suggest setting Helix’s inline diagnostics to show only warnings or above. Otherwise Codebook spelling issues render at the end of every affected line, which can be overwhelming:

[editor]
end-of-line-diagnostics = "warning"

And that’s it. Happy coding!


  1. Gosh, two years ago! I’m somewhat surprised I’m still using Helix. Not because it’s not a good editor — it surely is — but because I’m quite flighty with editors. ↩︎

← Older
Exploring container networking with network namespaces