summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md4
-rw-r--r--script/parser/guide.lua28
-rw-r--r--script/vm/compiler.lua3
-rw-r--r--script/vm/infer.lua9
-rw-r--r--test/completion/common.lua25
-rw-r--r--test/definition/luadoc.lua11
6 files changed, 56 insertions, 24 deletions
diff --git a/changelog.md b/changelog.md
index e482c2fc..7a20fc9e 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 b40207ed..32f94584 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 a17cc5b2..2d7f2a69 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 00f1b014..b9dfb29a 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 b73543fb..7591617e 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -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,
+ },
+}
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index a2605bcb..ae2c8e61 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -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)