Skip to content

Commit e0c2f03

Browse files
authored
Merge branch 'master' into ffi-plugin-lazyload
2 parents 622b174 + adc1c1b commit e0c2f03

File tree

13 files changed

+100
-54
lines changed

13 files changed

+100
-54
lines changed

.vscode/launch.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
]
3737
],
3838
"windows": {
39-
"name": "🍄attach",
40-
"type": "lua",
41-
"request": "attach",
4239
"sourceMaps": [
4340
[
4441
"script\\*",

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# changelog
22

3+
## 3.6.21
4+
`2023-5-24`
5+
* `FIX` disable ffi plugin
6+
37
## 3.6.20
8+
`2023-5-23`
49
* `NEW` support connecting by socket with `--socket=PORT`
10+
* `FIX` [#2113]
11+
12+
[#2113]: https://github.com/LuaLS/lua-language-server/issues/2113
513

614
## 3.6.19
715
`2023-4-26`

meta/template/jit.profile.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
local profile = {}
55

66
---@param mode string
7-
---@param func fun(L:thread,samples:integer,vmst:string)
7+
---@param func fun(L: thread, samples: integer, vmst: string)
88
function profile.start(mode, func)
99
end
1010

1111
function profile.stop()
1212
end
1313

14-
---@overload fun(th:thread,fmt:string,depth:integer)
14+
---@overload fun(th: thread, fmt: string, depth: integer)
1515
---@param fmt string
1616
---@param depth integer
1717
function profile.dumpstack(fmt, depth)

meta/template/jit.util.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ end
105105
function util.tracemc(tr)
106106
end
107107

108-
---@overload fun(exitno:integer):integer
108+
---@overload fun(exitno: integer): integer
109109
---@param tr Trace
110110
---@param exitno integer
111111
---@return integer? addr

script/brave/work.lua

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,60 @@ brave.on('loadProtoByStdio', function ()
1313
end
1414
end)
1515

16-
brave.on('loadProtoBySocket', function (fdHandle)
16+
brave.on('loadProtoBySocket', function (param)
1717
local jsonrpc = require 'jsonrpc'
1818
local socket = require 'bee.socket'
19-
local thread = require 'bee.thread'
20-
local fd = socket.fd(fdHandle)
19+
local util = require 'utility'
20+
local rfd = socket.fd(param.rfd)
21+
local wfd = socket.fd(param.wfd)
2122
local buf = ''
22-
while true do
23-
local proto, err = jsonrpc.decode(function (len)
24-
while true do
25-
if #buf >= len then
26-
local res = buf:sub(1, len)
27-
buf = buf:sub(len + 1)
28-
return res
29-
end
30-
local data = fd:recv()
31-
if data then
32-
buf = buf .. data
33-
else
34-
thread.sleep(0.01)
23+
24+
---@async
25+
local parser = coroutine.create(function ()
26+
while true do
27+
---@async
28+
local proto, err = jsonrpc.decode(function (len)
29+
while true do
30+
if #buf >= len then
31+
local res = buf:sub(1, len)
32+
buf = buf:sub(len + 1)
33+
return res
34+
end
35+
coroutine.yield()
3536
end
37+
end)
38+
--log.debug('loaded proto', proto.method)
39+
if not proto then
40+
brave.push('protoerror', err)
41+
return
3642
end
37-
end)
38-
--log.debug('loaded proto', proto.method)
39-
if not proto then
40-
brave.push('protoerror', err)
41-
return
43+
brave.push('proto', proto)
4244
end
43-
brave.push('proto', proto)
45+
end)
46+
47+
while true do
48+
local rd = socket.select({rfd, wfd}, nil, 10)
49+
if not rd or #rd == 0 then
50+
goto continue
51+
end
52+
if util.arrayHas(rd, wfd) then
53+
local needSend = wfd:recv()
54+
if needSend then
55+
rfd:send(needSend)
56+
elseif needSend == nil then
57+
error('socket closed!')
58+
end
59+
end
60+
if util.arrayHas(rd, rfd) then
61+
local recved = rfd:recv()
62+
if recved then
63+
buf = buf .. recved
64+
elseif recved == nil then
65+
error('socket closed!')
66+
end
67+
coroutine.resume(parser)
68+
end
69+
::continue::
4470
end
4571
end)
4672

script/meta/bee/socket.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function socket.select(readfds, writefds, timeout) end
2222
---@return bee.socket.fd
2323
function socket.fd(handle) end
2424

25+
---@return bee.socket.fd
26+
---@return bee.socket.fd
27+
function socket.pair() end
28+
2529
---@class bee.socket.fd
2630
local fd = {}
2731

@@ -53,6 +57,9 @@ function fd:send(content) end
5357
---@return lightuserdata
5458
function fd:handle() end
5559

60+
---@return lightuserdata
61+
function fd:detach() end
62+
5663
---@return boolean
5764
function fd:status() end
5865

script/plugins/ffi/c-parser/cpp.lua

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
21
local cpp = {}
32

43
local typed = require("plugins.ffi.c-parser.typed")
54
local c99 = require("plugins.ffi.c-parser.c99")
65

76
local SEP = package.config:sub(1,1)
87

9-
local shl, shr
10-
if jit then
11-
shl = function(a, b)
12-
return bit.lshift(a, b)
13-
end
14-
shr = function(a, b)
15-
return bit.rshift(a, b)
16-
end
17-
else
18-
shl, shr = load([[
19-
local function shl(a, b)
20-
return a << b
21-
end
22-
local function shr(a, b)
23-
return a >> b
24-
end
25-
return shl, shr
26-
]])()
8+
local function shl(a, b)
9+
return a << b
10+
end
11+
local function shr(a, b)
12+
return a >> b
2713
end
2814

29-
local function debug() end
15+
local function debug(...) end
3016
--[[
3117
local inspect = require("inspect")
3218
local function debug(...)
@@ -623,6 +609,7 @@ cpp.parse_file = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(filenam
623609
ctx = {
624610
incdirs = cpp_include_paths(),
625611
defines = gcc_default_defines(),
612+
---@type any[]
626613
ifmode = { true },
627614
output = {},
628615
current_dir = {}
@@ -785,7 +772,7 @@ cpp.parse_context = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(cont
785772
for cur, lineitem in ipairs(linelist) do
786773
local line = lineitem.line
787774
local tk = lineitem.tk
788-
debug(filename, cur, ifmode[#ifmode], #ifmode, line)
775+
debug(cur, ifmode[#ifmode], #ifmode, line)
789776

790777
if #ifmode == 1 and (tk.directive == "elif" or tk.directive == "else" or tk.directive == "endif") then
791778
return nil, "unexpected directive " .. tk.directive
@@ -812,6 +799,7 @@ cpp.parse_context = typed("string, FILE*?, Ctx? -> Ctx?, string?", function(cont
812799
elseif tk.directive == "if" then
813800
table.insert(ifmode, run_expression(ctx, tk.exp))
814801
elseif tk.directive == "elif" then
802+
---@diagnostic disable-next-line: assign-type-mismatch
815803
ifmode[#ifmode] = "skip"
816804
elseif tk.directive == "else" then
817805
ifmode[#ifmode] = not ifmode[#ifmode]

script/plugins/ffi/c-parser/ctypes.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ local convert_value = typed("TypeList, table -> CType?, string?", function (lst,
107107
src.ids = util.expandSingle(src.ids)
108108
-- FIXME multiple ids, e.g.: int *x, y, *z;
109109
local ok
110+
---@diagnostic disable-next-line: cast-local-type
110111
ok, name, ret_pointer, idxs = get_name(src.id or src.ids)
111112
if not ok then
112113
return nil, name

script/plugins/ffi/searchCode.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ local vm = require 'vm'
33
local function getLiterals(arg)
44
local literals = vm.getLiterals(arg)
55
local res = {}
6+
if not literals then
7+
return res
8+
end
69
for k, v in pairs(literals) do
710
if type(k) == 'string' then
811
res[#res+1] = k

0 commit comments

Comments
 (0)