diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-18 17:03:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-18 17:03:05 +0800 |
commit | c6cac231b097f0a0aaea76e03bb50bdbdd363809 (patch) | |
tree | e51ba03f013fcb40b994737f48ed60f10622b1ce /script/proto/proto.lua | |
parent | 2f984c1a2baf162f72240ca7b7f3f530459a71f4 (diff) | |
parent | 9e8901c5d09b4537a5741fd20dc5cc77c5a23dce (diff) | |
download | lua-language-server-c6cac231b097f0a0aaea76e03bb50bdbdd363809.zip |
Merge branch 'client-test'
Diffstat (limited to 'script/proto/proto.lua')
-rw-r--r-- | script/proto/proto.lua | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/script/proto/proto.lua b/script/proto/proto.lua index 2b9a6963..4ba99b88 100644 --- a/script/proto/proto.lua +++ b/script/proto/proto.lua @@ -92,7 +92,12 @@ function m.awaitRequest(name, params) params = params, } local result, error = await.wait(function (resume) - m.waiting[id] = resume + m.waiting[id] = { + id = id, + method = name, + params = params, + resume = resume, + } end) if error then log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message)) @@ -110,14 +115,19 @@ function m.request(name, params, callback) --log.debug('Request', name, #buf) logSend(buf) io.write(buf) - m.waiting[id] = function (result, error) - if error then - log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message)) - end - if callback then - callback(result) + m.waiting[id] = { + id = id, + method = name, + params = params, + resume = function (result, error) + if error then + log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message)) + end + if callback then + callback(result) + end end - end + } end local secretOption = { @@ -137,6 +147,9 @@ function m.doMethod(proto) logRecieve(proto) local method, optional = m.getMethodName(proto) local abil = m.ability[method] + if proto.id then + m.holdon[proto.id] = proto + end if not abil then if not optional then log.warn('Recieved unknown proto: ' .. method) @@ -146,9 +159,6 @@ function m.doMethod(proto) end return end - if proto.id then - m.holdon[proto.id] = proto - end await.call(function () ---@async --log.debug('Start method:', method) if proto.id then @@ -192,17 +202,17 @@ end function m.doResponse(proto) logRecieve(proto) local id = proto.id - local resume = m.waiting[id] - if not resume then + local waiting = m.waiting[id] + if not waiting then log.warn('Response id not found: ' .. util.dump(proto)) return end m.waiting[id] = nil if proto.error then - resume(nil, proto.error) + waiting.resume(nil, proto.error) return end - resume(proto.result) + waiting.resume(proto.result) end function m.listen() |