Skip to content

Commit 6b04f49

Browse files
committed
update workspace-symbol
1 parent 33b0d66 commit 6b04f49

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

script/core/workspace-symbol.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local guide = require 'parser.guide'
33
local matchKey = require 'core.matchkey'
44
local define = require 'proto.define'
55
local await = require 'await'
6+
local vm = require 'vm'
67

78
local function buildSource(uri, source, key, results)
89
if source.type == 'local'
@@ -54,10 +55,40 @@ local function searchFile(uri, key, results)
5455
end)
5556
end
5657

58+
---@async
59+
---@param key string
60+
---@param results table[]
61+
local function searchGlobalAndClass(key, results)
62+
for _, global in pairs(vm.getAllGlobals()) do
63+
local name = global:getCodeName()
64+
if matchKey(key, name) then
65+
for _, set in ipairs(global:getAllSets()) do
66+
local kind
67+
if set.type == 'doc.class' then
68+
kind = define.SymbolKind.Class
69+
elseif set.type == 'doc.alias' then
70+
kind = define.SymbolKind.Namespace
71+
else
72+
kind = define.SymbolKind.Variable
73+
end
74+
results[#results+1] = {
75+
name = name,
76+
kind = kind,
77+
uri = guide.getUri(set),
78+
range = { set.start, set.finish },
79+
}
80+
end
81+
await.delay()
82+
end
83+
end
84+
end
85+
5786
---@async
5887
return function (key)
5988
local results = {}
6089

90+
searchGlobalAndClass(key, results)
91+
6192
for uri in files.eachFile() do
6293
searchFile(uri, key, results)
6394
if #results > 1000 then

script/vm/global.lua

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function mt:addGet(uri, source)
4242
self.getsCache = nil
4343
end
4444

45-
---@param suri uri
45+
---@param suri uri
4646
---@return parser.object[]
4747
function mt:getSets(suri)
4848
if not self.setsCache then
@@ -72,6 +72,27 @@ function mt:getSets(suri)
7272
return cache
7373
end
7474

75+
---@return parser.object[]
76+
function mt:getAllSets()
77+
if not self.setsCache then
78+
self.setsCache = {}
79+
end
80+
local cache = self.setsCache['*']
81+
if cache then
82+
return cache
83+
end
84+
cache = {}
85+
self.setsCache['*'] = cache
86+
for _, link in pairs(self.links) do
87+
if link.sets then
88+
for _, source in ipairs(link.sets) do
89+
cache[#cache+1] = source
90+
end
91+
end
92+
end
93+
return cache
94+
end
95+
7596
---@return parser.object[]
7697
function mt:getGets(suri)
7798
if not self.getsCache then
@@ -467,6 +488,11 @@ function vm.getGlobals(cate)
467488
return globals
468489
end
469490

491+
---@return table<string, vm.global>
492+
function vm.getAllGlobals()
493+
return allGlobals
494+
end
495+
470496
---@param suri uri
471497
---@param cate vm.global.cate
472498
---@return parser.object[]

0 commit comments

Comments
 (0)