summaryrefslogtreecommitdiff
path: root/script-beta/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-09 15:00:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-09 15:00:29 +0800
commit9f621b6076181e577748dda3966bbc526586445d (patch)
tree05057166585d0f229030c44718312432ab163dc7 /script-beta/vm
parent1e3726e3d3f6c84ce29e857181261b5ffb2d0da3 (diff)
downloadlua-language-server-9f621b6076181e577748dda3966bbc526586445d.zip
支持看lib的table
Diffstat (limited to 'script-beta/vm')
-rw-r--r--script-beta/vm/eachDef.lua18
-rw-r--r--script-beta/vm/eachField.lua31
-rw-r--r--script-beta/vm/eachRef.lua2
-rw-r--r--script-beta/vm/getGlobals.lua3
-rw-r--r--script-beta/vm/getLibrary.lua5
5 files changed, 42 insertions, 17 deletions
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index 0274cbee..1b7ea621 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -25,7 +25,8 @@ function vm.eachDef(source, callback)
if info.mode == 'declare'
or info.mode == 'set'
or info.mode == 'return'
- or info.mode == 'value' then
+ or info.mode == 'value'
+ or info.mode == 'library' then
results[#results+1] = info
local src = info.source
if info.mode == 'return' then
@@ -38,11 +39,9 @@ function vm.eachDef(source, callback)
for _, info in ipairs(results) do
local src = info.source
local destUri = guide.getRoot(src).uri
- -- 如果是同一个文件,则检查位置关系后放行
- if sourceUri == destUri then
- if checkPath(source, info) then
- callback(info)
- end
+ -- 如果是library,则直接放行
+ if src.library then
+ callback(info)
goto CONTINUE
end
-- 如果是global或field,则直接放行(因为无法确定顺序)
@@ -55,6 +54,13 @@ function vm.eachDef(source, callback)
callback(info)
goto CONTINUE
end
+ -- 如果是同一个文件,则检查位置关系后放行
+ if sourceUri == destUri then
+ if checkPath(source, info) then
+ callback(info)
+ end
+ goto CONTINUE
+ end
-- 如果不是同一个文件,则必须在该文件 return 后才放行
if valueUris[destUri] then
callback(info)
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index 1d3d222d..a707407e 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -2,15 +2,28 @@ local guide = require 'parser.guide'
local vm = require 'vm.vm'
local function ofTabel(value, callback)
- for _, field in ipairs(value) do
- if field.type == 'tablefield'
- or field.type == 'tableindex' then
- callback {
- source = field,
- key = guide.getKeyName(field),
- value = field.value,
- mode = 'set',
- }
+ if value.library then
+ if value.child then
+ for k, field in pairs(value.child) do
+ callback {
+ source = field,
+ key = 's|' .. k,
+ value = field,
+ mode = 'set',
+ }
+ end
+ end
+ else
+ for _, field in ipairs(value) do
+ if field.type == 'tablefield'
+ or field.type == 'tableindex' then
+ callback {
+ source = field,
+ key = guide.getKeyName(field),
+ value = field.value,
+ mode = 'set',
+ }
+ end
end
end
end
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index d990ee1a..72d7c012 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -125,7 +125,7 @@ local function ofSpecialCall(call, func, index, callback)
if lib then
callback {
source = lib,
- mode = 'library',
+ mode = 'value',
}
end
end
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua
index 699dd270..116bf8d5 100644
--- a/script-beta/vm/getGlobals.lua
+++ b/script-beta/vm/getGlobals.lua
@@ -3,6 +3,9 @@ local vm = require 'vm.vm'
local function getGlobals(root)
local env = guide.getENV(root)
+ if not env then
+ return nil
+ end
local cache = {}
local mark = {}
vm.eachField(env, function (info)
diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua
index 959b7084..d2f88116 100644
--- a/script-beta/vm/getLibrary.lua
+++ b/script-beta/vm/getLibrary.lua
@@ -3,6 +3,9 @@ local library = require 'library'
local guide = require 'parser.guide'
local function checkStdLibrary(source)
+ if source.library then
+ return source
+ end
local globalName = vm.getGlobal(source)
if not globalName then
return nil
@@ -73,7 +76,7 @@ local function getLibrary(source)
return lib
end
return checkNode(source) or vm.eachRef(source, function (info)
- return checkNode(info.source)
+ return checkStdLibrary(info.source) or checkNode(info.source)
end)
end