Skip to content

Commit 9e8901c

Browse files
committed
FIX library files not recognized correctly
1 parent b7fdf17 commit 9e8901c

File tree

6 files changed

+74
-46
lines changed

6 files changed

+74
-46
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 2.6.1
44
* `FIX` modify luarc failed
5+
* `FIX` library files not recognized correctly
56

67
## 2.6.0
78
`2022-1-13`

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/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 & 0 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

test/tclient/lclient.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function mt:start(callback)
6363

6464
local finished = false
6565

66+
await.setErrorHandle(function (...)
67+
local msg = log.error(...)
68+
error(msg)
69+
end)
70+
6671
---@async
6772
await.call(function ()
6873
callback(self)
@@ -144,7 +149,7 @@ function mt:update()
144149
if callback then
145150
proto.doResponse {
146151
id = out.id,
147-
params = callback(out.params),
152+
result = callback(out.params),
148153
}
149154
elseif out.method:sub(1, 2) ~= '$/' then
150155
error('Unknown method: ' .. out.method)
@@ -164,10 +169,12 @@ end
164169

165170
function mt:registerFakers()
166171
for _, method in ipairs {
172+
'textDocument/publishDiagnostics',
167173
'workspace/configuration',
168174
'workspace/semanticTokens/refresh',
169175
'window/workDoneProgress/create',
170-
'textDocument/publishDiagnostics',
176+
'window/showMessage',
177+
'window/logMessage',
171178
} do
172179
self:register(method, function ()
173180
return nil

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local util = require 'utility'
33
local ws = require 'workspace'
44
local files = require 'files'
55
local furi = require 'file-uri'
6+
local fs = require 'bee.filesystem'
67

78
local libraryPath = LOGPATH .. '/large-file-library'
89
local largeFilePath = LOGPATH .. '/large-file-library/large-file.lua'
@@ -13,11 +14,14 @@ lclient():start(function (client)
1314

1415
client:register('workspace/configuration', function ()
1516
return {
16-
['Lua.workspace.library'] = { libraryPath }
17+
{
18+
['workspace.library'] = { libraryPath }
19+
},
1720
}
1821
end)
1922

20-
util.saveFile(largeFilePath, string.rep('--this is a large file\n', 20000))
23+
fs.create_directories(fs.path(libraryPath))
24+
util.saveFile(largeFilePath, string.rep('--this is a large file\n', 100000))
2125

2226
client:initialize()
2327

0 commit comments

Comments
 (0)