summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-22 17:09:10 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-22 17:09:10 +0800
commit5f9d41175625b6f6f7226a3026cef133f5432bc8 (patch)
tree0065b136852787d9d03ac4114474c27bc18327d5
parent2ed44f3cf2fa90f829b582d54c0b4d3abf692ff9 (diff)
downloadlua-language-server-5f9d41175625b6f6f7226a3026cef133f5432bc8.zip
暂存
-rw-r--r--server-beta/src/core/hover/label.lua10
-rw-r--r--server-beta/src/core/hover/name.lua8
-rw-r--r--server-beta/src/core/hover/table.lua35
-rw-r--r--server-beta/test/hover/init.lua9
4 files changed, 56 insertions, 6 deletions
diff --git a/server-beta/src/core/hover/label.lua b/server-beta/src/core/hover/label.lua
index d90a19b0..72ce60f4 100644
--- a/server-beta/src/core/hover/label.lua
+++ b/server-beta/src/core/hover/label.lua
@@ -1,6 +1,7 @@
local buildName = require 'core.hover.name'
local buildArg = require 'core.hover.arg'
local buildReturn = require 'core.hover.return'
+local buildTable = require 'core.hover.table'
local vm = require 'vm'
local util = require 'utility'
@@ -18,6 +19,9 @@ local function asLocal(source)
local name = buildName(source)
local type = vm.getType(source)
local literal = vm.getLiteral(source)
+ if type == 'table' then
+ type = buildTable(source)
+ end
if literal == nil then
return ('local %s: %s'):format(name, type)
else
@@ -29,6 +33,9 @@ local function asGlobal(source)
local name = buildName(source)
local type = vm.getType(source)
local literal = vm.getLiteral(source)
+ if type == 'table' then
+ type = buildTable(source)
+ end
if literal == nil then
return ('global %s: %s'):format(name, type)
else
@@ -64,6 +71,9 @@ local function asField(source)
local name = buildName(source)
local type = vm.getType(source)
local literal = vm.getLiteral(source)
+ if type == 'table' then
+ type = buildTable(source)
+ end
if literal == nil then
return ('field %s: %s'):format(name, type)
else
diff --git a/server-beta/src/core/hover/name.lua b/server-beta/src/core/hover/name.lua
index 468691a7..a22a8b5a 100644
--- a/server-beta/src/core/hover/name.lua
+++ b/server-beta/src/core/hover/name.lua
@@ -7,26 +7,26 @@ end
local function asMethod(source)
local class = vm.eachField(source.node, function (info)
- if info.key == 's|type' or info.key == 's|__name' then
+ if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then
if info.value and info.value.type == 'string' then
return info.value[1]
end
end
end)
- local node = class or guide.getName(source.node) or '*'
+ local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
return ('%s:%s'):format(node, method)
end
local function asField(source)
local class = vm.eachField(source.node, function (info)
- if info.key == 's|type' or info.key == 's|__name' then
+ if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then
if info.value and info.value.type == 'string' then
return info.value[1]
end
end
end)
- local node = class or guide.getName(source.node) or '*'
+ local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
return ('%s.%s'):format(node, method)
end
diff --git a/server-beta/src/core/hover/table.lua b/server-beta/src/core/hover/table.lua
new file mode 100644
index 00000000..9ed86692
--- /dev/null
+++ b/server-beta/src/core/hover/table.lua
@@ -0,0 +1,35 @@
+local vm = require 'vm'
+
+local function checkClass(source)
+end
+
+return function (source)
+ local fields = {}
+ local class
+ vm.eachField(source, function (info)
+ if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then
+ if info.value and info.value.type == 'string' then
+ class = info.value[1]
+ end
+ end
+ local type = vm.getType(info.source)
+ fields[#fields+1] = ('%s'):format(type)
+ end)
+ local fieldsBuf
+ if #fields == 0 then
+ fieldsBuf = '{}'
+ else
+ local lines = {}
+ lines[#lines+1] = '{'
+ for _, field in ipairs(fields) do
+ lines[#lines+1] = ' ' .. field
+ end
+ lines[#lines+1] = '}'
+ fieldsBuf = table.concat(lines, '\n')
+ end
+ if class then
+ return ('%s %s'):format(class, fieldsBuf)
+ else
+ return fieldsBuf
+ end
+end
diff --git a/server-beta/test/hover/init.lua b/server-beta/test/hover/init.lua
index 458adc8c..6a1c275b 100644
--- a/server-beta/test/hover/init.lua
+++ b/server-beta/test/hover/init.lua
@@ -156,12 +156,17 @@ t.<?x?> = 1
"global t.x: integer = 1"
TEST [[
+local <?obj?> = {}
+]]
+"local obj: {}"
+
+TEST [[
local mt = {}
mt.__name = 'class'
local <?obj?> = setmetatable({}, mt)
]]
-"local obj: *class {}"
+"local obj: class {}"
TEST [[
local mt = {}
@@ -171,7 +176,7 @@ mt.__index = mt
local <?obj?> = setmetatable({}, mt)
]]
[[
-local obj: *class {
+local obj: class {
__index: table,
name: string = "class",
}