diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-01 16:59:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-01 16:59:53 +0800 |
commit | 231e4e3b2be6f815c1d6734185537f777ef32d88 (patch) | |
tree | 908d1aeb53f442802de2eedcc0e22484e52c6efa | |
parent | b9fdfac7c33478161dc17b8e41a0bd46b6f23621 (diff) | |
download | lua-language-server-231e4e3b2be6f815c1d6734185537f777ef32d88.zip |
update
-rw-r--r-- | script/core/hover/label.lua | 13 | ||||
-rw-r--r-- | script/core/hover/table.lua | 5 | ||||
-rw-r--r-- | script/parser/guide.lua | 6 | ||||
-rw-r--r-- | script/vm/compiler.lua | 2 | ||||
-rw-r--r-- | script/vm/infer.lua | 44 | ||||
-rw-r--r-- | test/hover/init.lua | 4 |
6 files changed, 40 insertions, 34 deletions
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index 30a3e833..5da04e58 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -43,14 +43,13 @@ end ---@async local function asValue(source, title) local name = buildName(source, false) or '' - local type = infer.getInfer(source):view() - local literal = infer.getInfer(source):viewLiterals() + local ifr = infer.getInfer(source) + local type = ifr:view() + local literal = ifr:viewLiterals() local cont - if not infer.getInfer(source):hasType 'string' - and not type:find('%[%]$') then - if infer.getInfer(source):hasType 'table' then - cont = buildTable(source) - end + if ifr:hasType 'table' + and not ifr:hasType 'string' then + cont = buildTable(source) end local pack = {} pack[#pack+1] = title diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua index b83f3dcb..a21910e3 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -155,17 +155,18 @@ local function getInferMap(fields, keyMap) end ---@async +---@return string? return function (source) local uri = guide.getUri(source) local maxFields = config.get(uri, 'Lua.hover.previewFields') if maxFields <= 0 then - return 'table' + return nil end local fields = vm.getFields(source) local keys, map = getKeyMap(fields) if #keys == 0 then - return '{}' + return nil end local reachMax = #keys - maxFields diff --git a/script/parser/guide.lua b/script/parser/guide.lua index f490b306..15f52585 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1182,7 +1182,7 @@ function m.isOOP(source) return false end -local baseTypeMap = { +local basicTypeMap = { ['unknown'] = true, ['any'] = true, ['true'] = true, @@ -1199,8 +1199,8 @@ local baseTypeMap = { ---@param str string ---@return boolean -function m.isBaseType(str) - return baseTypeMap[str] == true +function m.isBasicType(str) + return basicTypeMap[str] == true end return m diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 058f80ec..158fdc36 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -414,7 +414,7 @@ local function isValidCallArgNode(source, node) end if source.type == 'table' then return node.type == 'doc.type.table' - or (node.type == 'global' and node.cate == 'type' and not guide.isBaseType(node.name)) + or (node.type == 'global' and node.cate == 'type' and not guide.isBasicType(node.name)) end return false end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index cb84571b..61d76caf 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -15,12 +15,12 @@ local m = {} ---@field uri? uri local mt = {} mt.__index = mt -mt.hasNumber = false -mt.hasTable = false -mt.hasClass = false -mt.isParam = false -mt.isLocal = false -mt.hasDocFunction = false +mt._hasNumber = false +mt._hasTable = false +mt._hasClass = false +mt._isParam = false +mt._isLocal = false +mt._hasDocFunction = false m.NULL = setmetatable({}, mt) @@ -45,25 +45,25 @@ local viewNodeSwitch = util.switch() end) : case 'number' : call(function (source, infer) - infer.hasNumber = true + infer._hasNumber = true return source.type end) : case 'table' : call(function (source, infer) - infer.hasTable = true + infer._hasTable = true end) : case 'local' : call(function (source, infer) if source.parent == 'funcargs' then - infer.isParam = true + infer._isParam = true else - infer.isLocal = true + infer._isLocal = true end end) : case 'global' : call(function (source, infer) if source.cate == 'type' then - infer.hasClass = true + infer._hasClass = true return source.name end end) @@ -73,7 +73,7 @@ local viewNodeSwitch = util.switch() end) : case 'doc.type.name' : call(function (source, infer) - infer.hasClass = true + infer._hasClass = true if source.signs then local buf = {} for i, sign in ipairs(source.signs) do @@ -90,12 +90,12 @@ local viewNodeSwitch = util.switch() end) : case 'doc.type.array' : call(function (source, infer) - infer.hasClass = true + infer._hasClass = true return m.getInfer(source.node):view() .. '[]' end) : case 'doc.type.table' : call(function (source, infer) - infer.hasTable = true + infer._hasTable = true end) : case 'doc.type.string' : call(function (source, infer) @@ -103,7 +103,7 @@ local viewNodeSwitch = util.switch() end) : case 'doc.type.function' : call(function (source, infer) - infer.hasDocFunction = true + infer._hasDocFunction = true local args = {} local rets = {} local argView = '' @@ -152,16 +152,16 @@ function m.getInfer(source) end function mt:_trim() - if self.hasNumber then + if self._hasNumber then self.views['integer'] = nil end - if self.hasDocFunction then + if self._hasDocFunction then self.views['function'] = nil end - if self.hasTable and not self.hasClass then + if self._hasTable and not self._hasClass then self.views['table'] = true end - if self.hasClass then + if self._hasClass then self:_eraseAlias() end end @@ -195,6 +195,12 @@ function mt:hasType(tp) return self.views[tp] == true end +---@return boolean +function mt:hasClass() + self:_computeViews() + return self._hasClass == true +end + function mt:_computeViews() if self.views then return diff --git a/test/hover/init.lua b/test/hover/init.lua index fe8b0e3f..258654d1 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -183,7 +183,7 @@ t = { TEST [[ local <?obj?> = {} ]] -"local obj: {}" +"local obj: table" --TEST [[ --local mt = {} @@ -450,7 +450,7 @@ local any = collectgarbage() t[any] = any ]] [[ -local t: {} +local t: table ]] TEST[[ |