summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua8
-rw-r--r--script/core/noder.lua2
-rw-r--r--script/core/searcher.lua53
-rw-r--r--script/vm/getGlobals.lua28
4 files changed, 34 insertions, 57 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index cc89b20d..35c2fb2f 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -323,7 +323,7 @@ local function checkModule(ast, word, offset, results)
local fileName = path:match '[^/\\]*$'
local stemName = fileName:gsub('%..+', '')
if not locals[stemName]
- and #vm.getDefs('G', stemName) == 0
+ and #vm.getGlobalSets(stemName) == 0
and not config.config.diagnostics.globals[stemName]
and stemName:match '^[%a_][%w_]*$'
and matchKey(word, stemName) then
@@ -541,16 +541,16 @@ end
local function checkGlobal(ast, word, start, offset, parent, oop, results)
local locals = guide.getVisibleLocals(ast.ast, offset)
- local refs = vm.getDefs('G', '*')
+ local refs = vm.getGlobalSets '*'
checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals, 'global')
end
local function checkField(ast, word, start, offset, parent, oop, results)
if parent.tag == '_ENV' or parent.special == '_G' then
- local refs = vm.getDefs('G', '*')
+ local refs = vm.getGlobalSets '*'
checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results)
else
- local refs = vm.getRefs(parent, '*')
+ local refs = vm.getGlobals '*'
checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results)
end
end
diff --git a/script/core/noder.lua b/script/core/noder.lua
index e6ff1084..a4bec423 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -888,7 +888,7 @@ function m.compileNodes(source)
local root = guide.getRoot(source)
local noders = m.getNoders(source)
if next(noders) then
- return
+ return noders
end
guide.eachSource(root, function (src)
m.pushSource(noders, src)
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 81b263de..8c260767 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -141,18 +141,6 @@ function m.getUri(obj)
return ''
end
--- TODO
-function m.findGlobals(root)
- noder.compileNode(noder.getNoders(root), root)
- -- TODO
- return {}
-end
-
--- TODO
-function m.isGlobal(source)
- return false
-end
-
---@param obj parser.guide.object
---@return parser.guide.object?
function m.getObjectValue(obj)
@@ -548,7 +536,7 @@ local function getField(status, source, mode)
end
end
-local function searchAllGlobalByUri(status, mode, uri, name, fullID)
+local function searchAllGlobalByUri(status, mode, uri, fullID)
local ast = files.getAst(uri)
if not ast then
return
@@ -576,24 +564,11 @@ local function searchAllGlobalByUri(status, mode, uri, name, fullID)
end
end
end
-
- local node = noder.getNodeByID(root, 'dn:_G')
- if node and node.sources then
- for _, source in ipairs(node.sources) do
- if source.type == 'doc.class' then
- for _, field in ipairs(source.fields) do
- if not name or name == guide.getKeyName(field) then
- m.pushResult(status, mode, field)
- end
- end
- end
- end
- end
end
-local function searchAllGlobals(status, mode, name, fullID)
+local function searchAllGlobals(status, mode, fullID)
for uri in files.eachFile() do
- searchAllGlobalByUri(status, mode, uri, name, fullID)
+ searchAllGlobalByUri(status, mode, uri, fullID)
end
end
@@ -610,6 +585,19 @@ function m.searchRefs(status, source, mode)
m.searchRefsByID(status, uri, id, mode)
end
+function m.findGlobals(uri, mode, name)
+ local status = m.status()
+
+ if name then
+ local fullID = ('g:%q'):format(name)
+ searchAllGlobalByUri(status, mode, uri, fullID)
+ else
+ searchAllGlobalByUri(status, mode, uri)
+ end
+
+ return status.results
+end
+
---搜索对象的field
---@param status guide.status
---@param source parser.guide.object
@@ -622,7 +610,7 @@ function m.searchFields(status, source, mode, field)
end
log.debug('searchFields:', id, field)
if field == '*' then
- if source == 'G' or source.special == '_G' then
+ if source.special == '_G' then
searchAllGlobals(status, mode)
else
local newStatus = m.status(status)
@@ -632,10 +620,9 @@ function m.searchFields(status, source, mode, field)
end
end
else
- if source == 'G' or source.special == '_G' then
+ if source.special == '_G' then
local fullID = ('g:%q'):format(field)
- searchAllGlobals(status, mode, field, fullID)
- --m.searchRefsByID(status, uri, fullID, mode)
+ searchAllGlobals(status, mode, fullID)
else
local fullID = ('%s%s%q'):format(id, noder.SPLIT_CHAR, field)
m.searchRefsByID(status, uri, fullID, mode)
@@ -678,7 +665,7 @@ function m.requestReference(obj, field)
end
--- 请求对象的定义
----@param obj parser.guide.object|'"G"'
+---@param obj parser.guide.object
---@param field? string
---@return parser.guide.object[]
function m.requestDefinition(obj, field)
diff --git a/script/vm/getGlobals.lua b/script/vm/getGlobals.lua
index fd88c6c8..5660df5c 100644
--- a/script/vm/getGlobals.lua
+++ b/script/vm/getGlobals.lua
@@ -18,12 +18,8 @@ local function getGlobalsOfFile(uri)
end
local globals = {}
cache.globals = globals
- local ast = files.getAst(uri)
- if not ast then
- return globals
- end
tracy.ZoneBeginN 'getGlobalsOfFile'
- local results = guide.findGlobals(ast.ast)
+ local results = searcher.findGlobals(uri)
local subscribe = ws.getCache 'globalSubscribe'
subscribe[uri] = {}
local mark = {}
@@ -60,12 +56,8 @@ local function getGlobalSetsOfFile(uri)
end
local globals = {}
cache.globalSets = globals
- local ast = files.getAst(uri)
- if not ast then
- return globals
- end
tracy.ZoneBeginN 'getGlobalSetsOfFile'
- local results = guide.findGlobals(ast.ast)
+ local results = searcher.findGlobals(uri, 'def')
local subscribe = ws.getCache 'globalSetsSubscribe'
subscribe[uri] = {}
local mark = {}
@@ -77,16 +69,14 @@ local function getGlobalSetsOfFile(uri)
goto CONTINUE
end
mark[res] = true
- if vm.isSet(res) then
- local name = guide.getSimpleName(res)
- if name then
- if not globals[name] then
- globals[name] = {}
- subscribe[uri][#subscribe[uri]+1] = name
- end
- globals[name][#globals[name]+1] = res
- globals['*'][#globals['*']+1] = res
+ local name = guide.getSimpleName(res)
+ if name then
+ if not globals[name] then
+ globals[name] = {}
+ subscribe[uri][#subscribe[uri]+1] = name
end
+ globals[name][#globals[name]+1] = res
+ globals['*'][#globals['*']+1] = res
end
::CONTINUE::
end