Zed MiniZinc #
A MiniZinc extension for Zed.
Features #
Syntax highlighting for MiniZinc (.mzn), DataZinc (.dzn), and FlatZinc (.fzn) using
shackle's tree-sitter grammars.
MiniZinc files also use shackle-ls for:
- diagnostics (errors and warnings)
- hover documentation
- go to definition and find references
- rename
- completion and signature help
- inlay hints
- semantic highlighting
- formatting
The extension adds an outline, auto-indent, a run button on solve, and tasks for solving and
compiling models. DataZinc and FlatZinc are highlight-only.
To distinguish par and var identifiers, enable semantic highlighting:
{
"languages": {
"MiniZinc": {
"semantic_tokens": "combined"
}
}
}
The formatter uses Zed's indentation settings and wraps at 100 columns.
The language server #
The extension uses the first available shackle-ls:
lsp.shackle-ls.binary.pathin Zed settings;shackle-lsonPATH;- the latest release from shackle's GitHub releases.
To pin a specific binary, add to your Zed settings:
{
"lsp": {
"shackle-ls": {
"binary": {
"path": "/path/to/shackle-ls"
}
}
}
}
Downloaded releases include the MiniZinc standard library and need no configuration. A locally
installed binary does not: expose Shackle's overlay beside the Cargo binary and set
MZN_STDLIB_DIR to MiniZinc's library (minizinc --config-dirs reports it as mznStdlibDir):
ln -s /path/to/shackle/share ~/.cargo/share
export MZN_STDLIB_DIR=/Applications/MiniZincIDE.app/Contents/Resources/share/minizinc
You can also set MZN_STDLIB_DIR under lsp.shackle-ls.binary.env. Reopen the project after
changing environment variables because Zed captures them when the project window opens. Use
RUST_LOG to adjust server logging.
Tasks #
The extension includes four tasks that require minizinc on PATH:
| Task | Command |
|---|---|
solve (also the ▶ next to the solve item) |
minizinc -s -i --solver "$MZN_SOLVER" model.mzn $MZN_DATA |
| solve, all solutions | as above, plus -a |
| compile to FlatZinc | minizinc -c -s --solver "$MZN_SOLVER" model.mzn $MZN_DATA |
| list available solvers | minizinc --solvers |
Set MZN_SOLVER to a solver ID (defaults to default) and MZN_DATA to one or more space-separated
data files. Reopen the project after changing them. For a one-off change, open task: spawn, select
a task, and press tab to edit its command. For fixed arguments, add a project task to
.zed/tasks.json:
[
{
"label": "solve kakuro with instance1",
"command": "minizinc",
"args": ["-s", "-i", "--solver", "chuffed", "kakuro.mzn", "data/instance1.dzn"]
}
]
Development #
cargo build --release --target wasm32-wasip2
Then use zed: install dev extension and select this directory.