Skip to content

Commit 84a76c0

Browse files
authored
update: support 0.14.0 (#10)
* update: support `0.14.0` * ci: remove 13 test
1 parent 5516efb commit 84a76c0

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
os: [ubuntu-latest]
20-
version: [0.13.0, master]
20+
version: [0.14.0, master]
2121
fail-fast: false
2222
runs-on: ${{ matrix.os }}
2323
steps:

build.zig.zon

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.{
2-
.name = "zig-lamp",
3-
.version = "0.0.1",
4-
.minimum_zig_version = "0.13.0",
2+
.name = .zig_lamp,
3+
.version = "0.0.2",
4+
.fingerprint = 0x519db185c03fa148,
5+
.minimum_zig_version = "0.14.0",
56
.dependencies = .{},
67
.paths = .{
78
"build.zig",

lua/zig-lamp/ffi.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ end
9292
--- @class ZigBuildZon
9393
--- @field name string
9494
--- @field version string
95+
--- @field fingerprint string
9596
--- @field minimum_zig_version string|nil
9697
--- @field dependencies { [string] : ZigDependency }
9798
--- @field paths string[]
@@ -110,10 +111,10 @@ function M.get_build_zon_info(file_path)
110111
if not _p:exists() then return nil end
111112

112113
local res = ffi.string(zig_lamp.get_build_zon_info(file_path))
113-
zig_lamp.free_build_zon_info()
114114
if res == "" then
115115
return nil
116116
end
117+
zig_lamp.free_build_zon_info()
117118
local _tmp = vim.fn.json_decode(res)
118119
return _tmp
119120
end
@@ -134,10 +135,10 @@ function M.fmt_zon(source_code)
134135
-- stylua: ignore
135136
if not zig_lamp then return nil end
136137
local res = ffi.string(zig_lamp.fmt_zon(source_code))
137-
zig_lamp.free_fmt_zon()
138138
if res == "" then
139139
return nil
140140
end
141+
zig_lamp.free_fmt_zon()
141142
return res
142143
end
143144

lua/zig-lamp/module/pkg.lua

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ local function render(ctx)
105105
col_end = str_len(version_str),
106106
})
107107

108+
-- for fingerprint
109+
local fingerprint_str = "  Fingerprint: "
110+
table.insert(content, fingerprint_str .. (zon_info.fingerprint or "[none]"))
111+
current_lnum = current_lnum + 1
112+
table.insert(highlight, {
113+
group = "Title",
114+
line = current_lnum,
115+
col_start = 0,
116+
col_end = str_len(fingerprint_str),
117+
})
118+
108119
local min_version = zon_info.minimum_zig_version or "[none]"
109120
local min_version_str = "  Minimum zig version: "
110121
table.insert(content, min_version_str .. min_version)
@@ -258,6 +269,8 @@ local function delete_cb(ctx)
258269
end
259270
lnum = lnum - 4
260271

272+
lnum = lnum - 1
273+
261274
if
262275
ctx.zon_info.paths
263276
and #ctx.zon_info.paths > 0
@@ -341,6 +354,24 @@ local edit_cb = function(ctx)
341354
end
342355
lnum = lnum - 1
343356

357+
-- for fingerprint
358+
if lnum - 1 == 0 then
359+
vim.ui.input({
360+
prompt = "Enter value for fingerprint: ",
361+
default = ctx.zon_info.fingerprint,
362+
}, function(input)
363+
-- stylua: ignore
364+
if not input then return end
365+
if input == "" then
366+
ctx.zon_info.fingerprint = nil
367+
else
368+
ctx.zon_info.fingerprint = input
369+
end
370+
render(ctx)
371+
end)
372+
end
373+
lnum = lnum - 1
374+
344375
-- for minimum zig version
345376
if lnum - 1 == 0 then
346377
vim.ui.input({
@@ -349,7 +380,11 @@ local edit_cb = function(ctx)
349380
}, function(input)
350381
-- stylua: ignore
351382
if not input then return end
352-
ctx.zon_info.minimum_zig_version = input
383+
if input == "" then
384+
ctx.zon_info.minimum_zig_version = nil
385+
else
386+
ctx.zon_info.minimum_zig_version = input
387+
end
353388
render(ctx)
354389
end)
355390
return
@@ -595,6 +630,8 @@ local function switch_cb(ctx)
595630
lnum = lnum - 1
596631
-- for version
597632
lnum = lnum - 1
633+
-- for fingerprint
634+
lnum = lnum - 1
598635
-- for minimum zig version
599636
lnum = lnum - 1
600637

@@ -644,8 +681,6 @@ local function switch_cb(ctx)
644681
return
645682
end
646683

647-
print(input)
648-
649684
if not is_url then
650685
local _hash = get_hash(input)
651686
if _hash then

lua/zig-lamp/util.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ end
5656
function M.wrap_j2zon(info)
5757
local res = ""
5858
res = res .. ".{"
59-
res = res .. ".name = " .. M.data2zon(info.name or "") .. ","
59+
res = res .. ".name = ." .. (info.name or "") .. ","
6060
res = res .. ".version = " .. M.data2zon(info.version or "") .. ","
61-
-- stylua: ignore
62-
res = res .. ".minimum_zig_version = " .. M.data2zon(info.minimum_zig_version or "") .. ","
61+
res = res .. ".fingerprint = " .. info.fingerprint .. ","
62+
if info.minimum_zig_version then
63+
-- stylua: ignore
64+
res = res .. ".minimum_zig_version = " .. M.data2zon(info.minimum_zig_version or "") .. ","
65+
end
6366
-- stylua: ignore
6467
res = res .. ".dependencies = ".. M.data2zon(info.dependencies or {}) .. ","
6568
res = res .. ".paths=" .. M.data2zon(info.paths or {}) .. ","

src/zon2json.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ fn stringify(allocator: std.mem.Allocator, writer: anytype, ast: std.zig.Ast, id
4545
if (try stringifyFieldName(allocator, ast, idx)) |name| {
4646
defer allocator.free(name);
4747
try writer.print("{s}:", .{name});
48+
if (std.mem.eql(u8, name, "\"fingerprint\"")) {
49+
const slice = ast.tokenSlice(ast.nodes.items(.main_token)[idx]);
50+
51+
const v = try std.fmt.allocPrint(allocator, "\"{s}\"", .{slice});
52+
defer allocator.free(v);
53+
54+
try writer.writeAll(v);
55+
return;
56+
}
4857
}
4958
}
5059

0 commit comments

Comments
 (0)