Skip to content

Commit 7d686f3

Browse files
committed
cleanup
1 parent 2e15bfa commit 7d686f3

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

script/files.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ function m.setText(uri, text, isTrust, callback)
274274
util.saveFile(LOGPATH .. '/diffed.lua', newText)
275275
end
276276
end
277+
m.getState(uri)
277278
log.trace('Set text:', uri, 'takes', os.clock() - clock, 'sec.')
278279

279280
--if instance or TEST then
@@ -557,6 +558,8 @@ function m.compileStateThen(state, file)
557558
log.warn(('Convert lazy-table for [%s] takes [%.3f] sec, size [%.3f] kb.'):format(file.uri, passed, #file.text / 1000))
558559
end
559560
end
561+
562+
m.onWatch('compile', file.uri)
560563
end
561564

562565
---@param uri uri

script/vm/global.lua

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ local util = require 'utility'
22
local scope = require 'workspace.scope'
33
local guide = require 'parser.guide'
44
local files = require 'files'
5-
local ws = require 'workspace'
65
---@class vm
76
local 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
1716
local mt = {}
1817
mt.__index = mt
@@ -30,6 +29,12 @@ function mt:addSet(uri, source)
3029
self.setsCache = nil
3130
end
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[]
3540
function mt:getSets(suri)
@@ -85,7 +90,6 @@ end
8590
function mt:dropUri(uri)
8691
self.links[uri] = nil
8792
self.setsCache = nil
88-
self.getsCache = nil
8993
end
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
583593
end
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
593596
files.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
605609
end)

script/workspace/loading.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ function mt:loadFile(uri, libraryUri)
9999
-- self._sets[#self._sets+1] = waker
100100
--end)
101101
files.setText(uri, content, false)
102-
if COMPILECORES then
103-
files.compileStateAsync(uri, function (state) end)
104-
else
105-
files.compileState(uri)
106-
end
107102
if not self._cache[uri] then
108103
files.addRef(uri)
109104
end

test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ local function main()
7878
local lclient = require 'lclient'
7979
local ws = require 'workspace'
8080
local furi = require 'file-uri'
81+
require 'vm'
8182

8283
--log.print = true
8384

0 commit comments

Comments
 (0)