Skip to content

Commit c6cac23

Browse files
committed
Merge branch 'client-test'
2 parents 2f984c1 + 9e8901c commit c6cac23

File tree

13 files changed

+201
-92
lines changed

13 files changed

+201
-92
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# changelog
22

3+
## 2.6.1
4+
* `FIX` modify luarc failed
5+
* `FIX` library files not recognized correctly
6+
37
## 2.6.0
48
`2022-1-13`
59
* `NEW` supports multi-workspace in server side, for developers of language clients, please [read here](https://github.com/sumneko/lua-language-server/wiki/Multi-workspace-supports) to learn more.

script/client.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ local function tryModifyRC(uri, finalChanges, create)
241241
return false
242242
end
243243
local workspace = require 'workspace'
244-
local loader = require 'config.loader'
245244
local path = workspace.getAbsolutePath(uri, '.luarc.json')
246245
if not path then
247246
return false

script/files.lua

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local guide = require 'parser.guide'
1212
local smerger = require 'string-merger'
1313
local progress = require "progress"
1414
local encoder = require 'encoder'
15+
local scope = require 'workspace.scope'
1516

1617
---@class files
1718
local m = {}
@@ -23,7 +24,6 @@ m.assocMatcher = nil
2324

2425
function m.reset()
2526
m.openMap = {}
26-
m.libraryMap = {}
2727
m.fileMap = {}
2828
m.dllMap = {}
2929
m.visible = {}
@@ -110,12 +110,28 @@ end
110110

111111
--- 是否是库文件
112112
function m.isLibrary(uri)
113-
return m.libraryMap[uri] ~= nil
113+
for _, scp in ipairs(scope.folders) do
114+
local map = scp:get 'libraryMap'
115+
if map and map[uri] ~= nil then
116+
return true
117+
end
118+
end
119+
local map = scope.fallback:get 'libraryMap'
120+
if map and map[uri] ~= nil then
121+
return true
122+
end
123+
return false
114124
end
115125

116126
--- 获取库文件的根目录
117127
function m.getLibraryPath(uri)
118-
return m.libraryMap[uri]
128+
for _, scp in ipairs(scope.folders) do
129+
local map = scp:get 'libraryMap'
130+
if map and map[uri] ~= nil then
131+
return scp.uri
132+
end
133+
end
134+
return nil
119135
end
120136

121137
---@param scp scope

script/library.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,12 @@ local function apply3rd(uri, cfg, onlyMemory)
323323
local changes = {}
324324
if cfg.configs then
325325
for _, change in ipairs(cfg.configs) do
326-
changes[#changes+1] = change
326+
changes[#changes+1] = {
327+
key = change.key,
328+
action = change.action,
329+
value = change.value,
330+
uri = uri,
331+
}
327332
end
328333
end
329334

script/proto/proto.lua

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ function m.awaitRequest(name, params)
9292
params = params,
9393
}
9494
local result, error = await.wait(function (resume)
95-
m.waiting[id] = resume
95+
m.waiting[id] = {
96+
id = id,
97+
method = name,
98+
params = params,
99+
resume = resume,
100+
}
96101
end)
97102
if error then
98103
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
@@ -110,14 +115,19 @@ function m.request(name, params, callback)
110115
--log.debug('Request', name, #buf)
111116
logSend(buf)
112117
io.write(buf)
113-
m.waiting[id] = function (result, error)
114-
if error then
115-
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
116-
end
117-
if callback then
118-
callback(result)
118+
m.waiting[id] = {
119+
id = id,
120+
method = name,
121+
params = params,
122+
resume = function (result, error)
123+
if error then
124+
log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
125+
end
126+
if callback then
127+
callback(result)
128+
end
119129
end
120-
end
130+
}
121131
end
122132

123133
local secretOption = {
@@ -137,6 +147,9 @@ function m.doMethod(proto)
137147
logRecieve(proto)
138148
local method, optional = m.getMethodName(proto)
139149
local abil = m.ability[method]
150+
if proto.id then
151+
m.holdon[proto.id] = proto
152+
end
140153
if not abil then
141154
if not optional then
142155
log.warn('Recieved unknown proto: ' .. method)
@@ -146,9 +159,6 @@ function m.doMethod(proto)
146159
end
147160
return
148161
end
149-
if proto.id then
150-
m.holdon[proto.id] = proto
151-
end
152162
await.call(function () ---@async
153163
--log.debug('Start method:', method)
154164
if proto.id then
@@ -192,17 +202,17 @@ end
192202
function m.doResponse(proto)
193203
logRecieve(proto)
194204
local id = proto.id
195-
local resume = m.waiting[id]
196-
if not resume then
205+
local waiting = m.waiting[id]
206+
if not waiting then
197207
log.warn('Response id not found: ' .. util.dump(proto))
198208
return
199209
end
200210
m.waiting[id] = nil
201211
if proto.error then
202-
resume(nil, proto.error)
212+
waiting.resume(nil, proto.error)
203213
return
204214
end
205-
resume(proto.result)
215+
waiting.resume(proto.result)
206216
end
207217

208218
function m.listen()

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/loading.lua

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ local await = require 'await'
44
local files = require 'files'
55
local config = require 'config.config'
66
local client = require 'client'
7-
local pub = require 'pub.pub'
7+
local util = require 'utility'
8+
local furi = require 'file-uri'
89

910
---@class workspace.loading
1011
---@field scp scope
@@ -69,50 +70,48 @@ function mt:loadFile(uri, libraryUri)
6970
end
7071
self.max = self.max + 1
7172
self:update()
72-
pub.task('loadFile', uri, function (content)
73-
self._stash[#self._stash+1] = function ()
74-
self.read = self.read + 1
75-
self:update()
76-
if not content then
77-
return
78-
end
79-
if self._cache[uri] then
80-
return
81-
end
82-
log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
83-
self._cache[uri] = true
84-
files.setText(uri, content, false)
85-
files.addRef(uri)
86-
if libraryUri then
87-
log.info('++++As library of:', libraryUri)
88-
files.setLibraryUri(self.scp, uri, libraryUri)
89-
end
73+
self._stash[#self._stash+1] = function ()
74+
local content = util.loadFile(furi.decode(uri))
75+
self.read = self.read + 1
76+
self:update()
77+
if not content then
78+
return
79+
end
80+
if self._cache[uri] then
81+
return
9082
end
91-
end)
83+
log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
84+
self._cache[uri] = true
85+
files.setText(uri, content, false)
86+
files.addRef(uri)
87+
if libraryUri then
88+
log.info('++++As library of:', libraryUri)
89+
files.setLibraryUri(self.scp, uri, libraryUri)
90+
end
91+
end
9292
elseif files.isDll(uri) then
9393
self.max = self.max + 1
9494
self:update()
95-
pub.task('loadFile', uri, function (content)
96-
self._stash[#self._stash+1] = function ()
97-
self.read = self.read + 1
98-
self:update()
99-
if not content then
100-
return
101-
end
102-
if self._cache[uri] then
103-
return
104-
end
105-
log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
106-
self._cache[uri] = true
107-
files.saveDll(uri, content)
108-
files.addRef(uri)
109-
if libraryUri then
110-
log.info('++++As library of:', libraryUri)
111-
end
95+
self._stash[#self._stash+1] = function ()
96+
local content = util.loadFile(furi.decode(uri))
97+
self.read = self.read + 1
98+
self:update()
99+
if not content then
100+
return
101+
end
102+
if self._cache[uri] then
103+
return
112104
end
113-
end)
114-
await.delay()
105+
log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0))
106+
self._cache[uri] = true
107+
files.saveDll(uri, content)
108+
files.addRef(uri)
109+
if libraryUri then
110+
log.info('++++As library of:', libraryUri)
111+
end
112+
end
115113
end
114+
await.delay()
116115
end
117116

118117
function mt:loadStashed()

script/workspace/workspace.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function m.reset()
5555
---@type scope[]
5656
m.folders = {}
5757
m.rootUri = nil
58+
m.inited = false
5859
end
5960
m.reset()
6061

@@ -385,9 +386,6 @@ function m.reload(scp)
385386
if not m.inited then
386387
return
387388
end
388-
if TEST then
389-
return
390-
end
391389
---@async
392390
await.call(function ()
393391
m.awaitReload(scp)

test.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ TEST = true
88
DEVELOP = true
99
--FOOTPRINT = true
1010
--TRACE = true
11-
LOGPATH = LOGPATH or (ROOT .. '/log')
12-
METAPATH = METAPATH or (ROOT .. '/meta')
11+
LOGPATH = LOGPATH or (ROOT:string() .. '/log')
12+
METAPATH = METAPATH or (ROOT:string() .. '/meta')
1313

1414
collectgarbage 'generational'
1515

@@ -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/init.lua

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

0 commit comments

Comments
 (0)