summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-07-10 21:59:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-07-10 21:59:11 +0800
commita9335f9a6477d267928c62776f61fabcaa7bcc66 (patch)
treed7e25e273b5ec2d259f65843734175e330d44e4b
parentb6a99fe50a46812696848f0ad68bd4ef343dc9b3 (diff)
downloadlua-language-server-a9335f9a6477d267928c62776f61fabcaa7bcc66.zip
更新arrayType语法
-rw-r--r--server/src/emmy/arrayType.lua7
-rw-r--r--server/src/emmy/manager.lua10
-rw-r--r--server/src/parser/ast.lua12
-rw-r--r--server/src/parser/grammar.lua9
-rw-r--r--server/src/vm/emmy.lua5
-rw-r--r--server/test/hover/init.lua10
6 files changed, 35 insertions, 18 deletions
diff --git a/server/src/emmy/arrayType.lua b/server/src/emmy/arrayType.lua
index 3c6a7b7b..c5d73500 100644
--- a/server/src/emmy/arrayType.lua
+++ b/server/src/emmy/arrayType.lua
@@ -19,17 +19,18 @@ end
function mt:setValue(value)
self.value = value
- self:getSource():get('emmy.typeUnit'):setValue(value)
+ self._child:setValue(value)
end
function mt:getValue()
return self.value
end
-return function (manager, source)
+return function (manager, source, child)
local self = setmetatable({
- name = source[1],
+ name = child:getName(),
source = source.id,
+ _child = child,
_manager = manager,
}, mt)
return self
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index 9b6978b9..fc7180bd 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -110,13 +110,9 @@ function mt:addType(source)
end
function mt:addArrayType(source)
- local typeObj = newArrayType(self, source)
- local typeUnit = newTypeUnit(self, source)
- local list = self:getClass(source[1])
- typeUnit:setParent(typeObj)
- list[source.id] = typeUnit
- source:set('emmy.typeUnit', typeUnit)
- return typeObj
+ local typeObj = self:addType(source)
+ local arrayTypeObj = newArrayType(self, source, typeObj)
+ return arrayTypeObj
end
function mt:addTableType(source, keyType, valueType)
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 52b34343..1d44c848 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1211,9 +1211,11 @@ local Defs = {
result.finish = result[#result].finish
return result
end,
- EmmyArrayType = function (typeName)
- typeName.type = 'emmyArrayType'
- return typeName
+ EmmyArrayType = function (start, emmy, _, finish)
+ emmy.type = 'emmyArrayType'
+ emmy.start = start
+ emmy.finish = finish - 1
+ return emmy
end,
EmmyTableType = function (start, keyType, valueType, finish)
return {
@@ -1238,7 +1240,9 @@ local Defs = {
return {...}
end,
EmmyFunctionArgs = function (...)
- return {...}
+ local args = {...}
+ args[#args] = nil
+ return args
end,
EmmyAlias = function (name, emmyName, ...)
return {
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index c20f5b32..bf725189 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -68,6 +68,7 @@ defs.Reserved = function (_, _, str)
end
return false
end
+defs.None = function () end
defs.np = m.Cp() / function (n) return n+1 end
m.setmaxstack(1000)
@@ -587,7 +588,9 @@ EmmyVararg <- EmmyType
EmmyLanguage <- MustEmmyName
-EmmyArrayType <- (MustEmmyName '[]')
+EmmyArrayType <- ({} MustEmmyName -> EmmyCommonType {} '[' DirtyBR)
+ -> EmmyArrayType
+ / ({} PL EmmyCommonType DirtyPR '[' DirtyBR)
-> EmmyArrayType
EmmyTableType <- ({} 'table' Cut '<' %s* EmmyType %s* ',' %s* EmmyType %s* '>' {})
@@ -595,9 +598,9 @@ EmmyTableType <- ({} 'table' Cut '<' %s* EmmyType %s* ',' %s* EmmyType %s* '>
EmmyFunctionType<- ({} 'fun' Cut %s* EmmyFunctionArgs %s* EmmyFunctionRtns {})
-> EmmyFunctionType
-EmmyFunctionArgs<- ('(' %s* EmmyFunctionArg %s* (',' %s* EmmyFunctionArg %s*)* ')')
+EmmyFunctionArgs<- ('(' %s* EmmyFunctionArg %s* (',' %s* EmmyFunctionArg %s*)* DirtyPR)
-> EmmyFunctionArgs
- / '(' %nil ')'?
+ / '(' %nil DirtyPR -> None
/ %nil
EmmyFunctionRtns<- (':' %s* EmmyType (%s* ',' %s* EmmyType)*)
-> EmmyFunctionRtns
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua
index 5a15d3b0..45fb13f9 100644
--- a/server/src/vm/emmy.lua
+++ b/server/src/vm/emmy.lua
@@ -259,7 +259,10 @@ function mt:buildEmmyArrayType(action)
---@type emmyMgr
local emmyMgr = self.emmyMgr
self:instantSource(action)
- action:set('emmy class', action[1])
+ for _, obj in ipairs(action) do
+ self:instantSource(obj)
+ action:set('emmy class', obj[1])
+ end
local type = emmyMgr:addArrayType(action)
return type
end
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 72ad28b5..cafbdc99 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -664,6 +664,16 @@ local x: {
]]
TEST [[
+---@type (string|boolean)[]
+local <?x?>
+]]
+[[
+local x: {
+ [*integer]: string|boolean,
+}
+]]
+
+TEST [[
---@type string[]
local t
local <?x?> = t[1]