A Neovim plugin and Zig library that streamlines Zig development with ZLS management, build.zig.zon parsing/formatting, and convenient build integration.
build.zig.zon
(paths, dependencies, hash, lazy), with automatic URL hash retrievalplenary.nvim
(required), nvim-lspconfig
(needed for Neovim without built‑in LSP config; on 0.11+ the plugin prefers the built‑in vim.lsp.config
/vim.lsp.enable
)curl
, unzip
curl
, tar
{
"jinzhongjia/zig-lamp",
event = "VeryLazy",
-- Optional but recommended: build the local FFI lib to enable faster/safer verification & formatting
build = ":ZigLampBuild async",
dependencies = {
"nvim-lua/plenary.nvim",
-- For Neovim < 0.11 you’ll likely want lspconfig
"neovim/nvim-lspconfig",
},
init = function()
-- Backward-compatible global vars (all optional)
-- Auto-install ZLS: timeout in milliseconds; set to nil to disable
vim.g.zig_lamp_zls_auto_install = nil
-- Fallback to system zls when no local match is found
vim.g.zig_lamp_fall_back_sys_zls = nil
-- Extra LSP options merged into defaults
vim.g.zig_lamp_zls_lsp_opt = {}
-- ZLS server settings (overrides built-in recommendations)
vim.g.zig_lamp_zls_settings = {}
-- Help text color for the package panel
vim.g.zig_lamp_pkg_help_fg = "#CF5C00"
-- Timeout (ms) used by `zig fetch` when retrieving url hashes
vim.g.zig_lamp_zig_fetch_timeout = 5000
end,
}
Tip: Do not set up ZLS in lspconfig yourself. zig-lamp will auto‑match and start ZLS as you open Zig buffers (on Neovim 0.11+ it prefers the built‑in LSP APIs).
All commands are rooted at :ZigLamp
(hierarchical subcommands with completion) plus one standalone command :ZigLampBuild
.
:ZigLamp info
— open the info panel:ZigLamp health
— run health checks (zig/curl/unzip|tar/lspconfig/native lib):ZigLamp build [--args…]
— run zig build
in the current Zig project (arguments are forwarded as‑is):ZigLamp test [--args…]
— run zig build test
in the current Zig project:ZigLamp clean
— remove zig-out
and zig-cache
in the current project:ZigLamp zls install
— download and install the ZLS version compatible with the current zig version
:ZigLamp zls uninstall <version>
— uninstall a local ZLS version (with completion):ZigLamp zls status
— show ZLS status (local versions, system zls availability, current LSP version, etc.):ZigLamp pkg
— open the package manager panel (view/edit build.zig.zon
)Standalone:
:ZigLampBuild [async|sync] [timeout_ms]
— build the plugin’s native library in the plugin root (ReleaseFast by default).q
— quiti
— add/edito
— toggle dependency type (url/path)<leader>r
— reload from filed
— delete path or dependency<leader>s
— save back to build.zig.zon
(formatted automatically)zig version
from a local DBzls
via the built‑in LSP (Neovim 0.11+) or lspconfig
fallbackunzip
, non‑Windows uses tar
zls.json
exists at project root, it is passed to ZLS automaticallyzig-lamp now automatically applies recommended ZLS settings without requiring a zls.json
file. Built-in settings include:
Override defaults via vim.g.zig_lamp_zls_settings
:
-- Example: Performance optimization (large projects)
vim.g.zig_lamp_zls_settings = {
zls = {
skip_std_references = true, -- Skip standard library references
semantic_tokens = "partial", -- Reduce semantic analysis
}
}
-- Example: Minimal UI (reduce distractions)
vim.g.zig_lamp_zls_settings = {
zls = {
warn_style = false, -- Disable style warnings
inlay_hints_show_variable_type_hints = false, -- Hide variable type hints
}
}
zls.json
(highest priority)vim.g.zig_lamp_zls_settings
user configurationThe repo also provides a Zig module for ZON parsing/formatting.
# Recommended: pin a specific commit or archived artifact
zig fetch --save https://github.com/jinzhongjia/zig-lamp/archive/main.tar.gz
# Alternative: Git URL (requires git)
zig fetch --save git+https://github.com/jinzhongjia/zig-lamp
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const zig_lamp = b.dependency("zig-lamp", .{ .target = target, .optimize = optimize });
const exe = b.addExecutable(.{
.name = "your-app",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zigLamp", zig_lamp.module("zigLamp"));
b.installArtifact(exe);
}
const std = @import("std");
const zigLamp = @import("zigLamp");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit();
const alloc = gpa.allocator();
// Parse build.zig.zon to JSON
const file = try std.fs.cwd().openFile("build.zig.zon", .{}); defer file.close();
var out = std.ArrayList(u8).init(alloc); defer out.deinit();
try zigLamp.zig2json(alloc, file.reader().any(), out.writer(), void{}, .{ .file_name = "build.zig.zon" });
std.log.info("JSON: {s}", .{out.items});
// Format ZON
const source = ".{ .name = .zig_lamp }";
const formatted = try zigLamp.fmtZon(source, alloc); defer alloc.free(formatted);
std.log.info("Formatted: {s}", .{formatted});
}
Note: checksum verification is exposed to Neovim via FFI (check_shasum
) and is not currently part of the public Zig API.
0.1.0
0.15.1+
0.10+
(on 0.11+ the built‑in LSP API is used):ZigLamp zls install
, or set vim.g.zig_lamp_fall_back_sys_zls = 1
to allow falling back to system zls:ZigLampBuild sync
, then restart Neovim; on Windows the lib resides in zig-out/bin
, on Unix‑like systems in zig-out/lib
curl
and the appropriate extractor are installed (unzip
on Windows, tar
on non‑Windows):ZigLamp health
# Build the plugin library (native)
zig build -Doptimize=ReleaseFast
# Run tests
zig build test