@@ -2,17 +2,16 @@ local util = require 'utility'
22local scope = require ' workspace.scope'
33local guide = require ' parser.guide'
44local files = require ' files'
5- local ws = require ' workspace'
65--- @class vm
76local vm = require ' vm.vm'
87
98--- @class vm.global.link
109--- @field sets parser.object[]
10+ --- @field hasGet boolean ?
1111
1212--- @class vm.global
1313--- @field links table<uri , vm.global.link>
1414--- @field setsCache ? table<uri , parser.object[]>
15- --- @field getsCache ? table<uri , parser.object[]>
1615--- @field cate vm.global.cate
1716local mt = {}
1817mt .__index = mt
@@ -30,6 +29,12 @@ function mt:addSet(uri, source)
3029 self .setsCache = nil
3130end
3231
32+ --- @param uri uri
33+ function mt :addGet (uri )
34+ local link = self .links [uri ]
35+ link .hasGet = true
36+ end
37+
3338--- @param suri uri
3439--- @return parser.object[]
3540function mt :getSets (suri )
8590function mt :dropUri (uri )
8691 self .links [uri ] = nil
8792 self .setsCache = nil
88- self .getsCache = nil
8993end
9094
9195--- @return string
@@ -174,6 +178,7 @@ local compilerGlobalSwitch = util.switch()
174178 return
175179 end
176180 local global = vm .declareGlobal (' variable' , name , uri )
181+ global :addGet (uri )
177182 source ._globalNode = global
178183
179184 local nxt = source .next
@@ -231,6 +236,7 @@ local compilerGlobalSwitch = util.switch()
231236 end
232237 local uri = guide .getUri (source )
233238 local global = vm .declareGlobal (' variable' , name , uri )
239+ global :addGet (uri )
234240 source ._globalNode = global
235241
236242 local nxt = source .next
@@ -255,6 +261,8 @@ local compilerGlobalSwitch = util.switch()
255261 if source .node .special == ' rawset' then
256262 global :addSet (uri , source )
257263 source .value = source .args [3 ]
264+ else
265+ global :addGet (uri )
258266 end
259267 source ._globalNode = global
260268
@@ -353,13 +361,15 @@ local compilerGlobalSwitch = util.switch()
353361 return
354362 end
355363 local type = vm .declareGlobal (' type' , name , uri )
364+ type :addGet (uri )
356365 source ._globalNode = type
357366 end )
358367 : case ' doc.extends.name'
359368 : call (function (source )
360369 local uri = guide .getUri (source )
361370 local name = source [1 ]
362371 local class = vm .declareGlobal (' type' , name , uri )
372+ class :addGet (uri )
363373 source ._globalNode = class
364374 end )
365375
@@ -582,24 +592,18 @@ local function dropUri(uri)
582592 end
583593end
584594
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-
592595--- @async
593596files .watch (function (ev , uri )
594597 if ev == ' update' then
595598 dropUri (uri )
596- ws .awaitReady (uri )
597- local state = files .getState (uri )
598- if state then
599- compileAst (state .ast )
600- end
601599 end
602600 if ev == ' remove' then
603601 dropUri (uri )
604602 end
603+ if ev == ' compile' then
604+ local state = files .getLastState (uri )
605+ if state then
606+ compileAst (state .ast )
607+ end
608+ end
605609end )
0 commit comments