summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/await.lua14
-rw-r--r--server-beta/src/core/diagnostics/redundant-parameter.lua6
-rw-r--r--server-beta/src/core/diagnostics/unused-function.lua8
-rw-r--r--server-beta/src/files.lua5
-rw-r--r--server-beta/src/provider/diagnostic.lua22
5 files changed, 32 insertions, 23 deletions
diff --git a/server-beta/src/await.lua b/server-beta/src/await.lua
index 4187f4b4..92db7f73 100644
--- a/server-beta/src/await.lua
+++ b/server-beta/src/await.lua
@@ -62,7 +62,7 @@ function m.wait(callback, ...)
end
--- 延迟
-function m.delay(...)
+function m.delay(getVersion)
local co, main = coroutine.running()
if main then
if m.errorHandle then
@@ -70,16 +70,22 @@ function m.delay(...)
end
return
end
- m.delayQueue[#m.delayQueue+1] = function (...)
- return m.checkResult(co, coroutine.resume(co, ...))
+ local version = getVersion and getVersion()
+ m.delayQueue[#m.delayQueue+1] = function ()
+ if version == (getVersion and getVersion()) then
+ return m.checkResult(co, coroutine.resume(co))
+ else
+ coroutine.close(co)
+ end
end
- return coroutine.yield(...)
+ return coroutine.yield()
end
--- 步进
function m.step()
local waker = m.delayQueue[m.delayQueueIndex]
if waker then
+ m.delayQueue[m.delayQueueIndex] = false
m.delayQueueIndex = m.delayQueueIndex + 1
waker()
return true
diff --git a/server-beta/src/core/diagnostics/redundant-parameter.lua b/server-beta/src/core/diagnostics/redundant-parameter.lua
index 04012ef4..43bb93ed 100644
--- a/server-beta/src/core/diagnostics/redundant-parameter.lua
+++ b/server-beta/src/core/diagnostics/redundant-parameter.lua
@@ -3,7 +3,7 @@ local guide = require 'parser.guide'
local searcher = require 'searcher'
local lang = require 'language'
local define = require 'proto.define'
-local library = require 'library'
+local await = require 'await'
local function countLibraryArgs(source)
local func = searcher.getLibrary(source)
@@ -60,6 +60,10 @@ return function (uri, callback)
return
end
+ await.delay(function ()
+ return files.globalVersion
+ end)
+
local func = source.node
local funcArgs
searcher.eachRef(func, function (info)
diff --git a/server-beta/src/core/diagnostics/unused-function.lua b/server-beta/src/core/diagnostics/unused-function.lua
index 0dd55906..eb6b8f7f 100644
--- a/server-beta/src/core/diagnostics/unused-function.lua
+++ b/server-beta/src/core/diagnostics/unused-function.lua
@@ -1,8 +1,9 @@
local files = require 'files'
local guide = require 'parser.guide'
local searcher = require 'searcher'
-local define = require 'proto.define'
-local lang = require 'language'
+local define = require 'proto.define'
+local lang = require 'language'
+local await = require 'await'
return function (uri, callback)
local ast = files.getAst(uri)
@@ -27,5 +28,8 @@ return function (uri, callback)
message = lang.script.DIAG_UNUSED_FUNCTION,
}
end
+ await.delay(function ()
+ return files.globalVersion
+ end)
end)
end
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index a9b833b2..ad2d9552 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -12,6 +12,7 @@ m.openMap = {}
m.fileMap = {}
m.assocVersion = -1
m.assocMatcher = nil
+m.globalVersion = 0
--- 打开文件
---@param uri string
@@ -72,6 +73,7 @@ function m.setText(uri, text)
file.lines = nil
file.ast = nil
file.globals = nil
+ m.globalVersion = m.globalVersion + 1
searcher.refreshCache()
local diagnostic = require 'provider.diagnostic'
@@ -118,6 +120,8 @@ function m.remove(uri)
return
end
m.fileMap[uri] = nil
+
+ m.globalVersion = m.globalVersion + 1
searcher.refreshCache()
local diagnostic = require 'service.diagnostic'
@@ -129,6 +133,7 @@ function m.removeAll()
for uri in pairs(m.fileMap) do
m.fileMap[uri] = nil
end
+ m.globalVersion = m.globalVersion + 1
searcher.refreshCache()
end
diff --git a/server-beta/src/provider/diagnostic.lua b/server-beta/src/provider/diagnostic.lua
index 74c6d87a..6583c8d8 100644
--- a/server-beta/src/provider/diagnostic.lua
+++ b/server-beta/src/provider/diagnostic.lua
@@ -7,8 +7,6 @@ local config = require 'config'
local core = require 'core.diagnostics'
local m = {}
-
-m.version = 0
m._start = false
m.cache = {}
@@ -154,23 +152,16 @@ function m.doDiagnostic(uri, syntaxOnly)
end
function m.refresh(uri)
- m.version = m.version + 1
- local myVersion = m.version
await.create(function ()
- await.delay()
- if myVersion ~= m.version then
- return
- end
+ await.delay(function ()
+ return files.globalVersion
+ end)
if uri then
m.doDiagnostic(uri, true)
end
if not m._start then
return
end
- await.sleep(0.2)
- if myVersion ~= m.version then
- return
- end
local clock = os.clock()
if uri then
m.doDiagnostic(uri)
@@ -178,10 +169,9 @@ function m.refresh(uri)
for destUri in files.eachFile() do
if destUri ~= uri then
m.doDiagnostic(files.getOriginUri(destUri))
- await.delay()
- if myVersion ~= m.version then
- return
- end
+ await.delay(function ()
+ return files.globalVersion
+ end)
end
end
local passed = os.clock() - clock