From 5f9d41175625b6f6f7226a3026cef133f5432bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 22 Nov 2019 17:09:10 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/core/hover/label.lua | 10 ++++++++++ server-beta/src/core/hover/name.lua | 8 ++++---- server-beta/src/core/hover/table.lua | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 server-beta/src/core/hover/table.lua (limited to 'server-beta/src/core/hover') 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 -- cgit v1.2.3