summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-02-16 15:36:59 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-02-16 15:36:59 +0800
commit4e5ede23db35012ce0f2d9ec9a9425375f4f5062 (patch)
tree06c458137e70f0c847b309117d3ab219f4fe14e6
parent30bc6d37b823cab58114ea09c3f6388c6ef30b02 (diff)
downloadlua-language-server-4e5ede23db35012ce0f2d9ec9a9425375f4f5062.zip
cleanup
-rw-r--r--script/vm/getDef.lua38
-rw-r--r--script/vm/node/compiler.lua2
2 files changed, 33 insertions, 7 deletions
diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua
index 991bab68..5546617a 100644
--- a/script/vm/getDef.lua
+++ b/script/vm/getDef.lua
@@ -58,26 +58,52 @@ local noderMap = util.switch()
end)
: getMap()
-function vm.getDefs(source)
- local results = {}
-
- -- search by simple
+---@param source parser.guide.object
+---@param results parser.guide.object[]
+local function searchBySimple(source, results)
local simple = simpleMap[source.type]
if simple then
simple(source, results)
end
- local uri = guide.getUri(source)
+end
- -- search by node
+---@param source parser.guide.object
+---@param results parser.guide.object[]
+local function searchByGlobal(source, results)
+ local global = source._globalID
+ if not global then
+ return
+ end
+ for _, src in ipairs(global:getSets()) do
+ results[#results+1] = src
+ end
+end
+
+---@param source parser.guide.object
+---@param results parser.guide.object[]
+local function searchByNode(source, results)
+ local uri = guide.getUri(source)
local node = compiler.compileNode(uri, source)
local noder = noderMap[node.type]
if noder then
noder(node, results)
end
+end
+
+---@param source parser.guide.object
+---@return parser.guide.object[]
+function vm.getDefs(source)
+ local results = {}
+
+ searchBySimple(source, results)
+ searchByGlobal(source, results)
+ searchByNode(source, results)
return results
end
+---@param source parser.guide.object
+---@return parser.guide.object[]
function vm.getAllDefs(source)
return vm.getDefs(source)
end
diff --git a/script/vm/node/compiler.lua b/script/vm/node/compiler.lua
index ea82a467..db5cd486 100644
--- a/script/vm/node/compiler.lua
+++ b/script/vm/node/compiler.lua
@@ -6,7 +6,7 @@ local state = require 'vm.state'
---@field _compiledGlobal boolean
---@field _compiledNodes boolean
---@field _compiled any
----@field _globalID string
+---@field _globalID vm.node.global
---@class vm.node.compiler
local m = {}