1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
local lclient = require 'lclient'
local fs = require 'bee.filesystem'
local util = require 'utility'
local furi = require 'file-uri'
local ws = require 'workspace'
local files = require 'files'
local scope = require 'workspace.scope'
local rootPath = LOGPATH .. '/multi-workspace'
local rootUri = furi.encode(rootPath)
for _, name in ipairs { 'ws1', 'ws2', 'share', 'lb1', 'lb2' } do
fs.create_directories(fs.path(rootPath .. '/' .. name))
util.saveFile(rootPath .. '/' .. name .. '/test.lua', '')
end
---@async
lclient():start(function (client)
client:registerFakers()
client:register('workspace/configuration', function (params)
local uri = params.items[1].scopeUri
if uri == rootUri .. '/ws1' then
return {
{
['workspace.library'] = {
rootPath .. '/share',
rootPath .. '/lb1',
}
}
}
end
if uri == rootUri .. '/ws2' then
return {
{
['workspace.library'] = {
rootPath .. '/share',
rootPath .. '/lb2',
}
}
}
end
return {}
end)
client:initialize {
rootPath = rootPath,
rootUri = rootUri,
workspaceFolders = {
{
name = 'ws1',
uri = rootUri .. '/ws1',
},
{
name = 'ws2',
uri = rootUri .. '/ws2',
},
}
}
ws.awaitReady(rootUri .. '/ws1')
ws.awaitReady(rootUri .. '/ws2')
assert(files.getState(rootUri .. '/ws1/test.lua') ~= nil)
assert(files.getState(rootUri .. '/ws2/test.lua') ~= nil)
assert(files.getState(rootUri .. '/share/test.lua') ~= nil)
assert(files.getState(rootUri .. '/lb1/test.lua') ~= nil)
assert(files.getState(rootUri .. '/lb2/test.lua') ~= nil)
assert(scope.getScope(rootUri .. '/ws1/test.lua').uri == rootUri .. '/ws1')
assert(scope.getScope(rootUri .. '/ws2/test.lua').uri == rootUri .. '/ws2')
assert(scope.getScope(rootUri .. '/share/test.lua').uri == rootUri .. '/ws1')
assert(scope.getScope(rootUri .. '/lb1/test.lua').uri == rootUri .. '/ws1')
assert(scope.getScope(rootUri .. '/lb2/test.lua').uri == rootUri .. '/ws2')
assert(files.isLibrary(rootUri .. '/ws1/test.lua') == false)
assert(files.isLibrary(rootUri .. '/ws2/test.lua') == false)
assert(files.isLibrary(rootUri .. '/share/test.lua') == true)
assert(files.isLibrary(rootUri .. '/lb1/test.lua') == true)
assert(files.isLibrary(rootUri .. '/lb2/test.lua') == true)
files.setText(rootUri .. '/ws1/unittest.lua', [[
GLOBAL = 1
---@class ZAAA
---@type Z
]])
files.setText(rootUri .. '/ws2/unittest.lua', [[
GLOBAL = 2
---@class ZBBB
---@type Z
]])
local defs1 = client:awaitRequest('textDocument/definition', {
textDocument = {
uri = rootUri .. '/ws1/unittest.lua',
},
position = {
line = 0,
character = 0,
},
})
assert(#defs1 == 1)
local defs2 = client:awaitRequest('textDocument/definition', {
textDocument = {
uri = rootUri .. '/ws2/unittest.lua',
},
position = {
line = 0,
character = 0,
},
})
assert(#defs2 == 1)
local comps1 = client:awaitRequest('textDocument/completion', {
textDocument = {
uri = rootUri .. '/ws1/unittest.lua',
},
position = {
line = 2,
character = 10,
},
})
assert(#comps1.items == 1)
local comps2 = client:awaitRequest('textDocument/completion', {
textDocument = {
uri = rootUri .. '/ws2/unittest.lua',
},
position = {
line = 2,
character = 10,
},
})
assert(#comps2.items == 1)
end)
|