summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-28 15:16:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-28 15:16:10 +0800
commitf72976a6fa20549afe91cdb8740d6bc59332ee92 (patch)
tree6f8b03dbfee40950f51ecea2ecd2729bbc7c5dbc /server/src/core
parente25be4fc724d0cc56b12c6453426763c750a7dc7 (diff)
downloadlua-language-server-f72976a6fa20549afe91cdb8740d6bc59332ee92.zip
类型推导
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/completion.lua6
-rw-r--r--server/src/core/document_symbol.lua2
-rw-r--r--server/src/core/hover.lua13
-rw-r--r--server/src/core/value.lua19
4 files changed, 21 insertions, 19 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index cbabd9ff..1cf05b35 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -157,7 +157,7 @@ local function getKind(var, default)
return CompletionItemKind.Enum
end
if value:getType() == 'function' then
- if var.parent and var.parent.value and var.parent.value.ENV ~= true then
+ if var.parent and var.parent.value and var.parent.value.GLOBAL ~= true then
return CompletionItemKind.Method
else
return CompletionItemKind.Function
@@ -469,7 +469,7 @@ local function searchInResult(result, word, source, vm, pos, callback)
elseif result.type == 'field' then
if source.isIndex then
searchAsIndex(vm, word, pos, result, callback)
- elseif result.parent and result.parent.value and result.parent.value.ENV == true then
+ elseif result.parent and result.parent.value and result.parent.value.GLOBAL == true then
searchAsGlobal(vm, word, pos, result, callback)
else
searchAsSuffix(result, word, callback)
@@ -506,7 +506,7 @@ local function searchSpecial(vm, pos, callback)
if not var then
break
end
- if var.value and var.value.ENV then
+ if var.value and var.value.GLOBAL then
break
end
local key = var.key
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index 4ede0654..e2253594 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -58,7 +58,7 @@ local function buildFunction(vm, func)
if var then
range = { math.min(source.start, declarat.start), source.finish }
selectionRange = { declarat.start, declarat.finish }
- if var.parent and var.parent.value and not var.parent.value.ENV then
+ if var.parent and var.parent.value and not var.parent.value.GLOBAL then
kind = SymbolKind.Field
end
else
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua
index d3beeaad..be60d590 100644
--- a/server/src/core/hover.lua
+++ b/server/src/core/hover.lua
@@ -210,21 +210,16 @@ local function getFunctionHoverAsLib(name, lib, oo, select)
end
local function findClass(result)
- -- 根据部分字段尝试找出自定义类型
- local metatable = result.value.metatable
- if not metatable then
- return nil
- end
-- 查找meta表的 __name 字段
- local name = metatable:rawGetField('__name')
+ local name = result.value:getMeta('__name', result.source)
-- 值必须是字符串
if name and name.value and type(name.value:getValue()) == 'string' then
return name.value:getValue()
end
-- 查找meta表 __index 里的字段
- local index = metatable:rawGetField('__index')
+ local index = result.value:getMeta('__index', result.source)
if index and index.value then
- index.value:eachField(function (key, field)
+ return index.value:eachField(function (key, field)
-- 键值类型必须均为字符串
if type(key) ~= 'string' then
goto CONTINUE
@@ -313,7 +308,7 @@ local function getValueHover(name, valueType, result, lib)
local tp = result.type
if tp == 'field' then
- if result.parent and result.parent.value and result.parent.value.ENV then
+ if result.parent and result.parent.value and result.parent.value.GLOBAL then
tp = 'global'
end
end
diff --git a/server/src/core/value.lua b/server/src/core/value.lua
index c0f8848d..35e59816 100644
--- a/server/src/core/value.lua
+++ b/server/src/core/value.lua
@@ -16,8 +16,11 @@ function mt:inference(tp, rate)
if tp == '...' then
error('Value type cant be ...')
end
- if not tp or tp == 'any' then
- return
+ if not tp then
+ tp = 'nil'
+ end
+ if tp == 'any' then
+ rate = 0.0
end
if not self._type then
self._type = {}
@@ -91,7 +94,7 @@ function mt:rawGetField(name, source)
return nil
end
-function mt:_getMeta(name, source)
+function mt:getMeta(name, source)
if not self._meta then
return nil
end
@@ -125,7 +128,7 @@ end
function mt:getField(name, source, stack)
local field = self:rawGetField(name, source)
if not field then
- local indexMeta = self:_getMeta('__index', source)
+ local indexMeta = self:getMeta('__index', source)
if not indexMeta then
return nil
end
@@ -143,17 +146,21 @@ end
function mt:eachField(callback)
if not self._child then
- return
+ return nil
end
local mark = {}
for _, childs in pairs(self._child) do
for name, field in pairs(childs) do
if not mark[name] then
mark[name] = true
- callback(name, field)
+ local res = callback(name, field)
+ if res ~= nil then
+ return res
+ end
end
end
end
+ return nil
end
function mt:getDeclarat()