feat(lsp): include lsp as subcommand

This commit is contained in:
Nurul Huda (Apon) 2026-03-22 04:27:57 +06:00
parent 51621e12ef
commit 4ad2bb1e3e
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
3 changed files with 17 additions and 21 deletions

View File

@ -60,6 +60,7 @@ pub fn build(b: *std.Build) !void {
// --- ZX CLI (Transpiler, Exporter, Dev Server) --- //
const zli_dep = b.dependency("zli", .{ .target = target, .optimize = optimize });
const zls_dep = b.dependency("zls", .{ .target = target, .optimize = optimize });
const exe_rootmod_opts: std.Build.Module.CreateOptions = .{
.root_source_file = b.path("src/main.zig"),
.target = target,
@ -67,27 +68,12 @@ pub fn build(b: *std.Build) !void {
.imports = &.{
.{ .name = "zx", .module = mod },
.{ .name = "zli", .module = zli_dep.module("zli") },
.{ .name = "zls", .module = zls_dep.module("zls") },
},
};
const exe = b.addExecutable(.{ .name = "zx", .root_module = b.createModule(exe_rootmod_opts) });
b.installArtifact(exe);
// --- ZXLS - LSP proxy for ZX files --- //
const zls_dep = b.dependency("zls", .{ .target = target, .optimize = optimize });
const zxls_exe = b.addExecutable(.{
.name = "zxls",
.root_module = b.createModule(.{
.root_source_file = b.path("src/lsp/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "zx", .module = mod },
.{ .name = "zls", .module = zls_dep.module("zls") },
},
}),
});
b.installArtifact(zxls_exe);
// --- Steps: Run --- //
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);

View File

@ -26,8 +26,8 @@
.cachez = .{ .path = "vendor/cachez" },
// Ziex Language Server utilities
.zls = .{
.url = "git+https://github.com/nurulhudaapon/lspz.git?ref=0.15.x#f91b2e1e305e5d5bd3725aea90f9f9bfb3dce055",
.hash = "zls-0.15.1-rmm5fgQ2JADjDh84Ja3pDBZ1io_kKdHS2YhQyvBYz66r",
.url = "git+https://github.com/ziex-dev/zls.git?ref=zx-0.15.1#6afd4d52580899022d24f41689781ec4a9350602",
.hash = "zls-0.15.1-rmm5fgg2JABtvFCDJk6Up7CuP4Khm62Li4NkCfwniFnU",
},
},
.paths = .{

View File

@ -1,7 +1,4 @@
pub fn main() !void {
if (builtin.os.tag == .wasi) return try main_wasm();
if (builtin.os.tag == .windows) _ = std.os.windows.kernel32.SetConsoleOutputCP(65001);
var dbg = std.heap.DebugAllocator(.{}).init;
const allocator = switch (builtin.mode) {
@ -11,6 +8,18 @@ pub fn main() !void {
defer if (builtin.mode == .Debug) std.debug.assert(dbg.deinit() == .ok);
var args = try std.process.argsWithAllocator(allocator);
_ = args.next();
const subcmd = args.next();
if (std.mem.eql(u8, subcmd orelse "", "lsp")) {
try lsp.main();
return;
}
if (builtin.os.tag == .wasi) return try main_wasm();
if (builtin.os.tag == .windows) _ = std.os.windows.kernel32.SetConsoleOutputCP(65001);
var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
var stdout = &stdout_writer.interface;
@ -82,6 +91,7 @@ const cli = @import("cli/root.zig");
const builtin = @import("builtin");
const zx = @import("zx");
const tui = @import("tui/main.zig");
const lsp = @import("lsp/main.zig");
pub const std_options = std.Options{
.log_scope_levels = &[_]std.log.ScopeLevel{