Skip to content

Commit 2e4f530

Browse files
committed
fix #1036
1 parent 4f98d55 commit 2e4f530

File tree

4 files changed

+51
-25
lines changed

4 files changed

+51
-25
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* `FIX` [#1033](https://github.com/sumneko/lua-language-server/issues/1033)
55
* `FIX` [#1034](https://github.com/sumneko/lua-language-server/issues/1034)
66
* `FIX` [#1035](https://github.com/sumneko/lua-language-server/issues/1035)
7+
* `FIX` [#1036](https://github.com/sumneko/lua-language-server/issues/1036)
78

89
## 3.0.0
910
`2022-4-10`

script/vm/global.lua

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ local ID_SPLITE = '\x1F'
2121
---@param source parser.object
2222
function mt:addSet(uri, source)
2323
local link = self.links[uri]
24+
if not link.sets then
25+
link.sets = {}
26+
end
2427
link.sets[#link.sets+1] = source
2528
self.setsCache = nil
2629
end
@@ -29,6 +32,9 @@ end
2932
---@param source parser.object
3033
function mt:addGet(uri, source)
3134
local link = self.links[uri]
35+
if not link.gets then
36+
link.gets = {}
37+
end
3238
link.gets[#link.gets+1] = source
3339
self.getsCache = nil
3440
end
@@ -38,20 +44,19 @@ function mt:getSets(suri)
3844
if not self.setsCache then
3945
self.setsCache = {}
4046
end
41-
---@type scope
42-
local scp = suri and scope.getScope(suri) or nil
43-
local cacheUri = scp and scp.uri or '<fallback>'
47+
local scp = scope.getScope(suri)
48+
local cacheUri = scp.uri or '<callback>'
4449
if self.setsCache[cacheUri] then
4550
return self.setsCache[cacheUri]
4651
end
4752
self.setsCache[cacheUri] = {}
4853
local cache = self.setsCache[cacheUri]
4954
for uri, link in pairs(self.links) do
50-
if not scp
51-
or scp:isChildUri(uri)
52-
or scp:isLinkedUri(uri) then
53-
for _, source in ipairs(link.sets) do
54-
cache[#cache+1] = source
55+
if link.sets then
56+
if scp:isVisible(uri) then
57+
for _, source in ipairs(link.sets) do
58+
cache[#cache+1] = source
59+
end
5560
end
5661
end
5762
end
@@ -63,20 +68,19 @@ function mt:getGets(suri)
6368
if not self.getsCache then
6469
self.getsCache = {}
6570
end
66-
---@type scope
67-
local scp = suri and scope.getScope(suri) or nil
68-
local cacheUri = scp and scp.uri or '<fallback>'
71+
local scp = scope.getScope(suri)
72+
local cacheUri = scp.uri or '<callback>'
6973
if self.getsCache[cacheUri] then
7074
return self.getsCache[cacheUri]
7175
end
7276
self.getsCache[cacheUri] = {}
7377
local cache = self.getsCache[cacheUri]
7478
for uri, link in pairs(self.links) do
75-
if not scp
76-
or scp:isChildUri(uri)
77-
or scp:isLinkedUri(uri) then
78-
for _, source in ipairs(link.gets) do
79-
cache[#cache+1] = source
79+
if link.gets then
80+
if scp:isVisible(uri) then
81+
for _, source in ipairs(link.gets) do
82+
cache[#cache+1] = source
83+
end
8084
end
8185
end
8286
end
@@ -111,11 +115,6 @@ return function (name, cate)
111115
return setmetatable({
112116
name = name,
113117
cate = cate,
114-
links = util.defaultTable(function ()
115-
return {
116-
sets = {},
117-
gets = {},
118-
}
119-
end),
118+
links = util.multiTable(2),
120119
}, mt)
121120
end

script/workspace/scope.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
local gc = require 'gc'
22

3+
---@class scope.manager
4+
local m = {}
5+
36
---@alias scope.type '"override"'|'"folder"'|'"fallback"'
47

58
---@class scope
@@ -59,6 +62,14 @@ function mt:isLinkedUri(uri)
5962
return false
6063
end
6164

65+
---@param uri uri
66+
---@return boolean
67+
function mt:isVisible(uri)
68+
return self:isChildUri(uri)
69+
or self:isLinkedUri(uri)
70+
or self == m.getScope(uri)
71+
end
72+
6273
---@param uri uri
6374
---@return uri?
6475
function mt:getLinkedUri(uri)
@@ -122,9 +133,6 @@ local function createScope(scopeType)
122133
return scope
123134
end
124135

125-
---@class scope.manager
126-
local m = {}
127-
128136
function m.reset()
129137
---@type scope[]
130138
m.folders = {}

test/tclient/tests/single-mode.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ lclient():start(function (client)
1515
text = [[
1616
local x
1717
print(x)
18+
19+
TEST = 1
20+
print(TEST)
1821
]]
1922
}
2023
})
@@ -42,4 +45,19 @@ print(x)
4245
})
4346

4447
assert(#locations > 0)
48+
49+
local locations = client:awaitRequest('textDocument/definition', {
50+
textDocument = { uri = 'file://single-file.lua' },
51+
position = { line = 3, character = 0 },
52+
})
53+
54+
assert(util.equal(locations, {
55+
{
56+
uri = 'file://single-file.lua',
57+
range = {
58+
start = { line = 3, character = 0 },
59+
['end'] = { line = 3, character = 4 },
60+
}
61+
}
62+
}))
4563
end)

0 commit comments

Comments
 (0)