diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-28 20:35:19 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-28 20:35:19 +0800 |
commit | a64957132d5c9ecf6c66003ff028d68772d1aa1f (patch) | |
tree | 2df5dee56cd1166b1c87c9f62ad3e268dafe48d6 /script-beta/core | |
parent | 1038520109da932c2e648da6ffa9bf25d36944b8 (diff) | |
download | lua-language-server-a64957132d5c9ecf6c66003ff028d68772d1aa1f.zip |
hover 显示 table
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/hover/class.lua | 9 | ||||
-rw-r--r-- | script-beta/core/hover/name.lua | 2 | ||||
-rw-r--r-- | script-beta/core/hover/table.lua | 48 |
3 files changed, 41 insertions, 18 deletions
diff --git a/script-beta/core/hover/class.lua b/script-beta/core/hover/class.lua index 6d28ee8a..be7b3995 100644 --- a/script-beta/core/hover/class.lua +++ b/script-beta/core/hover/class.lua @@ -5,7 +5,14 @@ local function getClass(source, deep) return nil end local class = vm.eachField(source, function (info) - if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then + if not info.key then + return + end + local lkey = info.key:lower() + if lkey == 's|type' + or lkey == 's|__name' + or lkey == 's|name' + or lkey == 's|class' then if info.value and info.value.type == 'string' then return info.value[1] end diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua index 0d5f65ad..b96a8169 100644 --- a/script-beta/core/hover/name.lua +++ b/script-beta/core/hover/name.lua @@ -42,7 +42,7 @@ local function buildName(source) return asMethod(source) or '' end if source.type == 'setfield' - or source.tyoe == 'getfield' then + or source.type == 'getfield' then return asField(source) or '' end if source.type == 'tablefield' then diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua index 9ed86692..9292d183 100644 --- a/script-beta/core/hover/table.lua +++ b/script-beta/core/hover/table.lua @@ -1,35 +1,51 @@ -local vm = require 'vm' +local vm = require 'vm' +local util = require 'utility' +local getClass = require 'core.hover.class' -local function checkClass(source) +local function getKey(info) + local ktype = info.key:sub(1, 2) + if ktype == 's|' then + return info.key:sub(3) + end + return ('[%s]'):format(info.key:sub(3)) +end + +local function getField(info) + local type = vm.getType(info.source) + local class = getClass(info.source) + local literal = vm.getLiteral(info.source) + local key = getKey(info) + local label + if literal then + label = ('%s: %s = %s'):format(key, class or type, util.viewLiteral(literal)) + else + label = ('%s: %s'):format(key, class or type) + end + return label, key end return function (source) local fields = {} - local class + local keys = {} 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) + local field, key = getField(info) + fields[#fields+1] = field + keys[field] = key end) local fieldsBuf if #fields == 0 then fieldsBuf = '{}' else + table.sort(fields, function (a, b) + return keys[a] < keys[b] + end) local lines = {} lines[#lines+1] = '{' for _, field in ipairs(fields) do - lines[#lines+1] = ' ' .. field + 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 + return fieldsBuf end |