A Tiny VS Code Extension for KiCad Custom Design Rules

View on GitHub

Table of contents

Overview

Just shipped a small Visual Studio Code extension: KiCad Custom Design Rules. Source on GitHub at Cimos/vscode-kicad-dru. It adds proper syntax highlighting and snippets for .kicad_dru files in VS Code, and nothing else. Specifically nothing else — more on that below.

Marketplace ID: cimos.kicad-dru. MIT-licensed. Currently v0.0.1.

Why this exists

KiCad’s only built-in editor for custom design rules is the single-line textbox in Board Setup → Custom Rules, plus a Check Rule Syntax button. That’s fine for a one-liner. The moment your DRU file has more than two or three rules — multi-class clearance, manufacturer-specific via stacks, a stack of disallow constraints — you want a real editor. Multi-cursor. Search. Folding. Colour that distinguishes a condition operator from an A.NetClass accessor from a layer name from a string literal.

The KiCad forums make the demand obvious. There’s a long-running megathread where people post DRU snippets and ask grammar questions, and at least one user spelled it out plainly: “externally I have a better text editor with syntax highlight and the possibility to search things and multiple cursors.” They were clearly already editing in VS Code; the editor just wasn’t doing anything useful.

The closest existing extension is DanielMeza.kicad-syntax-highlighter. It declares .kicad_dru in its file-extension list, but the underlying grammar is a generic KiCad s-expression highlighter — keywords like condition, constraint, disallow, A.NetClass, intersectsArea all colour as plain atoms. Functionally you get matched parens and not much else. oaslananka.kicadstudio is the heavyweight all-in-one, and it does great workspace-level things, but it doesn’t ship a TextMate grammar that knows the DRU sub-language either.

Nobody had bothered to write a grammar tuned to DRU specifically. So I did.

What it does

That’s the entire v0.0.1 surface. No extension.js, no activation event, no LSP, no telemetry. Just static JSON contributions: a TextMate grammar, a snippet file, and a language config. It loads when you open a .kicad_dru and does nothing the rest of the time.

What it doesn’t do

Worth being explicit, because the existing KiCad extensions on the marketplace tend to over-promise:

Install

From the VS Code Marketplace:

ext install cimos.kicad-dru

…or search for “KiCad Custom Design Rules” in the Extensions view.

A .vsix is also attached to each GitHub release if you’d rather sideload:

code --install-extension vscode-kicad-dru-<version>.vsix

Pairing it with KiCad

KiCad ≥ 7 has Preferences → Configure Paths → External Tools. Point it at VS Code’s executable and you get one-click round trips: open the .kicad_dru file from the PCB editor, edit it here, save, switch back, re-run Check Rule Syntax. That’s the workflow this extension is built around.

What’s next

The big-ticket items for v0.1.x:

If you hit a real .kicad_dru file the highlighter mangles, open an issue with a minimal snippet and I’ll take a look. PRs welcome too — DRU corner cases are exactly the kind of thing a small fixture catches and prose review misses.

-SM

Related