summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-18 21:48:05 +0800
committersumneko <sumneko@hotmail.com>2019-04-18 21:48:05 +0800
commit1a889f53a34fdb2ae77bfe7189a5e00a2e723187 (patch)
treed3f68da1b2f8ee9af8e37512c22af98b876047dc
parent92e1b16ba3e6749602f2ea2dcb64a73f11653caa (diff)
downloadlua-language-server-1a889f53a34fdb2ae77bfe7189a5e00a2e723187.zip
更新一下
-rw-r--r--server/src/core/diagnostics.lua14
-rw-r--r--server/src/emmy/manager.lua5
-rw-r--r--server/src/emmy/type.lua33
-rw-r--r--server/src/parser/ast.lua19
-rw-r--r--server/src/parser/grammar.lua10
-rw-r--r--server/src/vm/emmy.lua2
-rw-r--r--server/test/diagnostics/init.lua9
-rw-r--r--server/test/hover/init.lua44
8 files changed, 116 insertions, 20 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 33037d5f..d6d06880 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -462,10 +462,24 @@ function mt:checkEmmyClass(source, callback)
end
end
+function mt:checkEmmyType(source, callback)
+ for _, tpsource in ipairs(source) do
+ local name = tpsource[1]
+ local class = self.vm.emmyMgr:eachClass(name, function (class)
+ return class
+ end)
+ if not class then
+ callback(tpsource.start, tpsource.finish, lang.script.DIAG_UNDEFINED_CLASS)
+ end
+ end
+end
+
function mt:searchEmmyLua(callback)
self.vm:eachSource(function (source)
if source.type == 'emmyClass' then
self:checkEmmyClass(source, callback)
+ elseif source.type == 'emmyType' then
+ self:checkEmmyType(source, callback)
end
end)
end
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index df9094cd..104944b2 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -1,5 +1,6 @@
local listMgr = require 'vm.list'
local newClass = require 'emmy.class'
+local newType = require 'emmy.type'
local mt = {}
mt.__index = mt
@@ -58,9 +59,7 @@ function mt:addClass(source)
end
function mt:createType(source)
-end
-
-function mt:remove()
+ return newType(source)
end
return function ()
diff --git a/server/src/emmy/type.lua b/server/src/emmy/type.lua
new file mode 100644
index 00000000..84b43144
--- /dev/null
+++ b/server/src/emmy/type.lua
@@ -0,0 +1,33 @@
+local listMgr = require 'vm.list'
+
+local function buildName(source)
+ local names = {}
+ for i, type in ipairs(source) do
+ names[i] = type[1]
+ end
+ return table.concat(names, '|')
+end
+
+local mt = {}
+mt.__index = mt
+mt.type = 'emmy.type'
+
+function mt:getType()
+ return self.name
+end
+
+function mt:getName()
+ return self.name
+end
+
+function mt:getSource()
+ return listMgr.get(self.source)
+end
+
+return function (source)
+ local self = setmetatable({
+ name = buildName(source),
+ source = source.id,
+ }, mt)
+ return self
+end
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 35118d35..dd6c6cfc 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -1124,10 +1124,7 @@ local Defs = {
[2] = extends,
}
end,
- EmmyType = function (typeDef, ...)
- if ... then
- typeDef.enum = {...}
- end
+ EmmyType = function (typeDef)
return typeDef
end,
EmmyCommonType = function (...)
@@ -1152,18 +1149,20 @@ local Defs = {
...
}
end,
- EmmyAlias = function (name, emmyName)
+ EmmyAlias = function (name, emmyName, ...)
return {
type = 'emmyAlias',
- [1] = name,
- [2] = emmyName,
+ name,
+ emmyName,
+ ...
}
end,
- EmmyParam = function (argName, emmyName)
+ EmmyParam = function (argName, emmyName, ...)
return {
type = 'emmyParam',
- [1] = argName,
- [2] = emmyName,
+ argName,
+ emmyName,
+ ...
}
end,
EmmyReturn = function (...)
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index 97d60402..d5c375f0 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -536,9 +536,7 @@ EmmyIncomplete <- MustEmmyName
EmmyClass <- (MustEmmyName EmmyParentClass?)
EmmyParentClass <- %s* ':' %s* MustEmmyName
-EmmyType <- (EmmyTypeDef EmmyTypeEnums*)
- -> EmmyType
-EmmyTypeDef <- EmmyFunctionType
+EmmyType <- EmmyFunctionType
/ EmmyArrayType
/ EmmyTableType
/ EmmyCommonType
@@ -549,11 +547,11 @@ EmmyTypeName <- EmmyFunctionType
/ EmmyArrayType
/ EmmyTableType
/ MustEmmyName
-EmmyTypeEnums <- %s+ '|' %s+ String
+EmmyTypeEnums <- %s* '|' %s* String
-EmmyAlias <- MustEmmyName %s+ EmmyType
+EmmyAlias <- MustEmmyName %s+ EmmyType EmmyTypeEnums*
-EmmyParam <- MustEmmyName %s+ EmmyType
+EmmyParam <- MustEmmyName %s+ EmmyType EmmyTypeEnums*
EmmyReturn <- EmmyType
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua
index 67c620a8..c83b2d95 100644
--- a/server/src/vm/emmy.lua
+++ b/server/src/vm/emmy.lua
@@ -21,7 +21,7 @@ end
function mt:doEmmyType(action)
local emmyMgr = self.emmyMgr
self:instantSource(action)
- local type = emmyMgr:createType()
+ local type = emmyMgr:createType(action)
self._emmy = type
action:set('emmy.type', type)
end
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index 7bb25f00..c82a3eaa 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -355,3 +355,12 @@ TEST [[
---@class C : D
---@class D
]]
+
+TEST [[
+---@type <!A!>
+]]
+
+TEST [[
+---@class A
+---@type A|<!B!>|<!C!>
+]]
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 0d2180bb..bdd26932 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -480,3 +480,47 @@ TEST[[
[[
global x: *Class
]]
+
+TEST[[
+local t = {
+ ---@class Class
+ <?x?> = class()
+}
+]]
+[[
+field x: *Class
+]]
+
+TEST[[
+---@type Class
+local <?x?> = class()
+]]
+[[
+local x: *Class
+]]
+
+TEST[[
+---@type Class
+<?x?> = class()
+]]
+[[
+global x: *Class
+]]
+
+TEST[[
+local t = {
+ ---@type Class
+ <?x?> = class()
+}
+]]
+[[
+field x: *Class
+]]
+
+TEST[[
+---@type A|B|C
+local <?x?> = class()
+]]
+[[
+local x: *A|B|C
+]]