Skip to content

Commit a2075b5

Browse files
committed
cleanup
1 parent fb1d31d commit a2075b5

File tree

11 files changed

+113
-97
lines changed

11 files changed

+113
-97
lines changed

script/brave/work.lua

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,3 @@ brave.on('timer', function (time)
2424
brave.push('wakeup')
2525
end
2626
end)
27-
28-
brave.on('compile', function (text)
29-
local state, err = parser.compile(text, 'Lua', 'Lua 5.4')
30-
if not state then
31-
log.error(err)
32-
return
33-
end
34-
local lines = parser.lines(text)
35-
return {
36-
root = state.root,
37-
value = state.value,
38-
errs = state.errs,
39-
lines = lines,
40-
}
41-
end)
42-
43-
brave.on('listDirectory', function (uri)
44-
local path = fs.path(furi.decode(uri))
45-
local uris = {}
46-
for child in fs.pairs(path) do
47-
local childUri = furi.encode(child:string())
48-
uris[#uris+1] = childUri
49-
end
50-
return uris
51-
end)
52-
53-
brave.on('isDirectory', function (uri)
54-
local path = fs.path(furi.decode(uri))
55-
return fs.is_directory(path)
56-
end)
57-
58-
brave.on('loadFile', function (uri)
59-
local filename = furi.decode(uri)
60-
return util.loadFile(filename)
61-
end)
62-
63-
brave.on('saveFile', function (params)
64-
local filename = furi.decode(params.uri)
65-
return util.saveFile(filename, params.text)
66-
end)

script/core/noder.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,11 +1894,17 @@ function m.compileGlobalNodes(root)
18941894
end)
18951895
end
18961896

1897+
for uri in files.eachFile() do
1898+
local state = files.getState(uri)
1899+
if state then
1900+
m.compileGlobalNodes(state.ast)
1901+
end
1902+
end
1903+
18971904
files.watch(function (ev, uri)
18981905
if ev == 'update' then
18991906
local state = files.getState(uri)
19001907
if state then
1901-
--m.compileAllNodes(state.ast)
19021908
m.compileGlobalNodes(state.ast)
19031909
end
19041910
end

script/library.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,6 @@ files.watch(function (ev, uri)
496496
end)
497497

498498
function m.init()
499-
if m.inited then
500-
return
501-
end
502-
m.inited = true
503499
initBuiltIn(nil)
504500
for _, scp in ipairs(ws.folders) do
505501
initBuiltIn(scp.uri)

script/plugin.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ end
7070

7171
---@param scp scope
7272
function m.init(scp)
73-
if m.hasInited then
74-
return
75-
end
76-
m.hasInited = true
7773
await.call(function () ---@async
7874
local ws = require 'workspace'
7975
m.interface = {}

script/provider/provider.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local converter = require 'proto.converter'
1717
local filewatch = require 'filewatch'
1818
local json = require 'json'
1919
local scope = require 'workspace.scope'
20+
local furi = require 'file-uri'
2021

2122
---@async
2223
local function updateConfig(uri)
@@ -167,7 +168,7 @@ m.register 'workspace/didCreateFiles' {
167168
log.debug('workspace/didCreateFiles', util.dump(params))
168169
for _, file in ipairs(params.files) do
169170
if workspace.isValidLuaUri(file.uri) then
170-
files.setText(file.uri, pub.awaitTask('loadFile', file.uri), false)
171+
files.setText(file.uri, util.loadFile(furi.decode(file.uri)), false)
171172
end
172173
end
173174
end

script/workspace/workspace.lua

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ function m.reset()
5555
---@type scope[]
5656
m.folders = {}
5757
m.rootUri = nil
58-
m.inited = false
5958
end
6059
m.reset()
6160

@@ -92,7 +91,6 @@ local globInteferFace = {
9291
}
9392

9493
--- 创建排除文件匹配器
95-
---@async
9694
---@param scp scope
9795
function m.getNativeMatcher(scp)
9896
if scp:get 'nativeMatcher' then
@@ -107,7 +105,7 @@ function m.getNativeMatcher(scp)
107105
end
108106
end
109107
if scp.uri and config.get(scp.uri, 'Lua.workspace.useGitIgnore') then
110-
local buf = pub.awaitTask('loadFile', scp.uri .. '/.gitignore')
108+
local buf = util.loadFile(furi.decode(scp.uri) .. '/.gitignore')
111109
if buf then
112110
for line in buf:gmatch '[^\r\n]+' do
113111
if line:sub(1, 1) ~= '#' then
@@ -116,7 +114,7 @@ function m.getNativeMatcher(scp)
116114
end
117115
end
118116
end
119-
buf = pub.awaitTask('loadFile', scp.uri .. '/.git/info/exclude')
117+
buf = util.loadFile(furi.decode(scp.uri).. '/.git/info/exclude')
120118
if buf then
121119
for line in buf:gmatch '[^\r\n]+' do
122120
if line:sub(1, 1) ~= '#' then
@@ -127,7 +125,7 @@ function m.getNativeMatcher(scp)
127125
end
128126
end
129127
if scp.uri and config.get(scp.uri, 'Lua.workspace.ignoreSubmodules') then
130-
local buf = pub.awaitTask('loadFile', scp.uri .. '/.gitmodules')
128+
local buf = util.loadFile(furi.decode(scp.uri) .. '/.gitmodules')
131129
if buf then
132130
for path in buf:gmatch('path = ([^\r\n]+)') do
133131
log.info('Ignore by .gitmodules:', path)
@@ -383,20 +381,13 @@ end
383381

384382
---@param scp scope
385383
function m.reload(scp)
386-
if not m.inited then
387-
return
388-
end
389384
---@async
390385
await.call(function ()
391386
m.awaitReload(scp)
392387
end)
393388
end
394389

395390
function m.init()
396-
if m.inited then
397-
return
398-
end
399-
m.inited = true
400391
if m.rootUri then
401392
for _, folder in ipairs(scope.folders) do
402393
m.reload(folder)
@@ -526,7 +517,7 @@ fw.event(function (changes) ---@async
526517
if m.isValidLuaUri(uri) then
527518
-- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新
528519
if not files.isOpen(uri) then
529-
files.setText(uri, pub.awaitTask('loadFile', uri), false)
520+
files.setText(uri, util.loadFile(furi.decode(uri)), false)
530521
end
531522
else
532523
local filename = fs.path(path):filename():string()

test.lua

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,6 @@ local function loadAllLibs()
3131
assert(require 'lpeglabel')
3232
end
3333

34-
local function loadDocMetas()
35-
local files = require 'files'
36-
local library = require 'library'
37-
local furi = require 'file-uri'
38-
local fsu = require 'fs-utility'
39-
local client = require 'client'
40-
client.client 'vscode'
41-
for path in pairs(library.metaPaths) do
42-
local uri = furi.encode(path)
43-
files.setText(uri, fsu.loadFile(path))
44-
--scope.fallback:addLink(uri)
45-
end
46-
end
47-
4834
local function test(name)
4935
local clock = os.clock()
5036
print(('测试[%s]...'):format(name))
@@ -81,30 +67,28 @@ local function testAll()
8167
end
8268

8369
local function main()
70+
LOCALE = 'zh-cn'
8471
require 'utility'.enableCloseFunction()
85-
require 'library'.init()
86-
test 'tclient'
72+
require 'client' .client 'VSCode'
8773

88-
--config.Lua.intelliSense.searchDepth = 5
89-
--loadDocMetas()
74+
local lclient = require 'tclient.lclient'
75+
local ws = require 'workspace'
9076

91-
--test 'full';do return end
92-
require 'workspace.workspace'.reset()
93-
require 'files'.reset()
94-
require 'workspace.scope'.reset()
95-
require 'language' 'zh-cn'
96-
loadDocMetas()
97-
require 'bee.platform'.OS = 'Windows'
98-
testAll()
99-
require 'bee.platform'.OS = 'Linux'
100-
testAll()
101-
require 'bee.platform'.OS = 'macOS'
102-
testAll()
77+
for _, os in ipairs {'Windows', 'Linux', 'macOS'} do
78+
require 'bee.platform'.OS = os
79+
---@async
80+
lclient():start(function (client)
81+
client:registerFakers()
82+
client:initialize()
10383

104-
--test 'tclient'
84+
ws.awaitReady()
10585

106-
test 'full'
86+
testAll()
87+
end)
88+
end
10789

90+
test 'tclient'
91+
test 'full'
10892
print('测试完成')
10993
end
11094

test/tclient/init.lua

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

test/tclient/tests/library-ignore-limit.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ lclient():start(function (client)
2121
end)
2222

2323
fs.create_directories(fs.path(libraryPath))
24-
util.saveFile(largeFilePath, string.rep('--this is a large file\n', 100000))
24+
if not fs.exists(fs.path(largeFilePath)) then
25+
util.saveFile(largeFilePath, string.rep('--this is a large file\n', 100000))
26+
end
2527

2628
client:initialize()
2729

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
local lclient = require 'tclient.lclient'
2+
local fs = require 'bee.filesystem'
3+
local util = require 'utility'
4+
local furi = require 'file-uri'
5+
local ws = require 'workspace'
6+
local files = require 'files'
7+
8+
local rootPath = LOGPATH .. '/multi-workspace'
9+
local rootUri = furi.encode(rootPath)
10+
11+
for _, name in ipairs { 'ws1', 'ws2', 'share', 'lb1', 'lb2' } do
12+
fs.create_directories(fs.path(rootPath .. '/' .. name))
13+
util.saveFile(rootPath .. '/' .. name .. '/test.lua', '')
14+
end
15+
16+
---@async
17+
lclient():start(function (client)
18+
client:registerFakers()
19+
20+
client:register('workspace/configuration', function (params)
21+
local uri = params.items[1].scopeUri
22+
if uri == rootUri .. '/ws1' then
23+
return {
24+
{
25+
['workspace.library'] = {
26+
rootPath .. '/share',
27+
rootPath .. '/lb1',
28+
}
29+
}
30+
}
31+
end
32+
if uri == rootUri .. '/ws2' then
33+
return {
34+
{
35+
['workspace.library'] = {
36+
rootPath .. '/share',
37+
rootPath .. '/lb2',
38+
}
39+
}
40+
}
41+
end
42+
return {}
43+
end)
44+
45+
client:initialize {
46+
rootPath = rootPath,
47+
rootUri = rootUri,
48+
workspaceFolders = {
49+
{
50+
name = 'ws1',
51+
uri = rootUri .. '/ws1',
52+
},
53+
{
54+
name = 'ws2',
55+
uri = rootUri .. '/ws2',
56+
},
57+
}
58+
}
59+
60+
ws.awaitReady(rootUri .. '/ws1')
61+
ws.awaitReady(rootUri .. '/ws2')
62+
63+
assert(files.getState(rootUri .. '/ws1/test.lua') ~= nil)
64+
assert(files.getState(rootUri .. '/ws2/test.lua') ~= nil)
65+
assert(files.getState(rootUri .. '/share/test.lua') ~= nil)
66+
assert(files.getState(rootUri .. '/lb1/test.lua') ~= nil)
67+
assert(files.getState(rootUri .. '/lb2/test.lua') ~= nil)
68+
69+
assert(ws.getScope(rootUri .. '/ws1/test.lua').uri == rootUri .. '/ws1')
70+
assert(ws.getScope(rootUri .. '/ws2/test.lua').uri == rootUri .. '/ws2')
71+
assert(ws.getScope(rootUri .. '/share/test.lua').uri == rootUri .. '/ws1')
72+
assert(ws.getScope(rootUri .. '/lb1/test.lua').uri == rootUri .. '/ws1')
73+
assert(ws.getScope(rootUri .. '/lb2/test.lua').uri == rootUri .. '/ws2')
74+
75+
assert(files.isLibrary(rootUri .. '/ws1/test.lua') == false)
76+
assert(files.isLibrary(rootUri .. '/ws2/test.lua') == false)
77+
assert(files.isLibrary(rootUri .. '/share/test.lua') == true)
78+
assert(files.isLibrary(rootUri .. '/lb1/test.lua') == true)
79+
assert(files.isLibrary(rootUri .. '/lb2/test.lua') == true)
80+
end)

0 commit comments

Comments
 (0)