summaryrefslogtreecommitdiff
path: root/script/core/workspace-symbol.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/core/workspace-symbol.lua')
-rw-r--r--script/core/workspace-symbol.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua
index 9dd768db..9d52572b 100644
--- a/script/core/workspace-symbol.lua
+++ b/script/core/workspace-symbol.lua
@@ -3,6 +3,7 @@ local guide = require 'parser.guide'
local matchKey = require 'core.matchkey'
local define = require 'proto.define'
local await = require 'await'
+local vm = require 'vm'
local function buildSource(uri, source, key, results)
if source.type == 'local'
@@ -55,9 +56,39 @@ local function searchFile(uri, key, results)
end
---@async
+---@param key string
+---@param results table[]
+local function searchGlobalAndClass(key, results)
+ for _, global in pairs(vm.getAllGlobals()) do
+ local name = global:getCodeName()
+ if matchKey(key, name) then
+ for _, set in ipairs(global:getAllSets()) do
+ local kind
+ if set.type == 'doc.class' then
+ kind = define.SymbolKind.Class
+ elseif set.type == 'doc.alias' then
+ kind = define.SymbolKind.Namespace
+ else
+ kind = define.SymbolKind.Variable
+ end
+ results[#results+1] = {
+ name = name,
+ kind = kind,
+ uri = guide.getUri(set),
+ range = { set.start, set.finish },
+ }
+ end
+ await.delay()
+ end
+ end
+end
+
+---@async
return function (key)
local results = {}
+ searchGlobalAndClass(key, results)
+
for uri in files.eachFile() do
searchFile(uri, key, results)
if #results > 1000 then