summaryrefslogtreecommitdiff
path: root/script/proto
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/proto
parent483fe246b6ae8c25d433aa15e43f04f0e71a74d5 (diff)
parent3e6fd3ce1f2f0528336ded939d776a29bbfaf2eb (diff)
downloadlua-language-server-9b6df71d97a70ee7179949ef9f15368cbf29dcbd.zip
Merge branch 'master' of github.com:CppCXY/lua-language-server
Diffstat (limited to 'script/proto')
-rw-r--r--script/proto/converter.lua8
-rw-r--r--script/proto/define.lua38
-rw-r--r--script/proto/diagnostic.lua11
-rw-r--r--script/proto/proto.lua65
4 files changed, 96 insertions, 26 deletions
diff --git a/script/proto/converter.lua b/script/proto/converter.lua
index a723face..e86e4904 100644
--- a/script/proto/converter.lua
+++ b/script/proto/converter.lua
@@ -207,6 +207,14 @@ function m.setOffsetEncoding(encoding)
offsetEncoding = encoding:lower():gsub('%-', '')
end
+---@param s string
+---@param i? integer
+---@param j? integer
+---@return integer
+function m.len(s, i, j)
+ return encoder.len(offsetEncoding, s, i, j)
+end
+
---@class proto.command
---@field title string
---@field command string
diff --git a/script/proto/define.lua b/script/proto/define.lua
index 1bc1000d..77e7a77d 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -166,24 +166,26 @@ m.TokenTypes = {
}
m.BuiltIn = {
- ['basic'] = 'default',
- ['bit'] = 'default',
- ['bit32'] = 'default',
- ['builtin'] = 'default',
- ['coroutine'] = 'default',
- ['debug'] = 'default',
- ['ffi'] = 'default',
- ['io'] = 'default',
- ['jit'] = 'default',
- ['math'] = 'default',
- ['os'] = 'default',
- ['package'] = 'default',
- ['string'] = 'default',
- ['table'] = 'default',
- ['table.new'] = 'default',
- ['table.clear'] = 'default',
- ['utf8'] = 'default',
- ['string.buffer']='default',
+ ['basic'] = 'default',
+ ['bit'] = 'default',
+ ['bit32'] = 'default',
+ ['builtin'] = 'default',
+ ['coroutine'] = 'default',
+ ['debug'] = 'default',
+ ['ffi'] = 'default',
+ ['io'] = 'default',
+ ['jit'] = 'default',
+ ['jit.profile'] = 'default',
+ ['jit.util'] = 'default',
+ ['math'] = 'default',
+ ['os'] = 'default',
+ ['package'] = 'default',
+ ['string'] = 'default',
+ ['table'] = 'default',
+ ['table.new'] = 'default',
+ ['table.clear'] = 'default',
+ ['utf8'] = 'default',
+ ['string.buffer'] = 'default',
}
m.InlayHintKind = {
diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua
index 34f3646f..61b8ff4b 100644
--- a/script/proto/diagnostic.lua
+++ b/script/proto/diagnostic.lua
@@ -62,6 +62,7 @@ m.register {
'missing-return-value',
'redundant-return-value',
'missing-return',
+ 'missing-fields',
} {
group = 'unbalanced',
severity = 'Warning',
@@ -76,6 +77,7 @@ m.register {
'param-type-mismatch',
'cast-type-mismatch',
'return-type-mismatch',
+ 'inject-field',
} {
group = 'type-check',
severity = 'Warning',
@@ -103,6 +105,7 @@ m.register {
m.register {
'incomplete-signature-doc',
'missing-global-doc',
+ 'missing-local-export-doc',
} {
group = 'luadoc',
severity = 'Warning',
@@ -126,6 +129,14 @@ m.register {
}
m.register {
+ 'name-style-check'
+} {
+ group = 'codestyle',
+ severity = 'Warning',
+ status = 'None',
+}
+
+m.register {
'newline-call',
'newfield-call',
'ambiguity-1',
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 7875b919..2460b4ec 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -1,4 +1,3 @@
-local subprocess = require 'bee.subprocess'
local util = require 'utility'
local await = require 'await'
local pub = require 'pub'
@@ -6,6 +5,10 @@ local jsonrpc = require 'jsonrpc'
local define = require 'proto.define'
local json = require 'json'
local inspect = require 'inspect'
+local platform = require 'bee.platform'
+local fs = require 'bee.filesystem'
+local net = require 'service.net'
+local timer = require 'timer'
local reqCounter = util.counter()
@@ -29,6 +32,8 @@ local m = {}
m.ability = {}
m.waiting = {}
m.holdon = {}
+m.mode = 'stdio'
+m.client = nil
function m.getMethodName(proto)
if proto.method:sub(1, 2) == '$/' then
@@ -46,7 +51,12 @@ end
function m.send(data)
local buf = jsonrpc.encode(data)
logSend(buf)
- io.write(buf)
+ if m.mode == 'stdio' then
+ io.write(buf)
+ elseif m.mode == 'socket' then
+ m.client:write(buf)
+ net.update()
+ end
end
function m.response(id, res)
@@ -219,12 +229,51 @@ function m.doResponse(proto)
waiting.resume(proto.result)
end
-function m.listen()
- subprocess.filemode(io.stdin, 'b')
- subprocess.filemode(io.stdout, 'b')
- io.stdin:setvbuf 'no'
- io.stdout:setvbuf 'no'
- pub.task('loadProto')
+function m.listen(mode, socketPort)
+ m.mode = mode
+ if mode == 'stdio' then
+ if platform.OS == 'Windows' then
+ local windows = require 'bee.windows'
+ windows.filemode(io.stdin, 'b')
+ windows.filemode(io.stdout, 'b')
+ end
+ io.stdin:setvbuf 'no'
+ io.stdout:setvbuf 'no'
+ pub.task('loadProtoByStdio')
+ elseif mode == 'socket' then
+ local unixFolder = LOGPATH .. '/unix'
+ fs.create_directories(fs.path(unixFolder))
+ local unixPath = unixFolder .. '/' .. tostring(socketPort)
+
+ local server = net.listen('unix', unixPath)
+
+ assert(server)
+
+ local dummyClient = {
+ buf = '',
+ write = function (self, data)
+ self.buf = self.buf.. data
+ end,
+ update = function () end,
+ }
+ m.client = dummyClient
+
+ local t = timer.loop(0.1, function ()
+ net.update()
+ end)
+
+ function server:on_accept(client)
+ t:remove()
+ m.client = client
+ client:write(dummyClient.buf)
+ net.update()
+ end
+
+ pub.task('loadProtoBySocket', {
+ port = socketPort,
+ unixPath = unixPath,
+ })
+ end
end
return m