Askama-analyzer brings LSP support to template files
A language server for askama templates provides completion, hover, go to definition, references, renames, errors and formatting inside templates, drawing from the rust-analyzer already running. The project powers zed-askama, a Zed extension. After spending time with non-react stacks out of curiosity, the axum/askama/datastar combination proved particularly compelling. With many templating alternatives to react, the type-safety that TSX provides gets left behind, and those ergonomics matter both for manual coding and AI-assisted work. The stack runs pleasant, blindingly fast and uses few resources. It is solid and renders server-side by default.
Until now, dropping into a template and editing it meant working blind. No more. With this language server and the Zed extension, full LSP support arrives for symbols, clicking through code, renaming, formatting and type/error checking using rust-analyzer.
How askama templates get type-safe editing
Askama compiles a template into Rust inside #[derive(Template)]. rust-analyzer analyses that expansion but cannot map it back to the template. A broken template shows up as one error on the struct, and the template itself gets no completion or navigation. Existing editor support either highlights only, or approximates askama's code generation by hand and misses whatever the approximation does not cover.
askama-analyzer runs askama's own code generator, keeps the template position of every token it generates, and asks rust-analyzer about the result. Answers come back in template positions, and they are the compiler's answers, because the code is the compiler's code.
What askama-analyzer actually does
The language server, check and fmt tools live in crates/askama-analyzer. A separate crate, askama-analyzer-codegen, runs askama's generator on one template item and maintains a map from every generated token to its template range. This mapping is what lets the server present template-accurate answers.
Releases ship archives for macOS (signed and notarised), Linux (static) and Windows, on x86_64 and arm64. Or build it yourself:
cargo install --locked --git https://github.com/radiosilence/askama-analyzer askama-analyzerIt needs rust-analyzer, from the client's initialization options or on the PATH.
Command-line tools
askama-analyzer
check[--rust-analyzer PATH] [--annotate][PATH]prints every template error in a Cargo workspace and exits 1 if any exist. askama's own errors need nothing else; given a rust-analyzer, it also reports the type errors rust-analyzer finds in the generated code, as an editor shows them.askama-analyzer
fmt[--check[--annotate]] [--max-width N] [--no-indent-html][PATH...]formats templates. The files given or every file in or under atemplatesdirectory gets processed. Expressions inside tags lay out as rustfmt does, breaking over lines when they pass--max-width(100 by default). A line still too long breaks inside the tags that run past the width. An askama tag too long for a line of its own puts its contents on lines of their own. In HTML templates a start tag that begins its line puts one attribute per line. A dense line with nothing long enough to break stays long. Whitespace inside a tag never renders. Nothing between tags or in text changes. Other templates' text never touches, since askama renders it byte for byte. Arrays of short simple items pack onto lines, as rustfmt packs them.The
--annotateflag prints check's errors, and each run offmt --checkwould change, as GitHub Actions annotations. So a workflow shows them on the pull request's diff; fmt's hold the formatted text.askama-analyzer
completions SHELLprints a completion script for bash, zsh, fish, elvish or PowerShell.HTML template indentation
HTML templates (.html, .htm, also with askama's .askama, .j2, .jinja, .jinja2 or .rinja suffix) re-indent by the nesting of elements and block tags. One level comes from the file's .editorconfig (indent_style, indent_size, tab_width), or 2 spaces when it says nothing; fmt and the editor both read it, so a file the editor formatted passes
fmt --check.Only the amount of whitespace starting each line changes, which HTML renders the same whatever its amount.
<pre>,<textarea>,<script>,<style>, raw blocks, and the bodies of filter and block let tags stay as written. So do the blocks a parent template renders inside one of those elements (or every block when the parent cannot be read). The one way the output can change: a macro or an included template rendered inside another file's<pre>, or an element styledwhite-space: pre. Where that matters, turn it off with--no-indent-htmlorformat.indentHtml: false.LSP integration beyond the editor
Anything else that speaks LSP can run askama-analyzer on stdio for template files. rust-analyzer's path, arguments, environment and settings can pass as
initializationOptions.rustAnalyzer(path,args,env,initializationOptions,settings). The formatter's settings asinitializationOptions.format:maxWidth(100 by default) andindentHtml(true by default; false leaves HTML templates' indentation outside tags as written).The plugin attaches to .html, .htm, .txt and .md files as well as .askama, since that is how templates are named. In a file no template struct reads, the server does nothing. It leaves .rs files to rust-analyzer.
Zed and Claude Code
Zed: the Askama extension downloads the server and passes it your rust-analyzer settings.
Claude Code: editors/claude-code gives Claude Code's LSP tool the server. After each edit to a template, Claude sees askama's and rust-analyzer's errors in it, and it can ask for definitions, references and types there.
Project structure and release process
crates/askama-analyzer The language server, check and fmt crates/askama-analyzer-codegen askama's generator run on one template item, with a map from every generated token to its template range editors/claude-code The Claude Code plugin radiosilence/askama askama with a small tooling feature for long-running use, described in ARCHITECTURE.md, which the crates build from vendor/askama-testing askama's own test suite at the pinned release, which the generator and the formatter are tested against docs/releasing.md How a release goes and the secrets it needs MIT, in LICENSE. vendor/askama-testing is askama's code under its own MIT or Apache-2.0 licence, kept beside it.
The repository uses a GitHub action that downloads a release, checks it against the release's SHA256SUMS, caches it, and runs
fmt --check --annotate(and, when asked,check --annotate), so unformatted runs of lines and template errors appear on the pull request's diff. For supply-chain security, pin this to a specific hash for a tag and update regularly. @main runs the action as it stands; a release tag (@v0.7.0) pins the action but not the binary, which version picks: latest by default, so CI runs what editors download, or a release such as 0.7.0 to pin it too. It needs bash, curl and tar (unzip on Windows), which GitHub's runners have; it needs no token, since releases are public. rust-analyzer gives check a rust-analyzer binary for type errors in the generated code. The step fails when either command finds something; the workflow's continue-on-error makes it advisory. It needs a release of 0.7.0 or later, the first with --annotate.Ending
With askama-analyzer and rust-analyzer in the shell path, templates get the same type-safety and navigation that code enjoys. The tooling is ready for anyone working with the axum/askama/datastar stack or any askama-based project.