diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-05 17:52:03 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-05 17:52:03 +0800 |
commit | 14f38cf2671ce044dd2ee752b3d66dbbaf7b83aa (patch) | |
tree | f56f2d7c1d86557a6be502aa3118e00697b73dc1 /script-beta/core | |
parent | 51185264ab76b43571689dd717b3e685d4ff9c73 (diff) | |
download | lua-language-server-14f38cf2671ce044dd2ee752b3d66dbbaf7b83aa.zip |
更新hover
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/hover/table.lua | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua index f625d973..dba70860 100644 --- a/script-beta/core/hover/table.lua +++ b/script-beta/core/hover/table.lua @@ -3,22 +3,42 @@ local util = require 'utility' local getClass = require 'core.hover.class' local function getKey(info) - if not info.key then - return 'any' + if not info.key or #info.key <= 2 then + local source = info.source + if not source.index then + return '[any]' + end + local class = getClass(source.index) + if class then + return ('[%s]'):format(class) + end + local tp = vm.getType(source.index) + if tp then + return ('[%s]'):format(tp) + end + return '[any]' end local ktype = info.key:sub(1, 2) + local key = info.key:sub(3) if ktype == 's|' then - return info.key:sub(3) + if key:match '^[%a_][%w_]*$' then + return key + else + return ('[%s]'):format(util.viewLiteral(key)) + end end - return ('[%s]'):format(info.key:sub(3)) + return ('[%s]'):format(key) end local function getField(info) - local type = vm.getType(info.source) + local tp = vm.getType(info.source) local class = getClass(info.source) local literal = vm.getLiteral(info.source) local key = getKey(info) - return key, class or type, literal + if type(literal) == 'string' and #literal >= 50 then + literal = literal:sub(1, 47) .. '...' + end + return key, class or tp, literal end local function mergeLiteral(a, b) @@ -45,6 +65,9 @@ return function (source) classes[key] = vm.mergeTypeViews(class, classes[key]) literals[key] = mergeLiteral(literal, literals[key]) end) + if classes['[any]'] == 'any' then + classes['[any]'] = nil + end if not next(classes) then return '{}' end |