@@ -7,6 +7,15 @@ _G.h = h
7
7
8
8
local ns = a .create_namespace ' ghostzig'
9
9
h .ghostpath = vim .fn .stdpath ' run' .. ' /ghostzig_' .. vim .fn .getpid ()
10
+ h .ghostcmd = nil
11
+ h .ghostargs = {}
12
+
13
+ h .ghosted_bufs = {} -- bufs which might have stale diags
14
+
15
+ a .create_autocmd ({' TextChanged' , ' TextChangedI' }, {
16
+ pattern = " *.zig" ;
17
+ callback = function () h .ghostbuild () end ;
18
+ })
10
19
11
20
function h .ghostwrite ()
12
21
bufname = vim .fn .fnamemodify (vim .fn .bufname (), ' :.' )
@@ -21,7 +30,8 @@ function h.ghostwrite()
21
30
ghostpipe :close ()
22
31
end
23
32
24
- function h .ghostbuild (entrypoint , test )
33
+ function h .ghostbuild ()
34
+ if h .ghostcmd == nil then return end -- disabled
25
35
if h .state == " running" or h .state == " throttled" then
26
36
-- require'luadev'.print("THROTTLE")
27
37
h .state = " throttled"
@@ -30,13 +40,11 @@ function h.ghostbuild(entrypoint, test)
30
40
h .state = " running"
31
41
h .ghostwrite ()
32
42
33
- local subcmd = test and ' test' or ' build-exe'
34
- args = { subcmd , ' -lc' , ' -fno-emit-bin' , h .ghostpath .. ' /' .. entrypoint }
35
43
local start_time = vim .fn .reltime ()
36
44
-- require'luadev'.print("START")
37
45
local job = Job :new {
38
- command = ' zig ' ;
39
- args = args ;
46
+ command = h . ghostcmd ;
47
+ args = h . ghostargs ;
40
48
on_exit = vim .schedule_wrap (function (j , ret )
41
49
local time = vim .fn .reltime (start_time )
42
50
local lines = j :stderr_result ()
@@ -65,7 +73,7 @@ function h.ghostbuild(entrypoint, test)
65
73
66
74
if h .state == " throttled" then
67
75
h .state = nil
68
- h .ghostbuild (entrypoint )
76
+ h .ghostbuild (command , args )
69
77
else
70
78
h .state = " done"
71
79
end
86
94
87
95
function h .ghostzig (entrypoint , test )
88
96
cwd = vim .fn .getcwd ()
89
- h .ghosted_bufs = {}
90
97
-- TODO: only .zig files?
91
98
vim .fn .system ({' mkdir' , ' -p' , h .ghostpath })
92
99
vim .fn .system ({' cp' , ' -r' , cwd .. ' /src' , h .ghostpath .. ' /src' })
93
- a .create_autocmd ({' TextChanged' , ' TextChangedI' }, {
94
- pattern = " *.zig" ;
95
- callback = function () h .ghostbuild (entrypoint , test ) end ;
96
- })
100
+
101
+ local command = ' zig'
102
+ local subcmd = test and ' test' or ' build-exe'
103
+ args = { subcmd , ' -lc' , ' -fno-emit-bin' , h .ghostpath .. ' /' .. entrypoint }
104
+
97
105
end
98
106
return h
0 commit comments