# elsmith: an Emacs Lisp LSP server written in Rust

Date: 2026-12-02
Updated: 2026-12-02
Tags: emacs, emacs-lisp, rust, lean, lsp, formal-verification, release, rust-elsmith, lean-leanfran, lean-leanassay, rust-lsp-touchstone
URL: https://s.conao3.com/blog/2026/68dcf3
Author: conao3 (Naoya Yamashita)

I built elsmith, an Emacs Lisp LSP server written in Rust.
Rust handles everyday operations like completion, hover, and go-to-definition in a few milliseconds, while a disposable `emacs -Q --batch` process runs only for loading the standard library and checking files on save.

The server ships as a standalone binary, so you get editing support on machines without Emacs.
On machines with Emacs installed, elsmith adds standard function metadata and byte-compilation diagnostics on save.
Emacs, VS Code, Neovim, Vim, and Helix all connect to the same binary.

The repository is [conao3/rust-elsmith](https://github.com/conao3/rust-elsmith) under Apache-2.0.
This post covers [v0.1.1](https://github.com/conao3/rust-elsmith/releases/tag/v0.1.1), and the crate documentation lives on [docs.rs](https://docs.rs/elsmith/0.1.1).

[conao3/rust-elsmith](https://github.com/conao3/rust-elsmith): A fast Emacs Lisp language server written in Rust

![img](https://s.conao3.com/img/27ed9e-banner.png)

# Why I built it

Emacs has completion, definition lookup, and Flymake built in, yet those tools run inside Emacs alone.
Outside Emacs, in editors like VS Code or Neovim, options were limited to [Ellsp](https://github.com/elisp-lsp/Ellsp), which runs inside Emacs and assumes Eask, or [Elsa](https://github.com/emacs-elsa/Elsa), a static analyzer rather than an LSP server.

I maintain [vowls.el](https://github.com/conao3/vowls.el), an asynchronous LSP client for Emacs.
Having an Emacs Lisp server under my control makes client development and testing much easier.
I also wanted to test both sides against each other with [lsp-touchstone](https://s.conao3.com/blog/2026/45f8b5), a strict LSP checker I built earlier.

Pairing the two under `lsp-touchstone` caught a protocol bug in `vowls.el`, which sent `nil` for an optional argument; I fixed that in [this commit](https://github.com/conao3/vowls.el/commit/2fe1267fae431f668c57735f1acde8599f84f5b5).
Both implementations now pass `lsp-touchstone` with zero errors and zero warnings, and `vowls.el` sets elsmith in its [default server configuration](https://github.com/conao3/vowls.el/blob/e37f1ba1c34ba92119541fa5560e424af7c46700/vowls.el#L58-L59).

# Install and usage

elsmith supports go-to-definition, references, completion, hover, signature help, rename, and indentation formatting.
Rust returns static diagnostics as you type, and trusted projects add Emacs byte-compile and Checkdoc findings on save.

Install elsmith with Nix or Cargo.

```bash
nix profile add github:conao3/rust-elsmith
cargo install elsmith --locked
```

Point your editor at `elsmith server run-server`.
With `vowls.el` in Emacs, a single hook line connects the buffer.

```elisp
(add-hook 'emacs-lisp-mode-hook #'vowls-ensure)
```

Neovim assigns the `lisp` filetype to both Emacs Lisp and Common Lisp, so match `.el` files when starting the server.

```lua
vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
  pattern = "*.el",
  callback = function(event)
    vim.lsp.start({
      name = "elsmith",
      cmd = { "elsmith", "server", "run-server" },
      root_dir = vim.fs.root(event.buf, { "elsmith.toml", ".git" })
        or vim.fs.dirname(vim.api.nvim_buf_get_name(event.buf)),
      get_language_id = function() return "emacs-lisp" end,
    }, { bufnr = event.buf })
  end,
})
```

Setup examples for VS Code, Vim, Helix, Eglot, and lsp-mode live in [Editor setup in the README](https://github.com/conao3/rust-elsmith#editor-setup).

# Splitting work between Rust and Emacs

Starting `emacs -Q --batch` on GNU Emacs 31.1 takes a median of 62.1 ms, so spawning Emacs on completion or hover makes typing feel sluggish.
Byte-compiling a 28 KB file took a median of 132.9 ms, which works well for a disposable background run on save.

Spawning a fresh process per save also prevents stale Emacs state from skewing later checks.
Rust answers interactive editing requests, while batch Emacs handles standard-library collection and save-time checks.

![img](https://s.conao3.com/img/68dcf3-architecture.svg)

On first run, `emacs -Q --batch` collects standard functions, variables, and macros into a local cache, and Rust reads that cache on later runs.
That pass also extracts standard `.el.gz` files into the cache, so jumping to a standard definition from VS Code or Neovim opens a readable file.

# Emacs Lisp analysis and safe execution

Emacs Lisp is a Lisp-2 with separate namespaces for variables and functions, so rename and reference lookup keep them separate.
Renaming the local variable `f` in the expression below updates only the binding and the value reference `f`, leaving the call `(f)`, function reference `#'f`, and quoted `'f` intact.

```elisp
(let ((f 1))
  (list f (f) #'f 'f))
```

The Rust parser covers Emacs Lisp reader syntax and parses all 1,674 files in the Emacs 31.1 standard library with zero errors.
Tests also verify that incremental parsing matches a full reparse across random edits.

Handling of `lexical-binding` at the top of a file follows Emacs load rules, and I checked symbol role classification against Emacs 31.1 `elisp-scope.el`.

Security shaped the design as well.
Byte compilation and macro expansion run project code, so opening a repository triggers no Emacs evaluation, and Rust reads project config files as plain data.
Projects that need save-time checks or macro expansion opt in with the command below.

```bash
elsmith trust add-root --path /path/to/project
```

Unregistered projects still run the initial cache build outside the workspace, reading only Emacs's own standard library.

# Lean 4 proofs and verification

LSP servers often hide subtle bugs in character-position math and protocol state transitions.
I wrote 23 pure functions in Lean 4 covering position conversion, request lifecycle, Lisp-2 resolution and rename checks, and discarding stale diagnostics, then proved their properties.
My tool [leanfran](https://s.conao3.com/blog/2026/21ebbd) generates the Rust code from those functions.

I audited the proofs with [leanassay](https://s.conao3.com/blog/2026/e3d3ca), which tested 337 mutants and found zero proof holes.
Integration tests and `lsp-touchstone` check the parts outside Lean, including parsing, transport, and Emacs process handling.

I also tested elsmith against real editors: Emacs with `vowls.el`, Eglot, and `lsp-mode`, plus VS Code, Neovim, Vim, and Helix.

# Response time

I measured stdio latency on an Intel Core i5-8400 Linux machine using Emacs 31.1 and a release build against the 23-file [vowls.el](https://github.com/conao3/vowls.el/tree/a1727c661ba1362c6bdcf86e2f157acf820c184e) repository.
Each metric uses 25 samples for median or p95, aside from the single-run initial cache build.

![img](https://s.conao3.com/img/68dcf3-slo.svg)

<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">

<colgroup>
<col  class="org-left" />

<col  class="org-left" />

<col  class="org-left" />

<col  class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Metric</th>
<th scope="col" class="org-left">Statistic</th>
<th scope="col" class="org-left">Measured</th>
<th scope="col" class="org-left">Target</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">Cached initialize</td>
<td class="org-left">Median</td>
<td class="org-left">1.7 ms</td>
<td class="org-left">&lt; 30 ms</td>
</tr>

<tr>
<td class="org-left">Initial cache build</td>
<td class="org-left">1 run</td>
<td class="org-left">1,383 ms</td>
<td class="org-left">&lt; 2,000 ms</td>
</tr>

<tr>
<td class="org-left">Edit to static diagnostics</td>
<td class="org-left">p95</td>
<td class="org-left">4.9 ms</td>
<td class="org-left">&lt; 5 ms</td>
</tr>

<tr>
<td class="org-left">Completion (idle)</td>
<td class="org-left">p95</td>
<td class="org-left">0.7 ms</td>
<td class="org-left">&lt; 10 ms</td>
</tr>

<tr>
<td class="org-left">Hover (idle)</td>
<td class="org-left">p95</td>
<td class="org-left">0.3 ms</td>
<td class="org-left">&lt; 10 ms</td>
</tr>

<tr>
<td class="org-left">Definition (idle)</td>
<td class="org-left">p95</td>
<td class="org-left">0.3 ms</td>
<td class="org-left">&lt; 10 ms</td>
</tr>

<tr>
<td class="org-left">Semantic tokens (idle)</td>
<td class="org-left">p95</td>
<td class="org-left">4.3 ms</td>
<td class="org-left">&lt; 10 ms</td>
</tr>

<tr>
<td class="org-left">Completion (during compile)</td>
<td class="org-left">p95</td>
<td class="org-left">0.8 ms</td>
<td class="org-left">&lt; 25 ms</td>
</tr>

<tr>
<td class="org-left">Hover (during compile)</td>
<td class="org-left">p95</td>
<td class="org-left">0.3 ms</td>
<td class="org-left">&lt; 25 ms</td>
</tr>

<tr>
<td class="org-left">Definition (during compile)</td>
<td class="org-left">p95</td>
<td class="org-left">0.4 ms</td>
<td class="org-left">&lt; 25 ms</td>
</tr>

<tr>
<td class="org-left">Semantic tokens (during compile)</td>
<td class="org-left">p95</td>
<td class="org-left">4.8 ms</td>
<td class="org-left">&lt; 25 ms</td>
</tr>

<tr>
<td class="org-left">Save-time byte-compile</td>
<td class="org-left">p95</td>
<td class="org-left">336.2 ms</td>
<td class="org-left">&lt; 400 ms</td>
</tr>
</tbody>
</table>

All 12 metrics stay inside their targets; even during a background byte-compile, completion finishes in 0.8 ms, hover in 0.3 ms, and definition lookup in 0.4 ms.
Cached startup takes around 1.4 ms, so editing feels responsive.

# Conclusion

I built elsmith so Emacs Lisp works over LSP in whichever editor you prefer.
Install it with Nix or Cargo and try it on your `.el` files.

Emacs `vowls.el` connects out of the box, and editor configs plus CLI commands live in the [conao3/rust-elsmith README](https://github.com/conao3/rust-elsmith).
