Skip to content

Commit

Permalink
fix #1698
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Nov 15, 2022
1 parent 51ee592 commit 6f0e8df
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 24 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
28 changes: 8 additions & 20 deletions script/parser/guide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions script/vm/infer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/completion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4030,3 +4030,28 @@ local t = {
kind = define.CompletionItemKind.Function,
}
}

TEST [[
---@type table<string, integer>
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,
},
}
11 changes: 11 additions & 0 deletions test/definition/luadoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -963,4 +963,15 @@ local class
class.has.nested.<?fn?>()
]]

TEST [[
---@type table<string, integer>
local x = {
<!a!> = 1,
b = 2,
c = 3
}
print(x.<?a?>)
]]

config.set(nil, 'Lua.type.castNumberToInteger', true)

0 comments on commit 6f0e8df

Please sign in to comment.