summaryrefslogtreecommitdiff
path: root/script/proto/proto.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-17 21:12:15 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-17 21:12:15 +0800
commitb6eed1d1f301706f51fc3dcef45f64ae4400eadd (patch)
tree89942f14778c012351a066b89c4dd87ac51ebf83 /script/proto/proto.lua
parentc2d2e7a92461dafab0b3446cd30db67d00eed570 (diff)
downloadlua-language-server-b6eed1d1f301706f51fc3dcef45f64ae4400eadd.zip
stash
Diffstat (limited to 'script/proto/proto.lua')
-rw-r--r--script/proto/proto.lua26
1 files changed, 10 insertions, 16 deletions
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 2156b7fa..2b9a6963 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -41,6 +41,12 @@ function m.on(method, callback)
m.ability[method] = callback
end
+function m.send(data)
+ local buf = jsonrpc.encode(data)
+ logSend(buf)
+ io.write(buf)
+end
+
function m.response(id, res)
if id == nil then
log.error('Response id is nil!', util.dump(res))
@@ -51,10 +57,7 @@ function m.response(id, res)
local data = {}
data.id = id
data.result = res == nil and json.null or res
- local buf = jsonrpc.encode(data)
- --log.debug('Response', id, #buf)
- logSend(buf)
- io.write(buf)
+ m.send(data)
end
function m.responseErr(id, code, message)
@@ -64,39 +67,30 @@ function m.responseErr(id, code, message)
end
assert(m.holdon[id])
m.holdon[id] = nil
- local buf = jsonrpc.encode {
+ m.send {
id = id,
error = {
code = code,
message = message,
}
}
- --log.debug('ResponseErr', id, #buf)
- logSend(buf)
- io.write(buf)
end
function m.notify(name, params)
- local buf = jsonrpc.encode {
+ m.send {
method = name,
params = params,
}
- --log.debug('Notify', name, #buf)
- logSend(buf)
- io.write(buf)
end
---@async
function m.awaitRequest(name, params)
local id = reqCounter()
- local buf = jsonrpc.encode {
+ m.send {
id = id,
method = name,
params = params,
}
- --log.debug('Request', name, #buf)
- logSend(buf)
- io.write(buf)
local result, error = await.wait(function (resume)
m.waiting[id] = resume
end)