summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-24 17:27:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-24 17:27:11 +0800
commit16f26d627f29912421da68280e14df967c6c670e (patch)
treec9e6b873a1c5915c9da08724d7ff28a79f016a1e /script-beta
parent41d5da00933be228f5a18c2f67490b0b2a822931 (diff)
downloadlua-language-server-16f26d627f29912421da68280e14df967c6c670e.zip
暂存
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/vm/eachDef.lua24
-rw-r--r--script-beta/vm/eachField.lua64
-rw-r--r--script-beta/vm/eachRef.lua7
3 files changed, 55 insertions, 40 deletions
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index 45da2fc6..96001d97 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -62,18 +62,16 @@ local function ofGlobal(source, callback)
end
end
+local function ofTableField(source, callback)
+ callback(source)
+end
+
local function ofField(source, callback)
local parent = source.parent
local key = guide.getKeyName(source)
if parent.type == 'tablefield'
or parent.type == 'tableindex' then
- local tbl = parent.parent
- vm.eachField(tbl, function (src)
- if vm.isSet(src)
- and key == guide.getKeyName(src) then
- callback(src)
- end
- end)
+ ofTableField(parent, callback)
else
local node = parent.node
vm.eachField(node, function (src)
@@ -82,6 +80,9 @@ local function ofField(source, callback)
callback(src)
end
end)
+ vm.eachRef(node, function (src)
+ vm.eachFieldInTable(src.value, callback)
+ end)
end
end
@@ -116,15 +117,6 @@ local function ofGoTo(source, callback)
end
end
-local function ofTableField(source, callback)
- local tbl = source.parent
- local src = tbl.parent
- if not src then
- return
- end
- return vm.eachField(src, callback)
-end
-
local function findIndex(parent, source)
for i = 1, #parent do
if parent[i] == source then
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index a23cfadf..f6a7a57d 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -14,23 +14,13 @@ local function checkNext(source)
or ntype == 'getmethod' then
return nextSrc
end
- return nil
-end
-
-local function findFieldInTable(value, callback)
- if not value then
- return
- end
- if value.type ~= 'table' then
- return
- end
- for i = 1, #value do
- local field = value[i]
- if field.type == 'tablefield'
- or field.type == 'tableindex' then
- callback(field)
+ if ntype == 'setindex'
+ or ntype == 'getindex' then
+ if nextSrc.node == source then
+ return nextSrc
end
end
+ return nil
end
local function ofENV(source, callback)
@@ -45,7 +35,7 @@ local function ofENV(source, callback)
elseif ref.type == 'setglobal' then
callback(ref)
end
- findFieldInTable(ref.value, callback)
+ vm.eachFieldInTable(ref.value, callback)
end
end
@@ -54,8 +44,8 @@ local function ofLocal(source, callback)
ofENV(source, callback)
else
vm.eachRef(source, function (src)
- findFieldInTable(src.value, callback)
- local nextSrc, mode = checkNext(src)
+ vm.eachFieldInTable(src.value, callback)
+ local nextSrc = checkNext(src)
if not nextSrc then
return
end
@@ -71,7 +61,18 @@ local function ofGlobal(source, callback)
return
end
callback(nextSrc)
- findFieldInTable(src.value, callback)
+ vm.eachFieldInTable(src.value, callback)
+ end)
+end
+
+local function ofGetField(source, callback)
+ vm.eachRef(source, function (src)
+ local nextSrc = checkNext(src)
+ if not nextSrc then
+ return
+ end
+ callback(nextSrc)
+ vm.eachFieldInTable(src.value, callback)
end)
end
@@ -80,7 +81,7 @@ local function ofTable(source, callback)
if parent and parent.value == source then
return vm.eachField(parent, callback)
else
- findFieldInTable(source, callback)
+ vm.eachFieldInTable(source, callback)
end
end
@@ -93,6 +94,22 @@ local function ofTableField(source, callback)
end)
end
+function vm.eachFieldInTable(value, callback)
+ if not value then
+ return
+ end
+ if value.type ~= 'table' then
+ return
+ end
+ for i = 1, #value do
+ local field = value[i]
+ if field.type == 'tablefield'
+ or field.type == 'tableindex' then
+ callback(field)
+ end
+ end
+end
+
function vm.eachField(source, callback)
local stype = source.type
if stype == 'local' then
@@ -107,5 +124,12 @@ function vm.eachField(source, callback)
ofTable(source, callback)
elseif stype == 'tablefield' then
ofTableField(source, callback)
+ elseif stype == 'getfield'
+ or stype == 'setfield'
+ or stype == 'getmethod'
+ or stype == 'setmethod'
+ or stype == 'getindex'
+ or stype == 'setindex' then
+ ofGetField(source, callback)
end
end
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 04a2cf6c..91aed10e 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -78,11 +78,10 @@ local function ofLiteral(source, callback)
if not parent then
return
end
- if parent.type == 'setindex'
- or parent.type == 'getindex' then
+ if parent.type == 'setindex'
+ or parent.type == 'getindex'
+ or parent.type == 'tableindex' then
ofField(source, callback)
- elseif parent.type == 'tableindex' then
- ofTableField(parent, callback)
end
end