diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 17:09:10 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 17:09:10 +0800 |
commit | 5f9d41175625b6f6f7226a3026cef133f5432bc8 (patch) | |
tree | 0065b136852787d9d03ac4114474c27bc18327d5 /server-beta/src/core/hover | |
parent | 2ed44f3cf2fa90f829b582d54c0b4d3abf692ff9 (diff) | |
download | lua-language-server-5f9d41175625b6f6f7226a3026cef133f5432bc8.zip |
暂存
Diffstat (limited to 'server-beta/src/core/hover')
-rw-r--r-- | server-beta/src/core/hover/label.lua | 10 | ||||
-rw-r--r-- | server-beta/src/core/hover/name.lua | 8 | ||||
-rw-r--r-- | server-beta/src/core/hover/table.lua | 35 |
3 files changed, 49 insertions, 4 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 |