summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/proto/proto.lua34
-rw-r--r--test.lua4
-rw-r--r--test/tclient/init.lua1
-rw-r--r--test/tclient/lclient.lua32
-rw-r--r--test/tclient/tests/library-ignore-limit.lua27
-rw-r--r--test/tclient/tests/single-mode.lua11
6 files changed, 82 insertions, 27 deletions
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index b29d44b0..4ba99b88 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -92,7 +92,12 @@ function m.awaitRequest(name, params)
params = params,
}
local result, error = await.wait(function (resume)
- m.waiting[id] = resume
+ m.waiting[id] = {
+ id = id,
+ method = name,
+ params = params,
+ resume = resume,
+ }
end)
if error then
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
@@ -110,14 +115,19 @@ function m.request(name, params, callback)
--log.debug('Request', name, #buf)
logSend(buf)
io.write(buf)
- m.waiting[id] = function (result, error)
- if error then
- log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
- end
- if callback then
- callback(result)
+ m.waiting[id] = {
+ id = id,
+ method = name,
+ params = params,
+ resume = function (result, error)
+ if error then
+ log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
+ end
+ if callback then
+ callback(result)
+ end
end
- end
+ }
end
local secretOption = {
@@ -192,17 +202,17 @@ end
function m.doResponse(proto)
logRecieve(proto)
local id = proto.id
- local resume = m.waiting[id]
- if not resume then
+ local waiting = m.waiting[id]
+ if not waiting then
log.warn('Response id not found: ' .. util.dump(proto))
return
end
m.waiting[id] = nil
if proto.error then
- resume(nil, proto.error)
+ waiting.resume(nil, proto.error)
return
end
- resume(proto.result)
+ waiting.resume(proto.result)
end
function m.listen()
diff --git a/test.lua b/test.lua
index 61b5d766..f094c0c2 100644
--- a/test.lua
+++ b/test.lua
@@ -8,8 +8,8 @@ TEST = true
DEVELOP = true
--FOOTPRINT = true
--TRACE = true
-LOGPATH = LOGPATH or (ROOT .. '/log')
-METAPATH = METAPATH or (ROOT .. '/meta')
+LOGPATH = LOGPATH or (ROOT:string() .. '/log')
+METAPATH = METAPATH or (ROOT:string() .. '/meta')
collectgarbage 'generational'
diff --git a/test/tclient/init.lua b/test/tclient/init.lua
index 627aed17..8e7df570 100644
--- a/test/tclient/init.lua
+++ b/test/tclient/init.lua
@@ -1 +1,2 @@
require 'tclient.tests.single-mode'
+require 'tclient.tests.library-ignore-limit'
diff --git a/test/tclient/lclient.lua b/test/tclient/lclient.lua
index 4273d88c..52b72290 100644
--- a/test/tclient/lclient.lua
+++ b/test/tclient/lclient.lua
@@ -36,6 +36,26 @@ function mt:_flushServer()
files.reset()
end
+---@async
+function mt:initialize(params)
+ self:awaitRequest('initialize', params or {})
+ self:notify('initialized')
+end
+
+function mt:reportHangs()
+ local hangs = {}
+ hangs[#hangs+1] = ('====== C -> S ======')
+ for _, waiting in util.sortPairs(self._waiting) do
+ hangs[#hangs+1] = ('%03d %s'):format(waiting.id, waiting.method)
+ end
+ hangs[#hangs+1] = ('====== S -> C ======')
+ for _, waiting in util.sortPairs(proto.waiting) do
+ hangs[#hangs+1] = ('%03d %s'):format(waiting.id, waiting.method)
+ end
+ hangs[#hangs+1] = ('====================')
+ return table.concat(hangs, '\n')
+end
+
---@param callback async fun(client: languageClient)
function mt:start(callback)
self:_fakeProto()
@@ -68,7 +88,7 @@ function mt:start(callback)
timer.timeJump(1.0)
jumpedTime = jumpedTime + 1.0
if jumpedTime > 2 * 60 * 60 then
- error('two hours later ...')
+ error('two hours later ...\n' .. self:reportHangs())
end
::CONTINUE::
end
@@ -93,7 +113,11 @@ end
function mt:request(method, params, callback)
local id = counter()
- self._waiting[id] = callback
+ self._waiting[id] = {
+ id = id,
+ params = params,
+ callback = callback,
+ }
proto.doMethod {
id = id,
method = method,
@@ -126,7 +150,7 @@ function mt:update()
error('Unknown method: ' .. out.method)
end
else
- local callback = self._waiting[out.id]
+ local callback = self._waiting[out.id].callback
self._waiting[out.id] = nil
callback(out.result, out.error)
end
@@ -141,6 +165,8 @@ end
function mt:registerFakers()
for _, method in ipairs {
'workspace/configuration',
+ 'workspace/semanticTokens/refresh',
+ 'window/workDoneProgress/create',
'textDocument/publishDiagnostics',
} do
self:register(method, function ()
diff --git a/test/tclient/tests/library-ignore-limit.lua b/test/tclient/tests/library-ignore-limit.lua
new file mode 100644
index 00000000..66d6cc09
--- /dev/null
+++ b/test/tclient/tests/library-ignore-limit.lua
@@ -0,0 +1,27 @@
+local lclient = require 'tclient.lclient'
+local util = require 'utility'
+local ws = require 'workspace'
+local files = require 'files'
+local furi = require 'file-uri'
+
+local libraryPath = LOGPATH .. '/large-file-library'
+local largeFilePath = LOGPATH .. '/large-file-library/large-file.lua'
+
+---@async
+lclient():start(function (client)
+ client:registerFakers()
+
+ client:register('workspace/configuration', function ()
+ return {
+ ['Lua.workspace.library'] = { libraryPath }
+ }
+ end)
+
+ util.saveFile(largeFilePath, string.rep('--this is a large file\n', 20000))
+
+ client:initialize()
+
+ ws.awaitReady()
+
+ assert(files.getState(furi.encode(largeFilePath)) ~= nil)
+end)
diff --git a/test/tclient/tests/single-mode.lua b/test/tclient/tests/single-mode.lua
index 897eee31..d26eb98a 100644
--- a/test/tclient/tests/single-mode.lua
+++ b/test/tclient/tests/single-mode.lua
@@ -6,16 +6,7 @@ local util = require 'utility'
---@async
lclient():start(function (client)
client:registerFakers()
-
- client:awaitRequest('initialize', {
- clientInfo = {
- name = 'unit-test',
- version = 'single-mode',
- },
- rootUri = nil,
- })
-
- client:notify('initialized')
+ client:initialize()
client:notify('textDocument/didOpen', {
textDocument = {