summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-09-28 19:09:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-09-28 19:09:44 +0800
commite9fee73b62132d7fd5554da6a8237c0adf04d75a (patch)
tree9c450ef9b1cee43629bba5b343b8090f1c32e2e8 /script
parent0599a24ec2e3a91480c3cd3f24c5792ad1a30eca (diff)
downloadlua-language-server-e9fee73b62132d7fd5554da6a8237c0adf04d75a.zip
test delay refresh node cache
#1595
Diffstat (limited to 'script')
-rw-r--r--script/fs-utility.lua18
-rw-r--r--script/timer.lua6
-rw-r--r--script/vm/node.lua15
3 files changed, 31 insertions, 8 deletions
diff --git a/script/fs-utility.lua b/script/fs-utility.lua
index b57c15bb..5ac4139a 100644
--- a/script/fs-utility.lua
+++ b/script/fs-utility.lua
@@ -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 {},
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
diff --git a/script/timer.lua b/script/timer.lua
index a14cdd27..0a905b1c 100644
--- a/script/timer.lua
+++ b/script/timer.lua
@@ -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'
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 49207b13..9b10fa9d 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -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 = {}
@@ -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)