Skip to content

Commit b7fdf17

Browse files
committed
update
1 parent 9cc6ca5 commit b7fdf17

File tree

6 files changed

+82
-27
lines changed

6 files changed

+82
-27
lines changed

script/proto/proto.lua

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ function m.awaitRequest(name, params)
9292
params = params,
9393
}
9494
local result, error = await.wait(function (resume)
95-
m.waiting[id] = resume
95+
m.waiting[id] = {
96+
id = id,
97+
method = name,
98+
params = params,
99+
resume = resume,
100+
}
96101
end)
97102
if error then
98103
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
@@ -110,14 +115,19 @@ function m.request(name, params, callback)
110115
--log.debug('Request', name, #buf)
111116
logSend(buf)
112117
io.write(buf)
113-
m.waiting[id] = function (result, error)
114-
if error then
115-
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
116-
end
117-
if callback then
118-
callback(result)
118+
m.waiting[id] = {
119+
id = id,
120+
method = name,
121+
params = params,
122+
resume = function (result, error)
123+
if error then
124+
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
125+
end
126+
if callback then
127+
callback(result)
128+
end
119129
end
120-
end
130+
}
121131
end
122132

123133
local secretOption = {
@@ -192,17 +202,17 @@ end
192202
function m.doResponse(proto)
193203
logRecieve(proto)
194204
local id = proto.id
195-
local resume = m.waiting[id]
196-
if not resume then
205+
local waiting = m.waiting[id]
206+
if not waiting then
197207
log.warn('Response id not found: ' .. util.dump(proto))
198208
return
199209
end
200210
m.waiting[id] = nil
201211
if proto.error then
202-
resume(nil, proto.error)
212+
waiting.resume(nil, proto.error)
203213
return
204214
end
205-
resume(proto.result)
215+
waiting.resume(proto.result)
206216
end
207217

208218
function m.listen()

test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ TEST = true
88
DEVELOP = true
99
--FOOTPRINT = true
1010
--TRACE = true
11-
LOGPATH = LOGPATH or (ROOT .. '/log')
12-
METAPATH = METAPATH or (ROOT .. '/meta')
11+
LOGPATH = LOGPATH or (ROOT:string() .. '/log')
12+
METAPATH = METAPATH or (ROOT:string() .. '/meta')
1313

1414
collectgarbage 'generational'
1515

test/tclient/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
require 'tclient.tests.single-mode'
2+
require 'tclient.tests.library-ignore-limit'

test/tclient/lclient.lua

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ function mt:_flushServer()
3636
files.reset()
3737
end
3838

39+
---@async
40+
function mt:initialize(params)
41+
self:awaitRequest('initialize', params or {})
42+
self:notify('initialized')
43+
end
44+
45+
function mt:reportHangs()
46+
local hangs = {}
47+
hangs[#hangs+1] = ('====== C -> S ======')
48+
for _, waiting in util.sortPairs(self._waiting) do
49+
hangs[#hangs+1] = ('%03d %s'):format(waiting.id, waiting.method)
50+
end
51+
hangs[#hangs+1] = ('====== S -> C ======')
52+
for _, waiting in util.sortPairs(proto.waiting) do
53+
hangs[#hangs+1] = ('%03d %s'):format(waiting.id, waiting.method)
54+
end
55+
hangs[#hangs+1] = ('====================')
56+
return table.concat(hangs, '\n')
57+
end
58+
3959
---@param callback async fun(client: languageClient)
4060
function mt:start(callback)
4161
self:_fakeProto()
@@ -68,7 +88,7 @@ function mt:start(callback)
6888
timer.timeJump(1.0)
6989
jumpedTime = jumpedTime + 1.0
7090
if jumpedTime > 2 * 60 * 60 then
71-
error('two hours later ...')
91+
error('two hours later ...\n' .. self:reportHangs())
7292
end
7393
::CONTINUE::
7494
end
@@ -93,7 +113,11 @@ end
93113

94114
function mt:request(method, params, callback)
95115
local id = counter()
96-
self._waiting[id] = callback
116+
self._waiting[id] = {
117+
id = id,
118+
params = params,
119+
callback = callback,
120+
}
97121
proto.doMethod {
98122
id = id,
99123
method = method,
@@ -126,7 +150,7 @@ function mt:update()
126150
error('Unknown method: ' .. out.method)
127151
end
128152
else
129-
local callback = self._waiting[out.id]
153+
local callback = self._waiting[out.id].callback
130154
self._waiting[out.id] = nil
131155
callback(out.result, out.error)
132156
end
@@ -141,6 +165,8 @@ end
141165
function mt:registerFakers()
142166
for _, method in ipairs {
143167
'workspace/configuration',
168+
'workspace/semanticTokens/refresh',
169+
'window/workDoneProgress/create',
144170
'textDocument/publishDiagnostics',
145171
} do
146172
self:register(method, function ()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local lclient = require 'tclient.lclient'
2+
local util = require 'utility'
3+
local ws = require 'workspace'
4+
local files = require 'files'
5+
local furi = require 'file-uri'
6+
7+
local libraryPath = LOGPATH .. '/large-file-library'
8+
local largeFilePath = LOGPATH .. '/large-file-library/large-file.lua'
9+
10+
---@async
11+
lclient():start(function (client)
12+
client:registerFakers()
13+
14+
client:register('workspace/configuration', function ()
15+
return {
16+
['Lua.workspace.library'] = { libraryPath }
17+
}
18+
end)
19+
20+
util.saveFile(largeFilePath, string.rep('--this is a large file\n', 20000))
21+
22+
client:initialize()
23+
24+
ws.awaitReady()
25+
26+
assert(files.getState(furi.encode(largeFilePath)) ~= nil)
27+
end)

test/tclient/tests/single-mode.lua

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@ local util = require 'utility'
66
---@async
77
lclient():start(function (client)
88
client:registerFakers()
9-
10-
client:awaitRequest('initialize', {
11-
clientInfo = {
12-
name = 'unit-test',
13-
version = 'single-mode',
14-
},
15-
rootUri = nil,
16-
})
17-
18-
client:notify('initialized')
9+
client:initialize()
1910

2011
client:notify('textDocument/didOpen', {
2112
textDocument = {

0 commit comments

Comments
 (0)