summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-03-01 17:14:57 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-03-01 17:14:57 +0800
commitd6a09457eefdb44425f99ac4d5ffcaa2c1b7b685 (patch)
treed41ab233813660ff72d5ed9f0cde7d5e9254673f
parentda4ddec0289d7d72ce53816259cbfb0069353ab1 (diff)
downloadlua-language-server-d6a09457eefdb44425f99ac4d5ffcaa2c1b7b685.zip
improve delay of completion
-rw-r--r--script/await.lua3
-rw-r--r--script/files.lua4
-rw-r--r--script/parser/compile.lua7
-rw-r--r--script/provider/diagnostic.lua1
-rw-r--r--script/provider/provider.lua4
5 files changed, 11 insertions, 8 deletions
diff --git a/script/await.lua b/script/await.lua
index bfc1fd55..eb74fca6 100644
--- a/script/await.lua
+++ b/script/await.lua
@@ -81,13 +81,10 @@ function m.close(id)
if not map then
return
end
- local count = 0
for co in pairs(map) do
map[co] = nil
coroutine.close(co)
- count = count + 1
end
- --log.debug('Close await:', id, count)
end
function m.hasID(id, co)
diff --git a/script/files.lua b/script/files.lua
index 220a2ee2..ed9fd880 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -182,6 +182,7 @@ function m.setText(uri, text, isTrust)
file.version = file.version + 1
m.globalVersion = m.globalVersion + 1
await.close('files.version')
+ await.close('compile:' .. uri)
if create then
m.onWatch('create', originUri)
end
@@ -346,6 +347,7 @@ function m.eachDll()
end
function m.compileAst(uri, text)
+ await.setID('compile:' .. uri)
local ws = require 'workspace'
if not m.isOpen(uri) and #text >= config.config.workspace.preloadFileSize * 1000 then
if not m.notifyCache['preloadFileSize'] then
@@ -378,12 +380,14 @@ function m.compileAst(uri, text)
special = config.config.runtime.special,
unicodeName = config.config.runtime.unicodeName,
nonstandardSymbol = config.config.runtime.nonstandardSymbol,
+ delay = await.delay,
}
)
local passed = os.clock() - clock
if passed > 0.1 then
log.warn(('Compile [%s] takes [%.3f] sec, size [%.3f] kb.'):format(uri, passed, #text / 1000))
end
+ await.delay()
if state then
state.uri = uri
state.ast.uri = uri
diff --git a/script/parser/compile.lua b/script/parser/compile.lua
index f9992047..3c15beac 100644
--- a/script/parser/compile.lua
+++ b/script/parser/compile.lua
@@ -1,6 +1,6 @@
local guide = require 'parser.guide'
-local type = type
-local os = os
+local type = type
+local os = os
local specials = {
['_G'] = true,
@@ -540,6 +540,9 @@ return function (self, lua, mode, version, options)
if not state then
return nil, err
end
+ if options.delay then
+ options.delay()
+ end
local clock = os.clock()
pushError = state.pushError
if version == 'Lua 5.1' or version == 'LuaJIT' then
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 6f67d92c..883ae68c 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -246,6 +246,7 @@ function m.refresh(uri)
return
end
await.call(function ()
+ await.delay()
if uri then
m.doDiagnostic(uri)
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 58b7ddb8..12ddafa1 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -431,9 +431,6 @@ proto.on('textDocument/prepareRename', function (params)
end)
proto.on('textDocument/completion', function (params)
- await.close('completion')
- await.setID('completion')
- await.sleep(0.01)
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_COMPLETION, 0.5)
--log.info(util.dump(params))
@@ -827,6 +824,7 @@ do
files.watch(function (ev, uri)
if ev == 'update'
or ev == 'updateVisible' then
+ await.delay()
await.call(function ()
updateHint(uri)
end)