summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-08-19 17:25:17 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-08-19 17:25:17 +0800
commit7d2156d15be3f9d9d56bc092f58f1df0431c87c3 (patch)
tree4afcdf2c4650be821d64cbfa8f0ee6a94fdc50fa
parent2df623b95dd07d21bffa7be402f9be8c5d08b838 (diff)
downloadlua-language-server-7d2156d15be3f9d9d56bc092f58f1df0431c87c3.zip
尽快cancel掉之前的请求
-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