diff --git a/changelog.md b/changelog.md index e482c2fc4..7a20fc9e4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # changelog +## 3.6.4 +* `FIX` [#1698] +[#1698]: https://github.com/sumneko/lua-language-server/issues/1698 + ## 3.6.3 `2022-11-14` * `FIX` [#1684] diff --git a/script/parser/guide.lua b/script/parser/guide.lua index b40207ed7..32f94584a 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -953,26 +953,14 @@ function m.getKeyNameOfLiteral(obj) if tp == 'field' or tp == 'method' then return obj[1] - elseif tp == 'string' then - local s = obj[1] - if s then - return s - end - elseif tp == 'number' then - local n = obj[1] - if n then - return obj[1] - end - elseif tp == 'integer' then - local n = obj[1] - if n then - return obj[1] - end - elseif tp == 'boolean' then - local b = obj[1] - if b then - return b - end + elseif tp == 'string' + or tp == 'number' + or tp == 'integer' + or tp == 'boolean' + or tp == 'doc.type.integer' + or tp == 'doc.type.string' + or tp == 'doc.type.boolean' then + return obj[1] end end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index a17cc5b28..2d7f2a69c 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -991,7 +991,8 @@ local function compileLocal(source) end end local hasMarkValue - if not hasMarkDoc and source.value then + if (not hasMarkDoc and source.value) + or (source.value and source.value.type == 'table') then hasMarkValue = true if source.value.type == 'table' then vm.setNode(source, source.value) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 00f1b0148..b9dfb29a4 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -534,11 +534,11 @@ end ---@return string|number|boolean|nil function vm.viewKey(source, uri) if source.type == 'doc.type' then - if #source == 1 then - return vm.viewKey(source[1], uri) + if #source.types == 1 then + return vm.viewKey(source.types[1], uri) else local key = vm.viewObject(source, uri) - return '[' .. key .. ']', key + return '[' .. key .. ']' end end if source.type == 'tableindex' then @@ -564,6 +564,9 @@ function vm.viewKey(source, uri) if source.type == 'doc.type.field' then return vm.viewKey(source.name, uri) end + if source.type == 'doc.type.name' then + return '[' .. source[1] .. ']' + end local key = vm.getKeyName(source) if key == nil then return nil diff --git a/test/completion/common.lua b/test/completion/common.lua index b73543fb6..7591617eb 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -4030,3 +4030,28 @@ local t = { kind = define.CompletionItemKind.Function, } } + +TEST [[ +---@type table +local x = { + a = 1, + b = 2, + c = 3 +} + +x. +]] +{ + { + label = 'a', + kind = define.CompletionItemKind.Enum, + }, + { + label = 'b', + kind = define.CompletionItemKind.Enum, + }, + { + label = 'c', + kind = define.CompletionItemKind.Enum, + }, +} diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua index a2605bcb2..ae2c8e61e 100644 --- a/test/definition/luadoc.lua +++ b/test/definition/luadoc.lua @@ -963,4 +963,15 @@ local class class.has.nested.() ]] +TEST [[ +---@type table +local x = { + = 1, + b = 2, + c = 3 +} + +print(x.) +]] + config.set(nil, 'Lua.type.castNumberToInteger', true)