summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-06 20:37:21 +0800
committersumneko <sumneko@hotmail.com>2019-05-06 20:37:21 +0800
commit122f0cd318b54038761dd1523a49d00492d24f29 (patch)
treed17ae8a22b18b1684f9375e7d05b0b6111c02dfb /server
parent9be258a93dec660ace3ec153d3f154776663b599 (diff)
downloadlua-language-server-122f0cd318b54038761dd1523a49d00492d24f29.zip
内置类型
Diffstat (limited to 'server')
-rw-r--r--server/src/emmy/class.lua6
-rw-r--r--server/src/emmy/manager.lua26
-rw-r--r--server/test/completion/init.lua37
-rw-r--r--server/test/diagnostics/init.lua4
4 files changed, 48 insertions, 25 deletions
diff --git a/server/src/emmy/class.lua b/server/src/emmy/class.lua
index a7417210..6728e2c4 100644
--- a/server/src/emmy/class.lua
+++ b/server/src/emmy/class.lua
@@ -50,11 +50,11 @@ function mt:eachField(callback)
end
end
-return function (manager, source)
+return function (manager, name, extends, source)
local self = setmetatable({
- name = source[1][1],
+ name = name,
source = source.id,
- extends = source[2] and source[2][1],
+ extends = extends,
_manager = manager,
}, mt)
return self
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index cce1e0e4..c1d46742 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -1,4 +1,5 @@
local listMgr = require 'vm.list'
+local sourceMgr = require 'vm.source'
local newClass = require 'emmy.class'
local newType = require 'emmy.type'
local newTypeUnit = require 'emmy.typeUnit'
@@ -81,11 +82,17 @@ function mt:getClass(name)
return list
end
+function mt:newClass(name, extends, source)
+ local list = self:getClass(name)
+ list[source.id] = newClass(self, name, extends, source)
+ return list[source.id]
+end
+
function mt:addClass(source)
local className = source[1][1]
- local list = self:getClass(className)
- list[source.id] = newClass(self, source)
- return list[source.id]
+ local extends = source[2] and source[2][1]
+ local class = self:newClass(className, extends, source)
+ return class
end
function mt:addType(source)
@@ -196,5 +203,18 @@ return function ()
local self = setmetatable({
_class = {},
}, mt)
+
+ local source = sourceMgr.dummy()
+ self:newClass('any', nil, source)
+ self:newClass('string', 'any', source)
+ self:newClass('number', 'any', source)
+ self:newClass('integer', 'number', source)
+ self:newClass('boolean', 'any', source)
+ self:newClass('table', 'any', source)
+ self:newClass('function', 'any', source)
+ self:newClass('nil', 'any', source)
+ self:newClass('userdata', 'any', source)
+ self:newClass('thread', 'any', source)
+
return self
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index 0d34a63b..19bf927a 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -807,28 +807,28 @@ TEST [[
}
TEST [[
----@class ABC
----@class BBC : $
+---@class ZABC
+---@class ZBBC : Z$
]]
{
{
- label = 'ABC',
+ label = 'ZABC',
kind = CompletionItemKind.Class,
},
{
- label = 'BBC',
+ label = 'ZBBC',
kind = CompletionItemKind.Class,
},
}
TEST [[
----@class abc
+---@class zabc
local abcd
----@type a$
+---@type za$
]]
{
{
- label = 'abc',
+ label = 'zabc',
kind = CompletionItemKind.Class,
},
}
@@ -838,32 +838,27 @@ TEST [[
local abcd
---@type $
]]
-{
- {
- label = 'abc',
- kind = CompletionItemKind.Class,
- },
-}
+(EXISTS)
TEST [[
----@class abc
+---@class zabc
local abcd
----@type xxx|$
+---@type zxxx|z$
]]
{
{
- label = 'abc',
+ label = 'zabc',
kind = CompletionItemKind.Class,
}
}
TEST [[
----@alias abc abb
----@type a$
+---@alias zabc zabb
+---@type za$
]]
{
{
- label = 'abc',
+ label = 'zabc',
kind = CompletionItemKind.Class,
},
}
@@ -877,6 +872,10 @@ TEST [[
label = 'Class',
kind = CompletionItemKind.Class,
},
+ {
+ label = 'function',
+ kind = CompletionItemKind.Class,
+ },
}
TEST [[
diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua
index 499ffe78..2ef052bf 100644
--- a/server/test/diagnostics/init.lua
+++ b/server/test/diagnostics/init.lua
@@ -426,3 +426,7 @@ TEST [[
---@field <!x!> Class
---@field <!x!> Class
]]
+
+TEST [[
+---@class Class : any
+]]