Skip to content

Commit 6c97dc8

Browse files
committed
fix #920
1 parent a13a30f commit 6c97dc8

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* `FIX` modify luarc failed
1010
* `FIX` library files not recognized correctly
1111
* `FIX` [#906](https://github.com./sumneko/lua-language-server/issues/906)
12+
* `FIX` [#920](https://github.com./sumneko/lua-language-server/issues/920)
1213

1314
## 2.6.0
1415
`2022-1-13`

script/files.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ function m.isLibrary(uri)
124124
end
125125

126126
--- 获取库文件的根目录
127-
function m.getLibraryPath(uri)
127+
function m.getLibraryUri(uri)
128128
for _, scp in ipairs(scope.folders) do
129129
local map = scp:get 'libraryMap'
130130
if map and map[uri] ~= nil then
131-
return scp.uri
131+
return map[uri]
132132
end
133133
end
134134
return nil

script/workspace/require-path.lua

+12-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function m.getVisiblePath(suri, path)
4343
local strict = config.get(suri, 'Lua.runtime.pathStrict')
4444
path = workspace.normalize(path)
4545
local uri = furi.encode(path)
46-
local libraryPath = files.getLibraryPath(uri)
46+
local libraryPath = furi.decode(files.getLibraryUri(uri))
4747
local scp = scope.getScope(suri)
4848
local cache = scp:get('visiblePath') or scp:set('visiblePath', {})
4949
if not cache[path] then
@@ -145,10 +145,18 @@ local function removeVisiblePath(uri)
145145
path = workspace.normalize(path)
146146
for _, scp in ipairs(workspace.folders) do
147147
scp:get('visiblePath')[path] = nil
148-
scp:get('requireName'):dropUri(uri)
148+
---@type collector
149+
local clt = scp:get('requireName')
150+
if clt then
151+
clt:dropUri(uri)
152+
end
153+
end
154+
scope.fallback:get('visiblePath')[path] = nil
155+
---@type collector
156+
local clt = scope.fallback:get('requireName')
157+
if clt then
158+
clt:dropUri(uri)
149159
end
150-
scope.getScope(nil):get('visiblePath')[path] = nil
151-
scope.getScope(nil):get('requireName'):dropUri(uri)
152160
end
153161

154162
function m.flush(suri)

test/completion/common.lua

+7
Original file line numberDiff line numberDiff line change
@@ -3060,3 +3060,10 @@ local t
30603060
t:testFunc2(<??>)
30613061
]]
30623062
(EXISTS)
3063+
3064+
TEST [[
3065+
require '<??>'
3066+
]]
3067+
(function (results)
3068+
assert(#results == 11)
3069+
end)

test/completion/init.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ function TEST(script)
110110
end
111111
assert(result)
112112
result.complete = nil
113-
if expect.include then
114-
expect.include = nil
115-
assert(include(expect, result))
113+
if type(expect) == 'function' then
114+
expect(result)
116115
else
117-
assert(eq(expect, result))
116+
if expect.include then
117+
expect.include = nil
118+
assert(include(expect, result))
119+
else
120+
assert(eq(expect, result))
121+
end
118122
end
119123
files.remove('')
120124
end

0 commit comments

Comments
 (0)