Skip to content

Commit f050b38

Browse files
committed
update search reference
1 parent ae95f74 commit f050b38

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

script/core/definition.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ local accept = {
5656
['doc.see.field'] = true,
5757
['doc.cast.name'] = true,
5858
['doc.enum.name'] = true,
59+
['doc.field.name'] = true,
5960
}
6061

6162
local function checkRequire(source, offset)

script/core/reference.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ local accept = {
5151
['doc.extends.name'] = true,
5252
['doc.alias.name'] = true,
5353
['doc.enum.name'] = true,
54+
['doc.field.name'] = true,
5455
}
5556

5657
---@async
@@ -115,7 +116,8 @@ return function (uri, position)
115116
and source.type ~= 'doc.class.name'
116117
and source.type ~= 'doc.enum.name'
117118
and source.type ~= 'doc.extends.name'
118-
and source.type ~= 'doc.see.name' then
119+
and source.type ~= 'doc.see.name'
120+
and source.type ~= 'doc.alias.name' then
119121
goto CONTINUE
120122
end
121123
end

script/vm/compiler.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,10 @@ local compilerSwitch = util.switch()
16101610
end
16111611
vm.setNode(source, fieldNode)
16121612
end)
1613+
: case 'doc.field.name'
1614+
: call(function (source)
1615+
vm.setNode(source, vm.compileNode(source.parent))
1616+
end)
16131617
: case 'doc.type.field'
16141618
: call(function (source)
16151619
if not source.extends then

script/vm/def.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ simpleSwitch = util.switch()
1919
pushResult(loc)
2020
end
2121
end)
22+
: case 'doc.field'
23+
: call(function (source, pushResult)
24+
pushResult(source)
25+
end)
2226

2327
---@param source parser.object
2428
---@param pushResult fun(src: parser.object)

script/vm/ref.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ simpleSwitch = util.switch()
2626
end
2727
end
2828
end)
29+
: case 'doc.alias.name'
30+
: call(function (source, pushResult)
31+
local global = vm.getGlobal('type', source[1])
32+
if not global then
33+
return
34+
end
35+
for _, get in ipairs(global:getGets(guide.getUri(source))) do
36+
pushResult(get)
37+
end
38+
for _, set in ipairs(global:getSets(guide.getUri(source))) do
39+
pushResult(set)
40+
end
41+
end)
2942

3043
---@async
3144
local function searchInAllFiles(suri, searcher, notify)
@@ -173,6 +186,11 @@ local nodeSwitch = util.switch()
173186
: call(function (source, pushResult, defMap, fileNotify)
174187
searchField(source, pushResult, defMap, fileNotify)
175188
end)
189+
: case 'doc.field.name'
190+
---@async
191+
: call(function (source, pushResult, defMap, fileNotify)
192+
searchField(source, pushResult, defMap, fileNotify)
193+
end)
176194
: case 'function'
177195
: case 'doc.type.function'
178196
---@async
@@ -237,6 +255,9 @@ local function searchByDef(source, pushResult)
237255
or source.type == 'method' then
238256
source = source.parent
239257
end
258+
if source.type == 'doc.field.name' then
259+
source = source.parent
260+
end
240261
defMap[source] = true
241262
if guide.isSet(source) then
242263
local defs = vm.getDefs(source)

test/references/common.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,18 @@ local b = { }
201201
a.color = { 1, 1, 1 }
202202
b.<~color~> = a.color
203203
]]
204+
205+
TEST [[
206+
---@alias <~A~> number
207+
208+
---@type <!A!>
209+
]]
210+
211+
TEST [[
212+
---@class A
213+
---@field <~x~> number
214+
215+
---@type A
216+
local t
217+
print(t.<!x!>)
218+
]]

0 commit comments

Comments
 (0)