summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-02-23 17:55:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-02-23 17:55:44 +0800
commitf8e2955268708728a1f83743d0b2000d2e089539 (patch)
tree102ede06a30d1629025f1c45096aff030e05c8ee
parentc1ccd90beef8b0a79a8e9c47547dda3dd865e14d (diff)
downloadlua-language-server-f8e2955268708728a1f83743d0b2000d2e089539.zip
cleanup
-rw-r--r--script/vm/node/compiler.lua58
-rw-r--r--test/definition/field.lua23
-rw-r--r--test/definition/init.lua1
3 files changed, 47 insertions, 35 deletions
diff --git a/script/vm/node/compiler.lua b/script/vm/node/compiler.lua
index 72869b25..dfe4bc0c 100644
--- a/script/vm/node/compiler.lua
+++ b/script/vm/node/compiler.lua
@@ -13,7 +13,7 @@ local m = {}
---@class vm.node.cross
----@alias vm.node parser.object | vm.node.union | vm.node.cross
+---@alias vm.node parser.object | vm.node.union | vm.node.cross | vm.node.global
function m.setNode(source, node)
if not node then
@@ -71,36 +71,6 @@ local function getReturn(func, index)
end
end
-local valueMap = util.switch()
- : case 'boolean'
- : case 'table'
- : case 'integer'
- : case 'number'
- : case 'string'
- : case 'function'
- : call(function (source, value)
- state.declareLiteral(value)
- m.setNode(source, value)
- end)
- : case 'select'
- : call(function (source, value)
- local vararg = value.vararg
- if vararg.type == 'call' then
- m.setNode(source, getReturn(vararg.node, value.sindex))
- end
- end)
- : getMap()
-
-local function compileValue(source, value)
- if not value then
- return
- end
- local f = valueMap[value.type]
- if f then
- f(source, value)
- end
-end
-
local function compileByLocalID(source)
local sources = localID.getSources(source)
if not sources then
@@ -108,7 +78,7 @@ local function compileByLocalID(source)
end
for _, src in ipairs(sources) do
if src.value then
- compileValue(source, src.value)
+ m.setNode(source, m.compileNode(src.value))
end
end
end
@@ -136,19 +106,30 @@ local function compileByParentNode(source)
local f = searchFieldMap[parentNode.type]
if f then
f(parentNode, key, function (field)
- compileValue(source, field.value)
+ m.setNode(source, m.compileNode(field.value))
end)
end
end
local compilerMap = util.switch()
+ : case 'boolean'
+ : case 'table'
+ : case 'integer'
+ : case 'number'
+ : case 'string'
+ : case 'function'
+ : call(function (source)
+ m.setNode(source, state.declareLiteral(source))
+ end)
: case 'local'
: call(function (source)
- compileValue(source, source.value)
+ if source.value then
+ m.setNode(source, m.compileNode(source.value))
+ end
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
- compileValue(source, ref.value)
+ m.setNode(source, m.compileNode(ref.value))
end
end
end
@@ -182,6 +163,13 @@ local compilerMap = util.switch()
end
end
end)
+ : case 'select'
+ : call(function (source, value)
+ local vararg = value.vararg
+ if vararg.type == 'call' then
+ m.setNode(source, getReturn(vararg.node, value.sindex))
+ end
+ end)
: getMap()
---@param source parser.object
diff --git a/test/definition/field.lua b/test/definition/field.lua
new file mode 100644
index 00000000..5b5b67f9
--- /dev/null
+++ b/test/definition/field.lua
@@ -0,0 +1,23 @@
+TEST [[
+X.<!y!> = 1
+
+local t = X
+
+print(t.<?y?>)
+]]
+
+TEST [[
+X.x.<!y!> = 1
+
+local t = X.x
+
+print(t.<?y?>)
+]]
+
+TEST [[
+X.x.<!y!> = 1
+
+local t = X
+
+print(t.x.<?y?>)
+]]
diff --git a/test/definition/init.lua b/test/definition/init.lua
index fc2903c1..08b97442 100644
--- a/test/definition/init.lua
+++ b/test/definition/init.lua
@@ -44,6 +44,7 @@ end
require 'definition.local'
require 'definition.set'
+require 'definition.field'
require 'definition.arg'
require 'definition.function'
require 'definition.table'