A comprehensive Neovim plugin and Zig library for enhanced Zig development experience.
zig-lamp provides seamless ZLS (Zig Language Server) management for Neovim and powerful build.zig.zon parsing capabilities for Zig projects.
curl
and unzip
curl
and tar
{
"jinzhongjia/zig-lamp",
event = "VeryLazy",
build = ":ZigLamp build sync",
dependencies = {
"neovim/nvim-lspconfig",
"nvim-lua/plenary.nvim",
},
init = function()
-- Configuration options (all optional)
-- Timeout in milliseconds for automatic ZLS installation
-- Set to nil to disable auto-install
vim.g.zig_lamp_zls_auto_install = nil
-- Fallback to system ZLS if local version not found
-- Set to any non-negative value to enable
vim.g.zig_lamp_fall_back_sys_zls = nil
-- LSP configuration options passed to lspconfig
vim.g.zig_lamp_zls_lsp_opt = {}
-- UI customization
vim.g.zig_lamp_pkg_help_fg = "#CF5C00"
vim.g.zig_lamp_zig_fetch_timeout = 5000
end,
}
Important: Do not configure ZLS through lspconfig directly. zig-lamp handles ZLS setup automatically.
zig-lamp | Zig Version | Neovim |
---|---|---|
0.0.1 | 0.13.0 and earlier | 0.10+ |
latest | 0.14.0+ | 0.10+ |
:ZigLamp zls install
- Install ZLS matching current Zig version:ZigLamp zls uninstall
- Remove installed ZLS version:ZigLamp info
- Show project and toolchain information:ZigLamp pkg
- Open package manager interface:ZigLamp build [sync|async] [timeout]
- Build the zig-lamp libraryasync
(default) - Non-blocking build, returns immediatelysync [timeout]
- Blocking build with optional timeout in millisecondssync 20000
- Sync build with 20-second timeoutThe package manager provides an intuitive interface for managing Zig dependencies:
q
- Quit the package manageri
- Add or edit dependencyo
- Toggle between URL and local path dependencies<leader>r
- Reload from build.zig.zon filed
- Delete selected dependency or path<leader>s
- Save changes to build.zig.zon file# Recommended: Use specific commit instead of branch
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(.{});
// Add zig-lamp dependency
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,
});
// Import zig-lamp module
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 allocator = gpa.allocator();
// Parse build.zig.zon to JSON
const file = try std.fs.cwd().openFile("build.zig.zon", .{});
defer file.close();
var output = std.ArrayList(u8).init(allocator);
defer output.deinit();
try zigLamp.zig2json(
allocator,
file.reader().any(),
output.writer(),
void{},
.{ .file_name = "build.zig.zon" }
);
std.log.info("JSON output: {s}", .{output.items});
// Verify file hash
const digest = try zigLamp.sha256Digest(file);
std.log.info("SHA256: {}", .{std.fmt.fmtSliceHexLower(&digest)});
// Format ZON file
const source = "@import(\"std\")";
const formatted = try zigLamp.fmtZon(source, allocator);
defer allocator.free(formatted);
std.log.info("Formatted: {s}", .{formatted});
}
lua/zig-lamp/
├── core/ # Core functionality
│ ├── core_cmd.lua # Command system
│ ├── core_config.lua # Configuration management
│ ├── core_ffi.lua # FFI interface to Zig library
│ └── core_util.lua # Utility functions
├── info.lua # Information display
├── pkg/ # Package manager
├── zig/ # Zig integration
└── zls/ # ZLS management
src/
├── zig-lamp.zig # Main library interface
├── zon2json.zig # ZON to JSON parser
└── fmtzon.zig # ZON formatter
ZLS Not Found: Run :ZigLamp zls install
to download the appropriate ZLS version.
Build Failures: Ensure you have the required system tools (curl, unzip/tar) installed.
Library Crashes: If the Zig library causes Neovim crashes, please file an issue with:
Permission Errors: Make sure Neovim has write access to its data directory.
# Clone the repository
git clone https://github.com/jinzhongjia/zig-lamp.git
cd zig-lamp
# Build the library
zig build -Doptimize=ReleaseFast
# Run tests
zig build test
This project is open source. See the repository for license details.
Note: Since this plugin integrates with external libraries via FFI, stability depends on the Zig compilation target and C API compatibility. Please report any crashes or unexpected behavior.