Skip to content

Commit

Permalink
test delay refresh node cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Sep 28, 2022
1 parent 0599a24 commit e9fee73
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
18 changes: 11 additions & 7 deletions script/fs-utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ local function split(str, sep)
return t
end

---@class dummyfs
---@operator div(string|fs.path|dummyfs): dummyfs
---@field files table
local dfs = {}
dfs.__index = dfs
dfs.type = 'dummy'
dfs.path = ''

---@return dummyfs
function m.dummyFS(t)
return setmetatable({
files = t or {},
Expand Down Expand Up @@ -257,7 +261,7 @@ function dfs:saveFile(path, text)
return true
end

---@param path string|fs.path
---@param path string|fs.path|dummyfs
---@param option table
---@return fs.path?
local function fsAbsolute(path, option)
Expand Down Expand Up @@ -449,7 +453,7 @@ local function fileRemove(path, option)
end
end

---@param source fs.path?
---@param source fs.path|dummyfs?
---@param target fs.path?
---@param option table
local function fileCopy(source, target, option)
Expand Down Expand Up @@ -485,7 +489,7 @@ local function fileCopy(source, target, option)
end
end

---@param source fs.path?
---@param source fs.path|dummyfs?
---@param target fs.path?
---@param option table
local function fileSync(source, target, option)
Expand Down Expand Up @@ -594,8 +598,8 @@ function m.fileRemove(path, option)
end

--- 复制文件(夹)
---@param source string|fs.path
---@param target string|fs.path
---@param source string|fs.path|dummyfs
---@param target string|fs.path|dummyfs
---@return table
function m.fileCopy(source, target, option)
option = buildOption(option)
Expand All @@ -608,8 +612,8 @@ function m.fileCopy(source, target, option)
end

--- 同步文件(夹)
---@param source string|fs.path
---@param target string|fs.path
---@param source string|fs.path|dummyfs
---@param target string|fs.path|dummyfs
---@return table
function m.fileSync(source, target, option)
option = buildOption(option)
Expand Down
6 changes: 6 additions & 0 deletions script/timer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ local function onTick()
freeQueue[#freeQueue + 1] = q
end

---@class timer.manager
local m = {}

---@class timer
---@field _onTimer? fun(self: timer)
---@field _timeoutFrame integer
---@field _timeout integer
local mt = {}
mt.__index = mt
mt.type = 'timer'
Expand Down
15 changes: 14 additions & 1 deletion script/vm/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local files = require 'files'
local vm = require 'vm.vm'
local ws = require 'workspace.workspace'
local guide = require 'parser.guide'
local timer = require 'timer'

---@type table<vm.object, vm.node>
vm.nodeCache = {}
Expand Down Expand Up @@ -475,10 +476,22 @@ function vm.createNode(a, b)
return node
end

---@type timer?
local delayTimer
files.watch(function (ev, uri)
if ev == 'version' then
if ws.isReady(uri) then
vm.clearNodeCache()
if PREVIEW then
if delayTimer then
delayTimer:restart()
end
delayTimer = timer.wait(1, function ()
delayTimer = nil
vm.clearNodeCache()
end)
else
vm.clearNodeCache()
end
end
end
end)
Expand Down

0 comments on commit e9fee73

Please sign in to comment.