summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-10-17 11:41:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-10-17 11:41:20 +0800
commit6b04f490fc0c45a0e3a70f3ca27c976f70b620c1 (patch)
treec003e08e2f3548573f9481f9913e335aab00fad1
parent33b0d6673c146dcf6a42f01b5c5d21d489fa8dec (diff)
downloadlua-language-server-6b04f490fc0c45a0e3a70f3ca27c976f70b620c1.zip
update workspace-symbol
-rw-r--r--script/core/workspace-symbol.lua31
-rw-r--r--script/vm/global.lua28
2 files changed, 58 insertions, 1 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
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 590264bd..29474b57 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -42,7 +42,7 @@ function mt:addGet(uri, source)
self.getsCache = nil
end
----@param suri uri
+---@param suri uri
---@return parser.object[]
function mt:getSets(suri)
if not self.setsCache then
@@ -73,6 +73,27 @@ function mt:getSets(suri)
end
---@return parser.object[]
+function mt:getAllSets()
+ if not self.setsCache then
+ self.setsCache = {}
+ end
+ local cache = self.setsCache['*']
+ if cache then
+ return cache
+ end
+ cache = {}
+ self.setsCache['*'] = cache
+ for _, link in pairs(self.links) do
+ if link.sets then
+ for _, source in ipairs(link.sets) do
+ cache[#cache+1] = source
+ end
+ end
+ end
+ return cache
+end
+
+---@return parser.object[]
function mt:getGets(suri)
if not self.getsCache then
self.getsCache = {}
@@ -467,6 +488,11 @@ function vm.getGlobals(cate)
return globals
end
+---@return table<string, vm.global>
+function vm.getAllGlobals()
+ return allGlobals
+end
+
---@param suri uri
---@param cate vm.global.cate
---@return parser.object[]