summaryrefslogtreecommitdiff
path: root/script/vm/global-manager.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-05 05:56:03 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-05 05:56:03 +0800
commit0e159ee03730b74c284c5ad079215b31461d266e (patch)
tree9fd2d7aef9903d9c9c2d07749ea9f1175b0eee77 /script/vm/global-manager.lua
parent9310038417408a5c2f6c148447d951f248fce2fe (diff)
downloadlua-language-server-0e159ee03730b74c284c5ad079215b31461d266e.zip
update
Diffstat (limited to 'script/vm/global-manager.lua')
-rw-r--r--script/vm/global-manager.lua44
1 files changed, 37 insertions, 7 deletions
diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua
index eed65c64..5f0b6a14 100644
--- a/script/vm/global-manager.lua
+++ b/script/vm/global-manager.lua
@@ -89,16 +89,15 @@ local compilerGlobalSwitch = util.switch()
: case 'getindex'
---@param source parser.object
: call(function (source)
- local name
+ local name = guide.getKeyName(source)
+ if not name then
+ return
+ end
if source.node._globalNode then
local parentName = source.node._globalNode:getName()
- if parentName == '_G' then
- name = guide.getKeyName(source)
- else
- name = parentName .. m.ID_SPLITE .. guide.getKeyName(source)
+ if parentName ~= '_G' then
+ name = parentName .. m.ID_SPLITE .. name
end
- elseif source.node.special == '_G' then
- name = guide.getKeyName(source)
end
local uri = guide.getUri(source)
local global = m.declareGlobal('variable', name, uri)
@@ -260,6 +259,37 @@ function m.getGlobals(cate)
return globals
end
+---@param suri uri
+---@param cate vm.global.cate
+---@return parser.object[]
+function m.getGlobalSets(suri, cate)
+ local globals = m.getGlobals(cate)
+ local result = {}
+ for _, global in ipairs(globals) do
+ local sets = global:getSets()
+ for _, set in ipairs(sets) do
+ result[#result+1] = set
+ end
+ end
+ return result
+end
+
+---@param suri uri
+---@param cate vm.global.cate
+---@param name string
+---@return boolean
+function m.hasGlobalSets(suri, cate, name)
+ local global = m.getGlobal(cate, name)
+ if not global then
+ return false
+ end
+ local sets = global:getSets()
+ if #sets == 0 then
+ return false
+ end
+ return true
+end
+
---@param source parser.object
function m.compileObject(source)
if source._globalNode ~= nil then