summaryrefslogtreecommitdiff
path: root/script/proto
diff options
context:
space:
mode:
Diffstat (limited to 'script/proto')
-rw-r--r--script/proto/converter.lua5
-rw-r--r--script/proto/define.lua6
-rw-r--r--script/proto/proto.lua26
3 files changed, 35 insertions, 2 deletions
diff --git a/script/proto/converter.lua b/script/proto/converter.lua
index cf6331f1..9c75f056 100644
--- a/script/proto/converter.lua
+++ b/script/proto/converter.lua
@@ -2,7 +2,6 @@ local guide = require 'parser.guide'
local files = require 'files'
local encoder = require 'encoder'
--- TODO
local offsetEncoding = 'utf16'
local m = {}
@@ -178,4 +177,8 @@ function m.textEdit(range, newtext)
}
end
+function m.setOffsetEncoding(encoding)
+ offsetEncoding = encoding:lower():gsub('%-', '')
+end
+
return m
diff --git a/script/proto/define.lua b/script/proto/define.lua
index 713857af..dbb6ba85 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -44,6 +44,9 @@ m.DiagnosticDefaultSeverity = {
['no-implicit-any'] = 'Information',
['deprecated'] = 'Warning',
['different-requires'] = 'Warning',
+ ['await-in-sync'] = 'Warning',
+ ['not-yieldable'] = 'Warning',
+ ['discard-returns'] = 'Warning',
['type-check'] = 'Warning',
['duplicate-doc-class'] = 'Warning',
@@ -98,6 +101,9 @@ m.DiagnosticDefaultNeededFileStatus = {
['no-implicit-any'] = 'None',
['deprecated'] = 'Opened',
['different-requires'] = 'Any',
+ ['await-in-sync'] = 'None',
+ ['not-yieldable'] = 'None',
+ ['discard-returns'] = 'Opened',
['type-check'] = 'None',
['duplicate-doc-class'] = 'Any',
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index e380f54f..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 = {}
@@ -22,6 +36,7 @@ function m.getMethodName(proto)
end
end
+---@param callback async fun()
function m.on(method, callback)
m.ability[method] = callback
end
@@ -38,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
@@ -56,6 +72,7 @@ function m.responseErr(id, code, message)
}
}
--log.debug('ResponseErr', id, #buf)
+ logSend(buf)
io.write(buf)
end
@@ -65,9 +82,11 @@ function m.notify(name, params)
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 {
@@ -76,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
@@ -94,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
@@ -106,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
@@ -120,7 +142,7 @@ function m.doMethod(proto)
if proto.id then
m.holdon[proto.id] = proto
end
- await.call(function ()
+ await.call(function () ---@async
--log.debug('Start method:', method)
if proto.id then
await.setID('proto:' .. proto.id)
@@ -146,6 +168,7 @@ function m.doMethod(proto)
end
end
ok, res = xpcall(abil, log.error, proto.params)
+ await.delay()
end)
end
@@ -159,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