summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfesily <fesil@foxmail.com>2023-05-24 13:53:42 +0800
committerGitHub <noreply@github.com>2023-05-24 13:53:42 +0800
commit754e7194e45892a5d596cf9f331d4667b7542aa8 (patch)
tree065a9d174cedbf667a20de834650e93eee28d341
parenta41227005417301dcf2f2d93abcba8ed3521901c (diff)
parent4e2e282eaa79979c0bca2c4d1a2b3c1b2a64544e (diff)
downloadlua-language-server-754e7194e45892a5d596cf9f331d4667b7542aa8.zip
Merge branch 'LuaLS:master' into meta-support-metable
-rw-r--r--.vscode/launch.json3
m---------3rd/EmmyLuaCodeStyle0
-rw-r--r--changelog.md4
-rw-r--r--script/brave/work.lua70
-rw-r--r--script/meta/bee/socket.lua7
-rw-r--r--script/plugins/ffi/c-parser/cpp.lua30
-rw-r--r--script/plugins/ffi/c-parser/ctypes.lua1
-rw-r--r--script/plugins/ffi/searchCode.lua3
-rw-r--r--script/proto/proto.lua12
-rw-r--r--script/vm/tracer.lua6
-rw-r--r--test/type_inference/init.lua6
11 files changed, 92 insertions, 50 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 2b077bee..b80e7f49 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -36,9 +36,6 @@
]
],
"windows": {
- "name": "🍄attach",
- "type": "lua",
- "request": "attach",
"sourceMaps": [
[
"script\\*",
diff --git a/3rd/EmmyLuaCodeStyle b/3rd/EmmyLuaCodeStyle
-Subproject 28bff899e7590f594b15146ea5f3a791268d142
+Subproject edf464104a039f15ed39d700ba5e4c3a932c786
diff --git a/changelog.md b/changelog.md
index 50328c9c..b1e918cd 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,7 +1,11 @@
# changelog
## 3.6.20
+`2023-5-23`
* `NEW` support connecting by socket with `--socket=PORT`
+* `FIX` [#2113]
+
+[#2113]: https://github.com/LuaLS/lua-language-server/issues/2113
## 3.6.19
`2023-4-26`
diff --git a/script/brave/work.lua b/script/brave/work.lua
index 3b82b452..9eb756eb 100644
--- a/script/brave/work.lua
+++ b/script/brave/work.lua
@@ -13,34 +13,60 @@ brave.on('loadProtoByStdio', function ()
end
end)
-brave.on('loadProtoBySocket', function (fdHandle)
+brave.on('loadProtoBySocket', function (param)
local jsonrpc = require 'jsonrpc'
local socket = require 'bee.socket'
- local thread = require 'bee.thread'
- local fd = socket.fd(fdHandle)
+ local util = require 'utility'
+ local rfd = socket.fd(param.rfd)
+ local wfd = socket.fd(param.wfd)
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)
+
+ ---@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
- end)
- --log.debug('loaded proto', proto.method)
- if not proto then
- brave.push('protoerror', err)
- return
+ brave.push('proto', proto)
end
- brave.push('proto', proto)
+ end)
+
+ while true do
+ local rd = socket.select({rfd, wfd}, nil, 10)
+ if not rd or #rd == 0 then
+ goto continue
+ end
+ if util.arrayHas(rd, wfd) then
+ local needSend = wfd:recv()
+ if needSend then
+ rfd:send(needSend)
+ elseif needSend == nil then
+ error('socket closed!')
+ end
+ end
+ if util.arrayHas(rd, rfd) then
+ local recved = rfd:recv()
+ if recved then
+ buf = buf .. recved
+ elseif recved == nil then
+ error('socket closed!')
+ end
+ coroutine.resume(parser)
+ end
+ ::continue::
end
end)
diff --git a/script/meta/bee/socket.lua b/script/meta/bee/socket.lua
index b77c498b..1724cbb3 100644
--- a/script/meta/bee/socket.lua
+++ b/script/meta/bee/socket.lua
@@ -22,6 +22,10 @@ function socket.select(readfds, writefds, timeout) end
---@return bee.socket.fd
function socket.fd(handle) end
+---@return bee.socket.fd
+---@return bee.socket.fd
+function socket.pair() end
+
---@class bee.socket.fd
local fd = {}
@@ -53,6 +57,9 @@ function fd:send(content) end
---@return lightuserdata
function fd:handle() end
+---@return lightuserdata
+function fd:detach() end
+
---@return boolean
function fd:status() end
diff --git a/script/plugins/ffi/c-parser/cpp.lua b/script/plugins/ffi/c-parser/cpp.lua
index f885e724..eaa34330 100644
--- a/script/plugins/ffi/c-parser/cpp.lua
+++ b/script/plugins/ffi/c-parser/cpp.lua
@@ -1,4 +1,3 @@
-
local cpp = {}
local typed = require("plugins.ffi.c-parser.typed")
@@ -6,27 +5,14 @@ local c99 = require("plugins.ffi.c-parser.c99")
local SEP = package.config:sub(1,1)
-local shl, shr
-if jit then
- shl = function(a, b)
- return bit.lshift(a, b)
- end
- shr = function(a, b)
- return bit.rshift(a, b)
- end
-else
- shl, shr = load([[
- local function shl(a, b)
- return a << b
- end
- local function shr(a, b)
- return a >> b
- end
- return shl, shr
- ]])()
+local function shl(a, b)
+ return a << b
+end
+local function shr(a, b)
+ return a >> b
end
-local function debug() end
+local function debug(...) end
--[[
local inspect = require("inspect")
local function debug(...)
@@ -623,6 +609,7 @@ cpp.parse_file = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(filenam
ctx = {
incdirs = cpp_include_paths(),
defines = gcc_default_defines(),
+ ---@type any[]
ifmode = { true },
output = {},
current_dir = {}
@@ -785,7 +772,7 @@ cpp.parse_context = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(cont
for cur, lineitem in ipairs(linelist) do
local line = lineitem.line
local tk = lineitem.tk
- debug(filename, cur, ifmode[#ifmode], #ifmode, line)
+ debug(cur, ifmode[#ifmode], #ifmode, line)
if #ifmode == 1 and (tk.directive == "elif" or tk.directive == "else" or tk.directive == "endif") then
return nil, "unexpected directive " .. tk.directive
@@ -812,6 +799,7 @@ cpp.parse_context = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(cont
elseif tk.directive == "if" then
table.insert(ifmode, run_expression(ctx, tk.exp))
elseif tk.directive == "elif" then
+---@diagnostic disable-next-line: assign-type-mismatch
ifmode[#ifmode] = "skip"
elseif tk.directive == "else" then
ifmode[#ifmode] = not ifmode[#ifmode]
diff --git a/script/plugins/ffi/c-parser/ctypes.lua b/script/plugins/ffi/c-parser/ctypes.lua
index 284fbe84..81d0ccf6 100644
--- a/script/plugins/ffi/c-parser/ctypes.lua
+++ b/script/plugins/ffi/c-parser/ctypes.lua
@@ -107,6 +107,7 @@ local convert_value = typed("TypeList, table -> CType?, string?", function (lst,
src.ids = util.expandSingle(src.ids)
-- FIXME multiple ids, e.g.: int *x, y, *z;
local ok
+---@diagnostic disable-next-line: cast-local-type
ok, name, ret_pointer, idxs = get_name(src.id or src.ids)
if not ok then
return nil, name
diff --git a/script/plugins/ffi/searchCode.lua b/script/plugins/ffi/searchCode.lua
index 9e74e7c0..86dbc680 100644
--- a/script/plugins/ffi/searchCode.lua
+++ b/script/plugins/ffi/searchCode.lua
@@ -3,6 +3,9 @@ local vm = require 'vm'
local function getLiterals(arg)
local literals = vm.getLiterals(arg)
local res = {}
+ if not literals then
+ return res
+ end
for k, v in pairs(literals) do
if type(k) == 'string' then
res[#res+1] = k
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index fb623106..73544ffc 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -237,10 +237,14 @@ function m.listen(mode, socketPort)
io.stdout:setvbuf 'no'
pub.task('loadProtoByStdio')
elseif mode == 'socket' then
- local fd = assert(socket('tcp'))
- fd:connect('127.0.0.1', socketPort)
- m.fd = fd
- pub.task('loadProtoBySocket', fd:handle())
+ local rfd = assert(socket('tcp'))
+ rfd:connect('127.0.0.1', socketPort)
+ local wfd1, wfd2 = socket.pair()
+ m.fd = wfd1
+ pub.task('loadProtoBySocket', {
+ wfd = wfd2:detach(),
+ rfd = rfd:detach(),
+ })
end
end
diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua
index a8aa0c7c..e47a9824 100644
--- a/script/vm/tracer.lua
+++ b/script/vm/tracer.lua
@@ -296,6 +296,9 @@ local lookIntoChild = util.switch()
topNode = tracer.nodes[action]:copy()
end
end
+ if action.type == 'repeat' then
+ tracer:lookIntoChild(action.filter, topNode)
+ end
return topNode, outNode
end)
: case 'in'
@@ -745,6 +748,9 @@ function mt:lookIntoBlock(block, start, node)
::CONTINUE::
end
self.nodes[block] = node
+ if block.type == 'repeat' then
+ self:lookIntoChild(block.filter, node)
+ end
if block.type == 'do'
or block.type == 'loop'
or block.type == 'in'
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 6a8ba588..55b4f7af 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -4292,3 +4292,9 @@ local m = setmetatable({},{ __index = { a = 1 } })
m.<?a?>
]]
+
+TEST 'integer' [[
+local x = 1
+repeat
+until <?x?>
+]]