summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/files.lua53
-rw-r--r--script/provider/provider.lua3
-rw-r--r--script/workspace/loading.lua2
-rw-r--r--test/crossfile/completion.lua2
-rw-r--r--test/crossfile/definition.lua2
-rw-r--r--test/crossfile/diagnostic.lua2
-rw-r--r--test/crossfile/hover.lua2
-rw-r--r--test/crossfile/references.lua2
8 files changed, 29 insertions, 39 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
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 640585fa..3ad8c385 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -69,7 +69,7 @@ function TEST(data)
mainUri = uri
end
files.setText(uri, script)
- files.getState(uri)
+ files.compileState(uri)
end
local _ <close> = function ()
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 7cb76922..b13b57f3 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -53,7 +53,7 @@ function TEST(datas)
sourceUri = uri
end
files.setText(uri, newScript)
- files.getState(uri)
+ files.compileState(uri)
end
local _ <close> = function ()
diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua
index 7df07e6c..e270d3da 100644
--- a/test/crossfile/diagnostic.lua
+++ b/test/crossfile/diagnostic.lua
@@ -47,7 +47,7 @@ function TEST(datas)
end
data.content = newScript
files.setText(uri, newScript)
- files.getState(uri)
+ files.compileState(uri)
end
local _ <close> = function ()
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index ba799f49..d47bb41b 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -44,7 +44,7 @@ function TEST(expect)
local script, list = catch(file.content, '?')
local uri = furi.encode(file.path)
files.setText(uri, script)
- files.getState(uri)
+ files.compileState(uri)
if #list['?'] > 0 then
sourceUri = uri
sourcePos = (list['?'][1][1] + list['?'][1][2]) // 2
diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua
index fd489866..faa9dba9 100644
--- a/test/crossfile/references.lua
+++ b/test/crossfile/references.lua
@@ -74,7 +74,7 @@ function TEST(datas)
sourceUri = uri
end
files.setText(uri, newScript)
- files.getState(uri)
+ files.compileState(uri)
end
local _ <close> = function ()