Setting Up Odin Language Support in Doom Emacs

Introduction

Odin is a systems programming language designed as a modern alternative to C. This guide will walk you through setting up Odin language support in Doom Emacs:

  • Syntax highlighting via tree-sitter
  • LSP integration for code completion, diagnostics, and go-to-definition

Prerequisites

  • Doom Emacs installed and configured
  • The Odin compiler installed

Configuration

init.el

First, ensure you have LSP and tree-sitter enabled in your init.el. Find the :tools section and make sure these modules are uncommented:

:tools
  lsp
  (tree-sitter +langs)

packages.el

Next, install odin-ts-mode, a tree-sitter based major mode for Odin. Add this to your packages.el:

(package! odin-ts-mode
  :recipe (:host github :repo "Sampie159/odin-ts-mode"))

config.el

Finally, configure the mode and hook it up to LSP in your config.el:

(use-package! odin-ts-mode
  :mode "\\.odin\\'")

(add-hook 'odin-ts-mode-hook #'lsp-deferred)

After making these changes, run doom sync to install the new package.

Installing OLS (Odin Language Server)

For LSP features to work, you need OLS (Odin Language Server) installed and accessible in your PATH.

Note: On macOS, I encountered an issue where Emacs couldn't find the OLS binary. The fix was to create a symlink to the location where lsp-mode expects it:

sudo ln -s $(which ols) ~/.emacs.d/.local/etc/lsp/ols/latest/ols-arm64-darwin

Verification

Open an .odin file. Syntax highlighting should be enabled, "odin" LSP indicator in your modeline should be present. The following log should show up in the Messages:

LSP :: Connected to [ols:57853/starting /Users/marcin/proj/odin/test].
LSP :: ols:57853 initialized successfully in folders: (/Users/marcin/proj/odin/test)

Go to definition, etc. should work now.

mqdr


2025-12-28