summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/await.lua23
-rw-r--r--script-beta/core/completion.lua2
-rw-r--r--script-beta/files.lua31
-rw-r--r--script-beta/provider/diagnostic.lua3
-rw-r--r--script-beta/pub/report.lua2
5 files changed, 47 insertions, 14 deletions
diff --git a/script-beta/await.lua b/script-beta/await.lua
index 38fb6548..7134716b 100644
--- a/script-beta/await.lua
+++ b/script-beta/await.lua
@@ -80,13 +80,36 @@ function m.delay(getVersion)
return coroutine.yield()
end
+local function buildInfo(waker)
+ local co
+ for i = 1, 100 do
+ local n, v = debug.getupvalue(waker, i)
+ if not n then
+ return nil
+ end
+ if n == 'co' then
+ co = v
+ break
+ end
+ end
+ if not co then
+ return nil
+ end
+ return debug.traceback(co)
+end
+
--- 步进
function m.step()
local waker = m.delayQueue[m.delayQueueIndex]
if waker then
m.delayQueue[m.delayQueueIndex] = false
m.delayQueueIndex = m.delayQueueIndex + 1
+ local clock = os.clock()
waker()
+ local passed = os.clock() - clock
+ if passed > 0.01 then
+ log.warn(('Await step takes [%.3f] sec.\n%s'):format(passed, buildInfo(waker)))
+ end
return true
else
m.delayQueue = {}
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index b3e5fe28..92148f28 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -227,7 +227,7 @@ local function tryWord(ast, text, offset, results)
end
local function completion(uri, offset)
- local ast = files.getAst(uri)
+ local ast = files.getLastAst(uri)
if not ast then
return nil
end
diff --git a/script-beta/files.lua b/script-beta/files.lua
index 3eb26c46..60ff73f9 100644
--- a/script-beta/files.lua
+++ b/script-beta/files.lua
@@ -69,29 +69,36 @@ function m.setText(uri, text)
return
end
file.text = text
- file.lastAst = file.ast or file.lastAst
- file.vm = nil
- file.lines = nil
- file.ast = nil
- file.globals = nil
- file.links = nil
m.globalVersion = m.globalVersion + 1
- m.needRefreshUri = originUri
+ if not m.needRefreshUri then
+ m.needRefreshUri = {}
+ end
+ m.needRefreshUri[file] = true
end
--- 刷新缓存
---|必须在自动完成请求后执行,否则会影响自动完成的响应速度
function m.refresh()
- local uri = m.needRefreshUri
- if not uri then
- return false
+ local refreshed = m.needRefreshUri
+ if not refreshed then
+ return
end
+
+ local diagnostic = require 'provider.diagnostic'
log.debug('Refresh cache.')
m.needRefreshUri = nil
+ local lastFile
+ for file in pairs(refreshed) do
+ lastFile = file
+ file.vm = nil
+ file.lines = nil
+ file.ast = nil
+ file.globals = nil
+ file.links = nil
+ end
vm.refreshCache()
- local diagnostic = require 'provider.diagnostic'
- diagnostic.refresh(uri)
+ diagnostic.refresh(lastFile.uri)
return true
end
diff --git a/script-beta/provider/diagnostic.lua b/script-beta/provider/diagnostic.lua
index ba95f2bf..eac0472c 100644
--- a/script-beta/provider/diagnostic.lua
+++ b/script-beta/provider/diagnostic.lua
@@ -184,6 +184,9 @@ function m.refresh(uri)
if not m._start then
return
end
+ await.delay(function ()
+ return files.globalVersion
+ end)
local clock = os.clock()
if uri then
m.doDiagnostic(uri)
diff --git a/script-beta/pub/report.lua b/script-beta/pub/report.lua
index edd3ee0e..34f58277 100644
--- a/script-beta/pub/report.lua
+++ b/script-beta/pub/report.lua
@@ -2,7 +2,7 @@ local pub = require 'pub.pub'
local await = require 'await'
pub.on('log', function (params, brave)
- log.raw(brave.id, params.level, params.msg, params.src, params.line)
+ log.raw(brave.id, params.level, params.msg, params.src, params.line, params.clock)
end)
pub.on('mem', function (count, brave)