summaryrefslogtreecommitdiff
path: root/script/brave
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-05-10 17:44:34 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-05-10 17:44:34 +0800
commit7318bbba9808b94c59202d301ac4faf4dc7f1f5a (patch)
tree9d82c000652aa31d9770677ba41eadb36874c938 /script/brave
parentd7e59826b5dec2d6f4b9ba59f6d64af42c078edd (diff)
downloadlua-language-server-7318bbba9808b94c59202d301ac4faf4dc7f1f5a.zip
support connecting by socket with `--socket=PORT`
Diffstat (limited to 'script/brave')
-rw-r--r--script/brave/work.lua33
1 files changed, 32 insertions, 1 deletions
diff --git a/script/brave/work.lua b/script/brave/work.lua
index 3a565e08..3b82b452 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,37 @@ brave.on('loadProto', function ()
end
end)
+brave.on('loadProtoBySocket', function (fdHandle)
+ local jsonrpc = require 'jsonrpc'
+ local socket = require 'bee.socket'
+ local thread = require 'bee.thread'
+ local fd = socket.fd(fdHandle)
+ local buf = ''
+ while true do
+ 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
+ local data = fd:recv()
+ if data then
+ buf = buf .. data
+ else
+ thread.sleep(0.01)
+ end
+ end
+ end)
+ --log.debug('loaded proto', proto.method)
+ if not proto then
+ brave.push('protoerror', err)
+ return
+ end
+ brave.push('proto', proto)
+ end
+end)
+
brave.on('timer', function (time)
local thread = require 'bee.thread'
while true do