Skip to content

Commit b6eed1d

Browse files
committed
stash
1 parent c2d2e7a commit b6eed1d

File tree

12 files changed

+234
-91
lines changed

12 files changed

+234
-91
lines changed

script/config/config.lua

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ m.nullSymbols = {
234234
---@param nowValue any
235235
---@param rawValue any
236236
local function update(scp, key, nowValue, rawValue)
237-
local now = scp:get 'config.now'
238-
local raw = scp:get 'config.raw'
237+
local now = m.getNowTable(scp)
238+
local raw = m.getRawTable(scp)
239239

240240
now[key] = nowValue
241241
raw[key] = rawValue
@@ -245,7 +245,7 @@ end
245245
---@param key? string
246246
---@return scope
247247
local function getScope(uri, key)
248-
local raw = scope.override:get 'config.raw'
248+
local raw = m.getRawTable(scope.override)
249249
if raw then
250250
if not key or raw[key] ~= nil then
251251
return scope.override
@@ -256,7 +256,7 @@ local function getScope(uri, key)
256256
local scp = scope.getFolder(uri) or scope.getLinkedScope(uri)
257257
if scp then
258258
if not key
259-
or (scp:get 'config.raw' and scp:get 'config.raw' [key] ~= nil) then
259+
or m.getRawTable(scp)[key] ~= nil then
260260
return scp
261261
end
262262
end
@@ -272,7 +272,7 @@ function m.setByScope(scp, key, value)
272272
if not unit then
273273
return false
274274
end
275-
local raw = scp:get 'config.raw'
275+
local raw = m.getRawTable(scp)
276276
if util.equal(raw[key], value) then
277277
return false
278278
end
@@ -358,7 +358,7 @@ end
358358
---@return any
359359
function m.get(uri, key)
360360
local scp = getScope(uri, key)
361-
local value = scp:get 'config.now' [key]
361+
local value = m.getNowTable(scp)[key]
362362
if value == nil then
363363
value = Template[key].default
364364
end
@@ -373,7 +373,7 @@ end
373373
---@return any
374374
function m.getRaw(uri, key)
375375
local scp = getScope(uri, key)
376-
local value = scp:get 'config.raw' [key]
376+
local value = m.getRawTable(scp)[key]
377377
if value == nil then
378378
value = Template[key].default
379379
end
@@ -383,10 +383,22 @@ function m.getRaw(uri, key)
383383
return value
384384
end
385385

386+
---@param scp scope
387+
function m.getNowTable(scp)
388+
return scp:get 'config.now'
389+
or scp:set('config.now', {})
390+
end
391+
392+
---@param scp scope
393+
function m.getRawTable(scp)
394+
return scp:get 'config.raw'
395+
or scp:set('config.raw', {})
396+
end
397+
386398
---@param scp scope
387399
---@param ... table
388400
function m.update(scp, ...)
389-
local oldConfig = scp:get 'config.now'
401+
local oldConfig = m.getNowTable(scp)
390402
local newConfig = {}
391403
scp:set('config.now', newConfig)
392404
scp:set('config.raw', {})
@@ -460,6 +472,4 @@ function m.addNullSymbol(null)
460472
m.nullSymbols[null] = true
461473
end
462474

463-
m.update(scope.fallback, {})
464-
465475
return m

script/gc.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local util = require 'share.utility'
1+
local util = require 'utility'
22

33
---@class gc
44
---@field _list table

script/proto/proto.lua

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ function m.on(method, callback)
4141
m.ability[method] = callback
4242
end
4343

44+
function m.send(data)
45+
local buf = jsonrpc.encode(data)
46+
logSend(buf)
47+
io.write(buf)
48+
end
49+
4450
function m.response(id, res)
4551
if id == nil then
4652
log.error('Response id is nil!', util.dump(res))
@@ -51,10 +57,7 @@ function m.response(id, res)
5157
local data = {}
5258
data.id = id
5359
data.result = res == nil and json.null or res
54-
local buf = jsonrpc.encode(data)
55-
--log.debug('Response', id, #buf)
56-
logSend(buf)
57-
io.write(buf)
60+
m.send(data)
5861
end
5962

6063
function m.responseErr(id, code, message)
@@ -64,39 +67,30 @@ function m.responseErr(id, code, message)
6467
end
6568
assert(m.holdon[id])
6669
m.holdon[id] = nil
67-
local buf = jsonrpc.encode {
70+
m.send {
6871
id = id,
6972
error = {
7073
code = code,
7174
message = message,
7275
}
7376
}
74-
--log.debug('ResponseErr', id, #buf)
75-
logSend(buf)
76-
io.write(buf)
7777
end
7878

7979
function m.notify(name, params)
80-
local buf = jsonrpc.encode {
80+
m.send {
8181
method = name,
8282
params = params,
8383
}
84-
--log.debug('Notify', name, #buf)
85-
logSend(buf)
86-
io.write(buf)
8784
end
8885

8986
---@async
9087
function m.awaitRequest(name, params)
9188
local id = reqCounter()
92-
local buf = jsonrpc.encode {
89+
m.send {
9390
id = id,
9491
method = name,
9592
params = params,
9693
}
97-
--log.debug('Request', name, #buf)
98-
logSend(buf)
99-
io.write(buf)
10094
local result, error = await.wait(function (resume)
10195
m.waiting[id] = resume
10296
end)

script/timer.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local curFrame = 0
1212
local maxFrame = 0
1313
local curIndex = 0
1414
local tarFrame = 0
15+
local fwFrame = 0
1516
local freeQueue = {}
1617
local timer = {}
1718

@@ -206,7 +207,7 @@ end
206207

207208
local lastClock = monotonic()
208209
function m.update()
209-
local currentClock = monotonic()
210+
local currentClock = monotonic() + fwFrame
210211
local delta = currentClock - lastClock
211212
lastClock = currentClock
212213
if curIndex ~= 0 then
@@ -220,4 +221,8 @@ function m.update()
220221
end
221222
end
222223

224+
function m.timeJump(delta)
225+
fwFrame = fwFrame + mathFloor(delta * 1000.0)
226+
end
227+
223228
return m

script/workspace/workspace.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function m.reset()
5656
m.folders = {}
5757
m.rootUri = nil
5858
end
59+
m.reset()
5960

6061
function m.getRootUri(uri)
6162
local scp = m.getScope(uri)

test.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ local function main()
8686
require 'language' 'zh-cn'
8787
require 'library'.init()
8888
loadDocMetas()
89+
test 'tclient'
8990

9091
--config.Lua.intelliSense.searchDepth = 5
9192
--loadDocMetas()
@@ -99,7 +100,7 @@ local function main()
99100
require 'bee.platform'.OS = 'macOS'
100101
testAll()
101102

102-
test 'client'
103+
test 'tclient'
103104

104105
--test 'full'
105106

test/client/init.lua

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/client/lclient.lua

Lines changed: 0 additions & 61 deletions
This file was deleted.

test/client/tests/single-mode.lua

Whitespace-only changes.

test/tclient/init.lua

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

0 commit comments

Comments
 (0)