summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/lclient.lua17
-rw-r--r--script/proto/proto.lua28
2 files changed, 39 insertions, 6 deletions
diff --git a/script/lclient.lua b/script/lclient.lua
index 96a6c16f..0960729d 100644
--- a/script/lclient.lua
+++ b/script/lclient.lua
@@ -162,13 +162,16 @@ function mt:remove()
self._gc:remove()
end
+---@async
function mt:notify(method, params)
proto.doMethod {
method = method,
params = params,
}
+ await.sleep(0.1)
end
+---@async
function mt:request(method, params, callback)
local id = counter()
self._waiting[id] = {
@@ -181,16 +184,20 @@ function mt:request(method, params, callback)
method = method,
params = params,
}
+ await.sleep(0.1)
end
---@async
function mt:awaitRequest(method, params)
return await.wait(function (waker)
- self:request(method, params, function (result)
- if result == json.null then
- result = nil
- end
- waker(result)
+ ---@async
+ await.call(function ()
+ self:request(method, params, function (result)
+ if result == json.null then
+ result = nil
+ end
+ waker(result)
+ end)
end)
end)
end
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index dff7063d..b432a3d1 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -156,7 +156,9 @@ local secretOption = {
end
}
-function m.doMethod(proto)
+m.methodQueue = {}
+
+function m.applyMethod(proto)
logRecieve(proto)
local method, optional = m.getMethodName(proto)
local abil = m.ability[method]
@@ -202,6 +204,30 @@ function m.doMethod(proto)
end)
end
+function m.applyMethodQueue()
+ local queue = m.methodQueue
+ m.methodQueue = {}
+ local canceled = {}
+ for _, proto in ipairs(queue) do
+ if proto.method == '$/cancelRequest' then
+ canceled[proto.params.id] = true
+ end
+ end
+ for _, proto in ipairs(queue) do
+ if not canceled[proto.id] then
+ m.applyMethod(proto)
+ end
+ end
+end
+
+function m.doMethod(proto)
+ m.methodQueue[#m.methodQueue+1] = proto
+ if #m.methodQueue > 1 then
+ return
+ end
+ timer.wait(0, m.applyMethodQueue)
+end
+
function m.close(id, reason, message)
local proto = m.holdon[id]
if not proto then