Skip to content

Commit 716091a

Browse files
committed
pass tests
1 parent 2f984c1 commit 716091a

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

script/proto/proto.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ function m.doMethod(proto)
137137
logRecieve(proto)
138138
local method, optional = m.getMethodName(proto)
139139
local abil = m.ability[method]
140+
if proto.id then
141+
m.holdon[proto.id] = proto
142+
end
140143
if not abil then
141144
if not optional then
142145
log.warn('Recieved unknown proto: ' .. method)
@@ -146,9 +149,6 @@ function m.doMethod(proto)
146149
end
147150
return
148151
end
149-
if proto.id then
150-
m.holdon[proto.id] = proto
151-
end
152152
await.call(function () ---@async
153153
--log.debug('Start method:', method)
154154
if proto.id then

script/provider/completion.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ local function enable(uri)
3030
end
3131
nonil.enable()
3232
if not client.info.capabilities.textDocument.completion.dynamicRegistration then
33+
nonil.disable()
3334
return
3435
end
3536
nonil.disable()
@@ -55,6 +56,7 @@ local function disable(uri)
5556
end
5657
nonil.enable()
5758
if not client.info.capabilities.textDocument.completion.dynamicRegistration then
59+
nonil.disable()
5860
return
5961
end
6062
nonil.disable()

script/workspace/workspace.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,6 @@ function m.reload(scp)
385385
if not m.inited then
386386
return
387387
end
388-
if TEST then
389-
return
390-
end
391388
---@async
392389
await.call(function ()
393390
m.awaitReload(scp)

test.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,18 @@ end
8282

8383
local function main()
8484
require 'utility'.enableCloseFunction()
85-
require 'core.searcher'.debugMode = true
86-
require 'language' 'zh-cn'
8785
require 'library'.init()
88-
loadDocMetas()
89-
--test 'tclient'
86+
test 'tclient'
9087

9188
--config.Lua.intelliSense.searchDepth = 5
9289
--loadDocMetas()
9390

9491
--test 'full';do return end
95-
92+
require 'workspace.workspace'.reset()
93+
require 'files'.reset()
94+
require 'workspace.scope'.reset()
95+
require 'language' 'zh-cn'
96+
loadDocMetas()
9697
require 'bee.platform'.OS = 'Windows'
9798
testAll()
9899
require 'bee.platform'.OS = 'Linux'
@@ -102,7 +103,7 @@ local function main()
102103

103104
--test 'tclient'
104105

105-
--test 'full'
106+
test 'full'
106107

107108
print('测试完成')
108109
end

test/tclient/lclient.lua

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ function mt:start(callback)
4949
finished = true
5050
end)
5151

52+
local jumpedTime = 0
53+
5254
while true do
5355
if finished then
5456
break
@@ -64,6 +66,10 @@ function mt:start(callback)
6466
goto CONTINUE
6567
end
6668
timer.timeJump(1.0)
69+
jumpedTime = jumpedTime + 1.0
70+
if jumpedTime > 2 * 60 * 60 then
71+
error('two hours later ...')
72+
end
6773
::CONTINUE::
6874
end
6975

@@ -111,10 +117,14 @@ function mt:update()
111117
for _, out in ipairs(outs) do
112118
if out.method then
113119
local callback = self._methods[out.method]
114-
proto.doResponse {
115-
id = out.id,
116-
params = callback(out.params),
117-
}
120+
if callback then
121+
proto.doResponse {
122+
id = out.id,
123+
params = callback(out.params),
124+
}
125+
elseif out.method:sub(1, 2) ~= '$/' then
126+
error('Unknown method: ' .. out.method)
127+
end
118128
else
119129
local callback = self._waiting[out.id]
120130
self._waiting[out.id] = nil
@@ -124,8 +134,19 @@ function mt:update()
124134
return true
125135
end
126136

127-
function mt:register(name, callback)
128-
self._methods[name] = callback
137+
function mt:register(method, callback)
138+
self._methods[method] = callback
139+
end
140+
141+
function mt:registerFakers()
142+
for _, method in ipairs {
143+
'workspace/configuration',
144+
'textDocument/publishDiagnostics',
145+
} do
146+
self:register(method, function ()
147+
return nil
148+
end)
149+
end
129150
end
130151

131152
---@return languageClient

test/tclient/tests/single-mode.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ local util = require 'utility'
55

66
---@async
77
lclient():start(function (client)
8-
client:register('workspace/configuration', function ()
9-
return nil
10-
end)
8+
client:registerFakers()
119

1210
client:awaitRequest('initialize', {
1311
clientInfo = {
@@ -33,7 +31,7 @@ print(x)
3331

3432
ws.awaitReady()
3533

36-
local locations = client:awaitRequest('textDocument.definition', {
34+
local locations = client:awaitRequest('textDocument/definition', {
3735
textDocument = { uri = 'test://single-file.lua' },
3836
position = { line = 1, character = 7 },
3937
})

0 commit comments

Comments
 (0)