summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/files.lua53
-rw-r--r--script/provider/provider.lua3
-rw-r--r--script/workspace/loading.lua2
3 files changed, 24 insertions, 34 deletions
diff --git a/script/files.lua b/script/files.lua
index f67631f0..05ca1330 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -214,6 +214,12 @@ local function pluginOnSetText(file, text)
return text
end
+---@param file file
+function m.removeState(file)
+ file.state = nil
+ m.stateMap[file.uri] = nil
+end
+
--- 设置文件文本
---@param uri uri
---@param text? string
@@ -255,14 +261,14 @@ function m.setText(uri, text, isTrust, callback)
end
local clock = os.clock()
local newText = pluginOnSetText(file, text)
- m.stateMap[uri] = nil
- file.text = newText
- file.trusted = isTrust
- file.originText = text
- file.rows = nil
- file.words = nil
- file.cache = {}
- file.cacheActiveTime = math.huge
+ m.removeState(file)
+ file.text = newText
+ file.trusted = isTrust
+ file.originText = text
+ file.rows = nil
+ file.words = nil
+ file.compileCount = 0
+ file.cache = {}
m.globalVersion = m.globalVersion + 1
m.onWatch('version', uri)
if create then
@@ -305,10 +311,10 @@ function m.setRawText(uri, text)
if not text then
return
end
- m.stateMap[uri] = nil
local file = m.fileMap[uri]
file.text = text
file.originText = text
+ m.removeState(file)
end
function m.getCachedRows(uri)
@@ -461,8 +467,8 @@ function m.remove(uri)
if not file then
return
end
+ m.removeState(file)
m.fileMap[uri] = nil
- m.stateMap[uri] = nil
m._pairsCache = nil
m.fileCount = m.fileCount - 1
@@ -560,6 +566,12 @@ function m.compileStateThen(state, file)
end
end
+ file.compileCount = file.compileCount + 1
+ if file.compileCount >= 3 then
+ file.state = state
+ log.debug('State persistence:', file.uri)
+ end
+
m.onWatch('compile', file.uri)
end
@@ -704,7 +716,6 @@ function m.getState(uri)
return nil
end
local state = m.compileState(uri)
- file.cacheActiveTime = timer.clock()
return state
end
@@ -765,7 +776,6 @@ function m.getCache(uri)
if not file then
return nil
end
- --file.cacheActiveTime = timer.clock()
return file.cache
end
@@ -891,23 +901,4 @@ function m.onWatch(ev, uri)
end
end
-function m.init()
- --TODO 可以清空文件缓存,之后看要不要启用吧
- --timer.loop(10, function ()
- -- local list = {}
- -- for _, file in pairs(m.fileMap) do
- -- if timer.clock() - file.cacheActiveTime > 10.0 then
- -- file.cacheActiveTime = math.huge
- -- file.ast = nil
- -- file.cache = {}
- -- list[#list+1] = file.uri
- -- end
- -- end
- -- if #list > 0 then
- -- log.info('Flush file caches:', #list, '\n', table.concat(list, '\n'))
- -- collectgarbage()
- -- end
- --end)
-end
-
return m
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 488f1a61..ea02579c 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -134,7 +134,6 @@ m.register 'initialize' {
m.register 'initialized'{
---@async
function (params)
- files.init()
local _ <close> = progress.create(workspace.getFirstScope().uri, lang.script.WINDOW_INITIALIZING, 0.5)
m.updateConfig()
local registrations = {}
@@ -277,7 +276,7 @@ m.register 'textDocument/didOpen' {
end)
files.open(uri)
workspace.awaitReady(uri)
- files.getState(uri)
+ files.compileState(uri)
end
}
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index 9344949c..112a6991 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -99,7 +99,7 @@ function mt:loadFile(uri, libraryUri)
-- self._sets[#self._sets+1] = waker
--end)
files.setText(uri, content, false)
- files.getState(uri)
+ files.compileState(uri)
if not self._cache[uri] then
files.addRef(uri)
end