diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-18 16:06:26 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-18 16:06:26 +0800 |
commit | b7fdf179a9015e3bef83f89c5a0811f1a67ef4d0 (patch) | |
tree | db0a36705b76f5ecf83b6de4612f035a6d9f43f7 /script | |
parent | 9cc6ca5866fcfcf22bb42f9089ff21ca51a96987 (diff) | |
download | lua-language-server-b7fdf179a9015e3bef83f89c5a0811f1a67ef4d0.zip |
update
Diffstat (limited to 'script')
-rw-r--r-- | script/proto/proto.lua | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/script/proto/proto.lua b/script/proto/proto.lua index b29d44b0..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 = { @@ -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() |