summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-09 01:54:34 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-09 01:55:07 +0800
commit274de6ccd46ec6c589c799dea86a49b8c87b6df2 (patch)
tree09eedb43be4b1d087dac52080a7af0f56acd783a /script
parent4bf314156de18f08406953ae7ed8bf048102a0bb (diff)
downloadlua-language-server-274de6ccd46ec6c589c799dea86a49b8c87b6df2.zip
update tests
Diffstat (limited to 'script')
-rw-r--r--script/vm/compiler.lua34
-rw-r--r--script/vm/def.lua19
-rw-r--r--script/vm/ref.lua31
3 files changed, 44 insertions, 40 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index dad7d8f6..2af1746a 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -19,7 +19,7 @@ local m = {}
local searchFieldSwitch = util.switch()
: case 'table'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
local tp
if type(key) == 'table'
and key.type == 'global'
@@ -62,7 +62,7 @@ local searchFieldSwitch = util.switch()
end)
: case 'global'
---@param node vm.node.global
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
if node.cate == 'variable' then
if key then
if type(key) ~= 'string' then
@@ -80,17 +80,17 @@ local searchFieldSwitch = util.switch()
end
end
if node.cate == 'type' then
- m.getClassFields(node, key, pushResult)
+ m.getClassFields(suri, node, key, pushResult)
end
end)
: case 'string'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
-- change to `string: stringlib` ?
local stringlib = globalMgr.getGlobal('type', 'stringlib')
- m.getClassFields(stringlib, key, pushResult)
+ m.getClassFields(suri, stringlib, key, pushResult)
end)
: case 'local'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
local fields
if key then
fields = localID.getSources(node, key)
@@ -104,7 +104,7 @@ local searchFieldSwitch = util.switch()
end
end)
: case 'doc.type.array'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
if type(key) == 'number' then
if key < 1
or not math.tointeger(key) then
@@ -114,7 +114,7 @@ local searchFieldSwitch = util.switch()
pushResult(node.node)
end)
: case 'doc.type.table'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
for _, field in ipairs(node.fields) do
local fieldKey = field.name
if fieldKey.type == 'doc.type' then
@@ -141,7 +141,7 @@ local searchFieldSwitch = util.switch()
end)
-function m.getClassFields(node, key, pushResult)
+function m.getClassFields(suri, node, key, pushResult)
local mark = {}
local function searchClass(class)
@@ -164,14 +164,14 @@ function m.getClassFields(node, key, pushResult)
-- check local field and global field
if set.bindSources then
for _, src in ipairs(set.bindSources) do
- searchFieldSwitch(src.type, src, key, function (field)
+ searchFieldSwitch(src.type, suri, src, key, function (field)
if guide.isSet(field) then
hasFounded = true
pushResult(field)
end
end)
if src._globalNode then
- searchFieldSwitch('global', src._globalNode, key, function (field)
+ searchFieldSwitch('global', suri, src._globalNode, key, function (field)
hasFounded = true
pushResult(field)
end)
@@ -195,12 +195,9 @@ function m.getClassFields(node, key, pushResult)
local function searchGlobal(class)
if class.cate == 'type' and class.name == '_G' then
- local globals = globalMgr.getGlobals('variable')
- for _, global in ipairs(globals) do
- local sets = global:getSets()
- for _, set in ipairs(sets) do
- pushResult(set)
- end
+ local sets = globalMgr.getGlobalSets(suri, 'variable')
+ for _, set in ipairs(sets) do
+ pushResult(set)
end
end
end
@@ -449,8 +446,9 @@ function m.compileByParentNode(source, key, pushResult)
if not parentNode then
return
end
+ local suri = guide.getUri(source)
for node in nodeMgr.eachNode(parentNode) do
- searchFieldSwitch(node.type, node, key, pushResult)
+ searchFieldSwitch(node.type, suri, node, key, pushResult)
end
end
diff --git a/script/vm/def.lua b/script/vm/def.lua
index 1c9e1118..017d776a 100644
--- a/script/vm/def.lua
+++ b/script/vm/def.lua
@@ -77,7 +77,7 @@ simpleSwitch = util.switch()
local searchFieldSwitch = util.switch()
: case 'table'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
for _, field in ipairs(node) do
if field.type == 'tablefield'
or field.type == 'tableindex' then
@@ -90,7 +90,7 @@ local searchFieldSwitch = util.switch()
: case 'global'
---@param node vm.node
---@param key string
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
if node.cate == 'variable' then
local newGlobal = globalMgr.getGlobal('variable', node.name, key)
if newGlobal then
@@ -100,11 +100,11 @@ local searchFieldSwitch = util.switch()
end
end
if node.cate == 'type' then
- compiler.getClassFields(node, key, pushResult)
+ compiler.getClassFields(suri, node, key, pushResult)
end
end)
: case 'local'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
local sources = localID.getSources(node, key)
if sources then
for _, src in ipairs(sources) do
@@ -115,7 +115,7 @@ local searchFieldSwitch = util.switch()
end
end)
: case 'doc.type.table'
- : call(function (node, key, pushResult)
+ : call(function (suri, node, key, pushResult)
for _, field in ipairs(node.fields) do
local fieldKey = field.name
if fieldKey.type == 'doc.field.name' then
@@ -144,16 +144,18 @@ local nodeSwitch = util.switch()
if not parentNode then
return
end
+ local uri = guide.getUri(source)
local key = guide.getKeyName(source)
for pn in nodeMgr.eachNode(parentNode) do
- searchFieldSwitch(pn.type, pn, key, pushResult)
+ searchFieldSwitch(pn.type, uri, pn, key, pushResult)
end
end)
: case 'tableindex'
: case 'tablefield'
: call(function (source, pushResult)
local tbl = source.parent
- searchFieldSwitch(tbl.type, tbl, guide.getKeyName(source), pushResult)
+ local uri = guide.getUri(source)
+ searchFieldSwitch(tbl.type, uri, tbl, guide.getKeyName(source), pushResult)
end)
: case 'doc.see.field'
: call(function (source, pushResult)
@@ -161,8 +163,9 @@ local nodeSwitch = util.switch()
if not parentNode then
return
end
+ local uri = guide.getUri(source)
for pn in nodeMgr.eachNode(parentNode) do
- searchFieldSwitch(pn.type, pn, source[1], pushResult)
+ searchFieldSwitch(pn.type, uri, pn, source[1], pushResult)
end
end)
diff --git a/script/vm/ref.lua b/script/vm/ref.lua
index 70e7c483..51fd38bc 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -105,13 +105,13 @@ local function searchInAllFiles(suri, searcher, notify)
end
---@async
-local function searchField(source, pushResult, fileNotify)
+local function searchField(source, pushResult, defMap, fileNotify)
local key = guide.getKeyName(source)
---@param src parser.object
local function checkDef(src)
for _, def in ipairs(vm.getDefs(src)) do
- if def == source then
+ if defMap[def] then
pushResult(src)
return
end
@@ -192,8 +192,8 @@ local nodeSwitch = util.switch()
: case 'field'
: case 'method'
---@async
- : call(function (source, pushResult, fileNotify)
- searchByParentNode(source.parent, pushResult, fileNotify)
+ : call(function (source, pushResult, defMap, fileNotify)
+ searchByParentNode(source.parent, pushResult, defMap, fileNotify)
end)
: case 'getfield'
: case 'setfield'
@@ -202,7 +202,7 @@ local nodeSwitch = util.switch()
: case 'getindex'
: case 'setindex'
---@async
- : call(function (source, pushResult, fileNotify)
+ : call(function (source, pushResult, defMap, fileNotify)
local key = guide.getKeyName(source)
if type(key) ~= 'string' then
return
@@ -213,19 +213,19 @@ local nodeSwitch = util.switch()
return
end
- searchField(source, pushResult, fileNotify)
+ searchField(source, pushResult, defMap, fileNotify)
end)
: case 'tablefield'
: case 'tableindex'
---@async
- : call(function (source, pushResult, fileNotify)
- searchField(source, pushResult, fileNotify)
+ : call(function (source, pushResult, defMap, fileNotify)
+ searchField(source, pushResult, defMap, fileNotify)
end)
: case 'function'
: case 'doc.type.function'
---@async
- : call(function (source, pushResult, fileNotify)
- searchFunction(source, pushResult, fileNotify)
+ : call(function (source, pushResult, defMap, fileNotify)
+ searchFunction(source, pushResult, defMap, fileNotify)
end)
---@param source parser.object
@@ -250,8 +250,8 @@ end
---@param source parser.object
---@param pushResult fun(src: parser.object)
---@param fileNotify fun(uri: uri): boolean
-function searchByParentNode(source, pushResult, fileNotify)
- nodeSwitch(source.type, source, pushResult, fileNotify)
+function searchByParentNode(source, pushResult, defMap, fileNotify)
+ nodeSwitch(source.type, source, pushResult, defMap, fileNotify)
end
local function searchByNode(source, pushResult)
@@ -273,10 +273,13 @@ local function searchByDef(source, pushResult)
or source.type == 'doc.type.function' then
return
end
+ local defMap = {}
local defs = vm.getDefs(source)
for _, def in ipairs(defs) do
pushResult(def)
+ defMap[def] = true
end
+ return defMap
end
---@async
@@ -303,8 +306,8 @@ function vm.getRefs(source, fileNotify)
searchBySimple(source, pushResult)
searchByLocalID(source, pushResult)
searchByNode(source, pushResult)
- searchByDef(source, pushResult)
- searchByParentNode(source, pushResult, fileNotify)
+ local defMap = searchByDef(source, pushResult)
+ searchByParentNode(source, pushResult, defMap, fileNotify)
return results
end