summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-11-09 17:33:37 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-11-09 17:33:37 +0800
commit00a0f93354e11472ac65e407652d54db32782ef0 (patch)
tree28be012230109ab7ca03d44f17c42fa0b593c568 /script
parentea95e996ba0d8b7657f9ab29735136003c49b008 (diff)
downloadlua-language-server-00a0f93354e11472ac65e407652d54db32782ef0.zip
rpclog
Diffstat (limited to 'script')
-rw-r--r--script/global.d.lua7
-rw-r--r--script/proto/proto.lua21
2 files changed, 27 insertions, 1 deletions
diff --git a/script/global.d.lua b/script/global.d.lua
index cc0aafbd..0435293e 100644
--- a/script/global.d.lua
+++ b/script/global.d.lua
@@ -11,7 +11,7 @@ DBGPORT = 0
DBGWAIT = false
---displayed language, use command line: --locale="en-us"
----@type '"en-us"'|'"zh-cn"'
+---@type '"en-us"'|'"zh-cn"'|'"pt-br"'
LOCALE = 'en-us'
---path of local config file, use command line: --configpath="config.lua"
@@ -27,4 +27,9 @@ SHOWSOURCE = false
TRACE = false
---trace searching with `too deep!` into log, use command line: --footprint=true
+---@type boolean
FOOTPRINT = false
+
+---trace rpc, use command line: --rpclog=true
+---@type boolean
+RPCLOG = false
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 66f7d810..7cdc461c 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -8,6 +8,20 @@ local json = require 'json'
local reqCounter = util.counter()
+local function logSend(buf)
+ if not RPCLOG then
+ return
+ end
+ log.debug('rpc send:', buf)
+end
+
+local function logRecieve(proto)
+ if not RPCLOG then
+ return
+ end
+ log.debug('rpc recieve:', json.encode(proto))
+end
+
local m = {}
m.ability = {}
@@ -39,6 +53,7 @@ function m.response(id, res)
data.result = res == nil and json.null or res
local buf = jsonrpc.encode(data)
--log.debug('Response', id, #buf)
+ logSend(buf)
io.write(buf)
end
@@ -57,6 +72,7 @@ function m.responseErr(id, code, message)
}
}
--log.debug('ResponseErr', id, #buf)
+ logSend(buf)
io.write(buf)
end
@@ -66,6 +82,7 @@ function m.notify(name, params)
params = params,
}
--log.debug('Notify', name, #buf)
+ logSend(buf)
io.write(buf)
end
@@ -78,6 +95,7 @@ function m.awaitRequest(name, params)
params = params,
}
--log.debug('Request', name, #buf)
+ logSend(buf)
io.write(buf)
local result, error = await.wait(function (resume)
m.waiting[id] = resume
@@ -96,6 +114,7 @@ function m.request(name, params, callback)
params = params,
}
--log.debug('Request', name, #buf)
+ logSend(buf)
io.write(buf)
m.waiting[id] = function (result, error)
if error then
@@ -108,6 +127,7 @@ function m.request(name, params, callback)
end
function m.doMethod(proto)
+ logRecieve(proto)
local method, optional = m.getMethodName(proto)
local abil = m.ability[method]
if not abil then
@@ -162,6 +182,7 @@ function m.close(id, reason)
end
function m.doResponse(proto)
+ logRecieve(proto)
local id = proto.id
local resume = m.waiting[id]
if not resume then