summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-04 17:51:48 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-04 17:51:48 +0800
commit167a17c541a08b3dc5b3588dbb617d2ebf61f343 (patch)
tree0baa2ce8cf2b92b2512c6c0e6217d0f55747ba39
parentc83d18a6d66162a08d86955f4ceac886cb105e6d (diff)
downloadlua-language-server-167a17c541a08b3dc5b3588dbb617d2ebf61f343.zip
fix #1479
-rw-r--r--changelog.md2
-rw-r--r--script/vm/compiler.lua7
-rw-r--r--test/type_inference/init.lua14
3 files changed, 23 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index 912fd5a6..b248b6f4 100644
--- a/changelog.md
+++ b/changelog.md
@@ -114,6 +114,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
}
```
* `CHG` [#1533] supports completion with table field of function
+* `FIX` [#1479]
* `FIX` [#1480]
* `FIX` [#1567]
* `FIX` [#1593]
@@ -132,6 +133,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
[#1332]: https://github.com/sumneko/lua-language-server/issues/1332
[#1344]: https://github.com/sumneko/lua-language-server/issues/1344
[#1458]: https://github.com/sumneko/lua-language-server/issues/1458
+[#1479]: https://github.com/sumneko/lua-language-server/issues/1479
[#1480]: https://github.com/sumneko/lua-language-server/issues/1480
[#1484]: https://github.com/sumneko/lua-language-server/issues/1484
[#1533]: https://github.com/sumneko/lua-language-server/issues/1533
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index b21cccea..826c3742 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -224,6 +224,13 @@ local searchFieldSwitch = util.switch()
or (fn.name == 'string' and type(key) == 'string') then
pushResult(field)
end
+ elseif fn.type == 'doc.type.string'
+ or fn.type == 'doc.type.integer'
+ or fn.type == 'doc.type.boolean' then
+ if key == nil
+ or fn[1] == key then
+ pushResult(field)
+ end
end
end
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 6ad98e97..9af0d28c 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -3917,3 +3917,17 @@ local A
local <?o?> = A()
]]
+
+TEST 'number' [[
+---@type table<'Test1', fun(x: number)>
+local t = {
+ ["Test1"] = function(<?x?>) end,
+}
+]]
+
+TEST 'number' [[
+---@type table<5, fun(x: number)>
+local t = {
+ [5] = function(<?x?>) end,
+}
+]]