@@ -2,17 +2,16 @@ local util = require 'utility'
2
2
local scope = require ' workspace.scope'
3
3
local guide = require ' parser.guide'
4
4
local files = require ' files'
5
- local ws = require ' workspace'
6
5
--- @class vm
7
6
local vm = require ' vm.vm'
8
7
9
8
--- @class vm.global.link
10
9
--- @field sets parser.object[]
10
+ --- @field hasGet boolean ?
11
11
12
12
--- @class vm.global
13
13
--- @field links table<uri , vm.global.link>
14
14
--- @field setsCache ? table<uri , parser.object[]>
15
- --- @field getsCache ? table<uri , parser.object[]>
16
15
--- @field cate vm.global.cate
17
16
local mt = {}
18
17
mt .__index = mt
@@ -30,6 +29,12 @@ function mt:addSet(uri, source)
30
29
self .setsCache = nil
31
30
end
32
31
32
+ --- @param uri uri
33
+ function mt :addGet (uri )
34
+ local link = self .links [uri ]
35
+ link .hasGet = true
36
+ end
37
+
33
38
--- @param suri uri
34
39
--- @return parser.object[]
35
40
function mt :getSets (suri )
85
90
function mt :dropUri (uri )
86
91
self .links [uri ] = nil
87
92
self .setsCache = nil
88
- self .getsCache = nil
89
93
end
90
94
91
95
--- @return string
@@ -174,6 +178,7 @@ local compilerGlobalSwitch = util.switch()
174
178
return
175
179
end
176
180
local global = vm .declareGlobal (' variable' , name , uri )
181
+ global :addGet (uri )
177
182
source ._globalNode = global
178
183
179
184
local nxt = source .next
@@ -231,6 +236,7 @@ local compilerGlobalSwitch = util.switch()
231
236
end
232
237
local uri = guide .getUri (source )
233
238
local global = vm .declareGlobal (' variable' , name , uri )
239
+ global :addGet (uri )
234
240
source ._globalNode = global
235
241
236
242
local nxt = source .next
@@ -255,6 +261,8 @@ local compilerGlobalSwitch = util.switch()
255
261
if source .node .special == ' rawset' then
256
262
global :addSet (uri , source )
257
263
source .value = source .args [3 ]
264
+ else
265
+ global :addGet (uri )
258
266
end
259
267
source ._globalNode = global
260
268
@@ -353,13 +361,15 @@ local compilerGlobalSwitch = util.switch()
353
361
return
354
362
end
355
363
local type = vm .declareGlobal (' type' , name , uri )
364
+ type :addGet (uri )
356
365
source ._globalNode = type
357
366
end )
358
367
: case ' doc.extends.name'
359
368
: call (function (source )
360
369
local uri = guide .getUri (source )
361
370
local name = source [1 ]
362
371
local class = vm .declareGlobal (' type' , name , uri )
372
+ class :addGet (uri )
363
373
source ._globalNode = class
364
374
end )
365
375
@@ -582,24 +592,18 @@ local function dropUri(uri)
582
592
end
583
593
end
584
594
585
- for uri in files .eachFile () do
586
- local state = files .getState (uri )
587
- if state then
588
- compileAst (state .ast )
589
- end
590
- end
591
-
592
595
--- @async
593
596
files .watch (function (ev , uri )
594
597
if ev == ' update' then
595
598
dropUri (uri )
596
- ws .awaitReady (uri )
597
- local state = files .getState (uri )
598
- if state then
599
- compileAst (state .ast )
600
- end
601
599
end
602
600
if ev == ' remove' then
603
601
dropUri (uri )
604
602
end
603
+ if ev == ' compile' then
604
+ local state = files .getLastState (uri )
605
+ if state then
606
+ compileAst (state .ast )
607
+ end
608
+ end
605
609
end )
0 commit comments