Skip to content

Commit f3ad922

Browse files
committed
cleanup
1 parent d4e3588 commit f3ad922

File tree

4 files changed

+69
-35
lines changed

4 files changed

+69
-35
lines changed

script/parser/guide.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,11 @@ function m.getKeyName(obj)
10091009
return obj.enum[1]
10101010
elseif tp == 'doc.field' then
10111011
return obj.field[1]
1012-
elseif tp == 'doc.field.name' then
1012+
elseif tp == 'doc.field.name'
1013+
or tp == 'doc.type.name'
1014+
or tp == 'doc.class.name'
1015+
or tp == 'doc.alias.name'
1016+
or tp == 'doc.enum.name' then
10131017
return obj[1]
10141018
elseif tp == 'doc.type.field' then
10151019
return m.getKeyName(obj.name)

script/vm/global.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ local vm = require 'vm.vm'
99
---@class vm.global.link
1010
---@field gets parser.object[]
1111
---@field sets parser.object[]
12-
---@field hasGet boolean?
1312

1413
---@class vm.global
1514
---@field links table<uri, vm.global.link>
@@ -35,11 +34,10 @@ end
3534
---@param uri uri
3635
---@param source parser.object
3736
function mt:addGet(uri, source)
38-
local link = self.links[uri]
3937
if PREVIEW then
40-
link.hasGet = true
4138
return
4239
end
40+
local link = self.links[uri]
4341
if not link.gets then
4442
link.gets = {}
4543
end
@@ -98,7 +96,6 @@ function mt:getAllSets()
9896
return cache
9997
end
10098

101-
---@async
10299
---@return parser.object[]
103100
function mt:getGets(suri)
104101
if not self.getsCache then

script/vm/ref.lua

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ local function searchInAllFiles(suri, searcher, notify)
6262
end
6363

6464
---@async
65-
local function searchField(source, pushResult, defMap, fileNotify)
65+
local function searchWord(source, pushResult, defMap, fileNotify)
6666
local key = guide.getKeyName(source)
67+
if not key then
68+
return
69+
end
70+
71+
local global = vm.getGlobalNode(source)
6772

6873
---@param src parser.object
6974
local function checkDef(src)
@@ -75,42 +80,53 @@ local function searchField(source, pushResult, defMap, fileNotify)
7580
end
7681
end
7782

78-
local pat = '[:.]%s*' .. key
79-
8083
---@async
8184
local function findWord(uri)
8285
local text = files.getText(uri)
8386
if not text then
8487
return
8588
end
86-
if not text:match(pat) then
89+
if not text:match(key) then
8790
return
8891
end
8992
local state = files.getState(uri)
9093
if not state then
9194
return
9295
end
93-
---@async
94-
guide.eachSourceTypes(state.ast, {'getfield', 'setfield'}, function (src)
95-
if src.field and src.field[1] == key then
96-
checkDef(src)
97-
await.delay()
98-
end
99-
end)
100-
---@async
101-
guide.eachSourceTypes(state.ast, {'getmethod', 'setmethod'}, function (src)
102-
if src.method and src.method[1] == key then
103-
checkDef(src)
104-
await.delay()
105-
end
106-
end)
107-
---@async
108-
guide.eachSourceTypes(state.ast, {'getindex', 'setindex'}, function (src)
109-
if src.index and src.index.type == 'string' and src.index[1] == key then
110-
checkDef(src)
111-
await.delay()
112-
end
113-
end)
96+
97+
if global then
98+
local globalName = global:asKeyName()
99+
---@async
100+
guide.eachSourceTypes(state.ast, {'getglobal', 'setglobal', 'setfield', 'getfield', 'setmethod', 'getmethod', 'setindex', 'getindex', 'doc.type.name', 'doc.class.name', 'doc.alias.name'}, function (src)
101+
local myGlobal = vm.getGlobalNode(src)
102+
if myGlobal and myGlobal:asKeyName() == globalName then
103+
pushResult(src)
104+
await.delay()
105+
end
106+
end)
107+
else
108+
---@async
109+
guide.eachSourceTypes(state.ast, {'getfield', 'setfield'}, function (src)
110+
if src.field and src.field[1] == key then
111+
checkDef(src)
112+
await.delay()
113+
end
114+
end)
115+
---@async
116+
guide.eachSourceTypes(state.ast, {'getmethod', 'setmethod'}, function (src)
117+
if src.method and src.method[1] == key then
118+
checkDef(src)
119+
await.delay()
120+
end
121+
end)
122+
---@async
123+
guide.eachSourceTypes(state.ast, {'getindex', 'setindex'}, function (src)
124+
if src.index and src.index.type == 'string' and src.index[1] == key then
125+
checkDef(src)
126+
await.delay()
127+
end
128+
end)
129+
end
114130
end
115131

116132
searchInAllFiles(guide.getUri(source), findWord, fileNotify)
@@ -165,18 +181,35 @@ local nodeSwitch = util.switch()
165181
return
166182
end
167183

168-
searchField(source, pushResult, defMap, fileNotify)
184+
searchWord(source, pushResult, defMap, fileNotify)
169185
end)
170186
: case 'tablefield'
171187
: case 'tableindex'
188+
: case 'doc.field.name'
172189
---@async
173190
: call(function (source, pushResult, defMap, fileNotify)
174-
searchField(source, pushResult, defMap, fileNotify)
191+
searchWord(source, pushResult, defMap, fileNotify)
175192
end)
176-
: case 'doc.field.name'
193+
: case 'setglobal'
194+
: case 'getglobal'
195+
---@async
196+
: call(function (source, pushResult, defMap, fileNotify)
197+
searchWord(source, pushResult, defMap, fileNotify)
198+
end)
199+
: case 'doc.alias.name'
200+
: case 'doc.class.name'
201+
: case 'doc.enum.name'
202+
---@async
203+
: call(function (source, pushResult, defMap, fileNotify)
204+
searchWord(source.parent, pushResult, defMap, fileNotify)
205+
end)
206+
: case 'doc.alias'
207+
: case 'doc.class'
208+
: case 'doc.enum'
209+
: case 'doc.type.name'
177210
---@async
178211
: call(function (source, pushResult, defMap, fileNotify)
179-
searchField(source, pushResult, defMap, fileNotify)
212+
searchWord(source, pushResult, defMap, fileNotify)
180213
end)
181214
: case 'function'
182215
: case 'doc.type.function'
@@ -216,7 +249,6 @@ function searchByParentNode(source, pushResult, defMap, fileNotify)
216249
nodeSwitch(source.type, source, pushResult, defMap, fileNotify)
217250
end
218251

219-
---@async
220252
local function searchByGlobal(source, pushResult)
221253
if source.type == 'field'
222254
or source.type == 'method'

test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ log.init(ROOT, ROOT / 'log' / 'test.log')
2222
log.debug('测试开始')
2323

2424
LOCALE = 'zh-cn'
25+
PREVIEW = true
2526

2627
--dofile((ROOT / 'build_package.lua'):string())
2728
require 'tracy'

0 commit comments

Comments
 (0)