Skip to content

Commit 2e15bfa

Browse files
committed
cleanup
1 parent f3ad922 commit 2e15bfa

File tree

4 files changed

+7
-62
lines changed

4 files changed

+7
-62
lines changed

script/core/rename.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,9 @@ local function ofGlobal(source, newname, callback)
200200
if not global then
201201
return
202202
end
203-
local uri = guide.getUri(source)
204-
for _, set in ipairs(global:getSets(uri)) do
205-
ofFieldThen(key, set, newname, callback)
206-
end
207-
for _, get in ipairs(global:getGets(uri)) do
208-
ofFieldThen(key, get, newname, callback)
203+
local refs = vm.getRefs(source)
204+
for _, ref in ipairs(refs) do
205+
ofFieldThen(key, ref, newname, callback)
209206
end
210207
end
211208

@@ -235,7 +232,8 @@ local function ofDocTypeName(source, newname, callback)
235232
callback(doc, doc.enum.start, doc.enum.finish, newname)
236233
end
237234
end
238-
for _, doc in ipairs(global:getGets(uri)) do
235+
local refs = vm.getRefs(source)
236+
for _, doc in ipairs(refs) do
239237
if doc.type == 'doc.type.name' then
240238
callback(doc, doc.start, doc.finish, newname)
241239
end

script/vm/global.lua

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ local ws = require 'workspace'
77
local vm = require 'vm.vm'
88

99
---@class vm.global.link
10-
---@field gets parser.object[]
1110
---@field sets parser.object[]
1211

1312
---@class vm.global
@@ -31,20 +30,6 @@ function mt:addSet(uri, source)
3130
self.setsCache = nil
3231
end
3332

34-
---@param uri uri
35-
---@param source parser.object
36-
function mt:addGet(uri, source)
37-
if PREVIEW then
38-
return
39-
end
40-
local link = self.links[uri]
41-
if not link.gets then
42-
link.gets = {}
43-
end
44-
link.gets[#link.gets+1] = source
45-
self.getsCache = nil
46-
end
47-
4833
---@param suri uri
4934
---@return parser.object[]
5035
function mt:getSets(suri)
@@ -96,35 +81,6 @@ function mt:getAllSets()
9681
return cache
9782
end
9883

99-
---@return parser.object[]
100-
function mt:getGets(suri)
101-
if not self.getsCache then
102-
self.getsCache = {}
103-
end
104-
local scp = scope.getScope(suri)
105-
local cacheUri = scp.uri or '<callback>'
106-
if self.getsCache[cacheUri] then
107-
return self.getsCache[cacheUri]
108-
end
109-
local clock = os.clock()
110-
self.getsCache[cacheUri] = {}
111-
local cache = self.getsCache[cacheUri]
112-
for uri, link in pairs(self.links) do
113-
if link.gets then
114-
if scp:isVisible(uri) then
115-
for _, source in ipairs(link.gets) do
116-
cache[#cache+1] = source
117-
end
118-
end
119-
end
120-
end
121-
local cost = os.clock() - clock
122-
if cost > 0.1 then
123-
log.warn('global-manager getGets costs', cost, self.name)
124-
end
125-
return cache
126-
end
127-
12884
---@param uri uri
12985
function mt:dropUri(uri)
13086
self.links[uri] = nil
@@ -218,7 +174,6 @@ local compilerGlobalSwitch = util.switch()
218174
return
219175
end
220176
local global = vm.declareGlobal('variable', name, uri)
221-
global:addGet(uri, source)
222177
source._globalNode = global
223178

224179
local nxt = source.next
@@ -276,7 +231,6 @@ local compilerGlobalSwitch = util.switch()
276231
end
277232
local uri = guide.getUri(source)
278233
local global = vm.declareGlobal('variable', name, uri)
279-
global:addGet(uri, source)
280234
source._globalNode = global
281235

282236
local nxt = source.next
@@ -301,8 +255,6 @@ local compilerGlobalSwitch = util.switch()
301255
if source.node.special == 'rawset' then
302256
global:addSet(uri, source)
303257
source.value = source.args[3]
304-
else
305-
global:addGet(uri, source)
306258
end
307259
source._globalNode = global
308260

@@ -401,15 +353,13 @@ local compilerGlobalSwitch = util.switch()
401353
return
402354
end
403355
local type = vm.declareGlobal('type', name, uri)
404-
type:addGet(uri, source)
405356
source._globalNode = type
406357
end)
407358
: case 'doc.extends.name'
408359
: call(function (source)
409360
local uri = guide.getUri(source)
410361
local name = source[1]
411362
local class = vm.declareGlobal('type', name, uri)
412-
class:addGet(uri, source)
413363
source._globalNode = class
414364
end)
415365

script/vm/ref.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ local function searchWord(source, pushResult, defMap, fileNotify)
9797
if global then
9898
local globalName = global:asKeyName()
9999
---@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)
100+
guide.eachSourceTypes(state.ast, {'getglobal', 'setglobal', 'setfield', 'getfield', 'setmethod', 'getmethod', 'setindex', 'getindex', 'doc.type.name', 'doc.class.name', 'doc.alias.name', 'doc.extends.name'}, function (src)
101101
local myGlobal = vm.getGlobalNode(src)
102102
if myGlobal and myGlobal:asKeyName() == globalName then
103103
pushResult(src)
@@ -207,6 +207,7 @@ local nodeSwitch = util.switch()
207207
: case 'doc.class'
208208
: case 'doc.enum'
209209
: case 'doc.type.name'
210+
: case 'doc.extends.name'
210211
---@async
211212
: call(function (source, pushResult, defMap, fileNotify)
212213
searchWord(source, pushResult, defMap, fileNotify)
@@ -264,9 +265,6 @@ local function searchByGlobal(source, pushResult)
264265
for _, set in ipairs(node:getSets(uri)) do
265266
pushResult(set)
266267
end
267-
for _, get in ipairs(node:getGets(uri)) do
268-
pushResult(get)
269-
end
270268
end
271269

272270
local function searchByDef(source, pushResult)

test.lua

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

2424
LOCALE = 'zh-cn'
25-
PREVIEW = true
2625

2726
--dofile((ROOT / 'build_package.lua'):string())
2827
require 'tracy'

0 commit comments

Comments
 (0)