summaryrefslogtreecommitdiff
path: root/script/brave/work.lua
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2024-02-22 20:29:13 +0800
committerCppCXY <812125110@qq.com>2024-02-22 20:29:13 +0800
commit9b6df71d97a70ee7179949ef9f15368cbf29dcbd (patch)
treebf7a7e62ed7c164a12bdce437c17262a5235bcec /script/brave/work.lua
parent483fe246b6ae8c25d433aa15e43f04f0e71a74d5 (diff)
parent3e6fd3ce1f2f0528336ded939d776a29bbfaf2eb (diff)
downloadlua-language-server-9b6df71d97a70ee7179949ef9f15368cbf29dcbd.zip
Merge branch 'master' of github.com:CppCXY/lua-language-server
Diffstat (limited to 'script/brave/work.lua')
-rw-r--r--script/brave/work.lua51
1 files changed, 50 insertions, 1 deletions
diff --git a/script/brave/work.lua b/script/brave/work.lua
index 3a565e08..a6a7a41e 100644
--- a/script/brave/work.lua
+++ b/script/brave/work.lua
@@ -1,6 +1,6 @@
local brave = require 'brave.brave'
-brave.on('loadProto', function ()
+brave.on('loadProtoByStdio', function ()
local jsonrpc = require 'jsonrpc'
while true do
local proto, err = jsonrpc.decode(io.read)
@@ -13,6 +13,55 @@ brave.on('loadProto', function ()
end
end)
+brave.on('loadProtoBySocket', function (param)
+ local jsonrpc = require 'jsonrpc'
+ local net = require 'service.net'
+ local buf = ''
+
+ ---@async
+ local parser = coroutine.create(function ()
+ while true do
+ ---@async
+ local proto, err = jsonrpc.decode(function (len)
+ while true do
+ if #buf >= len then
+ local res = buf:sub(1, len)
+ buf = buf:sub(len + 1)
+ return res
+ end
+ coroutine.yield()
+ end
+ end)
+ --log.debug('loaded proto', proto.method)
+ if not proto then
+ brave.push('protoerror', err)
+ return
+ end
+ brave.push('proto', proto)
+ end
+ end)
+
+ local lsclient = net.connect('tcp', '127.0.0.1', param.port)
+ local lsmaster = net.connect('unix', param.unixPath)
+
+ assert(lsclient)
+ assert(lsmaster)
+
+ function lsclient:on_data(data)
+ buf = buf .. data
+ coroutine.resume(parser)
+ end
+
+ function lsmaster:on_data(data)
+ lsclient:write(data)
+ net.update()
+ end
+
+ while true do
+ net.update(10)
+ end
+end)
+
brave.on('timer', function (time)
local thread = require 'bee.thread'
while true do