Skip to content

Commit f8cd9ff

Browse files
committed
improve workspace-symbol
1 parent 6b04f49 commit f8cd9ff

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

script/core/workspace-symbol.lua

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,63 @@ local function searchGlobalAndClass(key, results)
8484
end
8585

8686
---@async
87-
return function (key)
88-
local results = {}
89-
90-
searchGlobalAndClass(key, results)
87+
---@param key string
88+
---@param results table[]
89+
local function searchClassField(key, results)
90+
local class, inField = key:match('^(.+)%.(.-)$')
91+
if not class then
92+
return
93+
end
94+
local global = vm.getGlobal('type', class)
95+
if not global then
96+
return
97+
end
98+
local set = global:getAllSets()[1]
99+
if not set then
100+
return
101+
end
102+
local suri = guide.getUri(set)
103+
vm.getClassFields(suri, global, nil, false, function (field, isMark)
104+
if field.type == 'generic' then
105+
return
106+
end
107+
---@cast field -vm.generic
108+
local keyName = guide.getKeyName(field)
109+
if not keyName then
110+
return
111+
end
112+
if not matchKey(inField, keyName) then
113+
return
114+
end
115+
results[#results+1] = {
116+
name = class .. '.' .. keyName,
117+
kind = define.SymbolKind.Field,
118+
uri = guide.getUri(field),
119+
range = { field.start, field.finish },
120+
}
121+
end)
122+
end
91123

124+
---@async
125+
---@param key string
126+
---@param results table[]
127+
local function searchWords(key, results)
92128
for uri in files.eachFile() do
93129
searchFile(uri, key, results)
94130
if #results > 1000 then
95131
break
96132
end
97133
await.delay()
98134
end
135+
end
136+
137+
---@async
138+
return function (key)
139+
local results = {}
140+
141+
searchGlobalAndClass(key, results)
142+
searchClassField(key, results)
143+
searchWords(key, results)
99144

100145
return results
101146
end

0 commit comments

Comments
 (0)