summaryrefslogtreecommitdiff
path: root/script/files.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/files.lua')
-rw-r--r--script/files.lua30
1 files changed, 20 insertions, 10 deletions
diff --git a/script/files.lua b/script/files.lua
index 4d649b29..a779f0f6 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -120,16 +120,22 @@ end
--- 设置文件文本
---@param uri uri
---@param text string
-function m.setText(uri, text, isTrust, instance)
+---@param isTrust boolean
+---@param version integer
+function m.setText(uri, text, isTrust, version)
if not text then
return
end
+ if #text > 1024 * 1024 * 10 then
+ local client = require 'client'
+ client.showMessage('Warning', lang.script('WORKSPACE_SKIP_HUGE_FILE', uri))
+ return
+ end
--log.debug('setText', uri)
local create
if not m.fileMap[uri] then
m.fileMap[uri] = {
uri = uri,
- version = 0,
}
m.fileCount = m.fileCount + 1
create = true
@@ -154,7 +160,7 @@ function m.setText(uri, text, isTrust, instance)
m.astMap[uri] = nil
file.cache = {}
file.cacheActiveTime = math.huge
- file.version = file.version + 1
+ file.version = version
m.globalVersion = m.globalVersion + 1
await.close('files.version')
m.onWatch('version')
@@ -457,6 +463,7 @@ function m.compileState(uri, text)
--await.delay()
if state then
state.uri = uri
+ state.lua = text
state.ast.uri = uri
local clock = os.clock()
parser.luadoc(state)
@@ -488,14 +495,14 @@ function m.getState(uri)
if not file then
return nil
end
- local ast = m.astMap[uri]
- if not ast then
- ast = m.compileState(uri, file.text)
- m.astMap[uri] = ast
+ local state = m.astMap[uri]
+ if not state then
+ state = m.compileState(uri, file.text)
+ m.astMap[uri] = state
--await.delay()
end
file.cacheActiveTime = timer.clock()
- return ast
+ return state
end
---设置文件的当前可见范围
@@ -703,13 +710,16 @@ function m.getDllWords(uri)
end
--- 注册事件
+---@param callback async fun(ev: string, uri: uri)
function m.watch(callback)
m.watchList[#m.watchList+1] = callback
end
-function m.onWatch(ev, ...)
+function m.onWatch(ev, uri)
for _, callback in ipairs(m.watchList) do
- xpcall(callback, log.error, ev, ...)
+ await.call(function ()
+ callback(ev, uri)
+ end)
end
end