Skip to content

Commit e5f5d42

Browse files
committed
fix duplicate fields in table hover
1 parent 5fd1d62 commit e5f5d42

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 3.6.1
44
* `FIX` wrong diagnostics for `pcall` and `xpcall`
5+
* `FIX` duplicate fields in table hover
56

67
## 3.6.0
78
`2022-11-8`

script/core/hover/table.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,24 @@ local function getVisibleKeyMap(source, fields)
9494
local uri = guide.getUri(source)
9595
local keys = {}
9696
local map = {}
97+
local ignored = {}
9798
for _, field in ipairs(fields) do
9899
local key = vm.viewKey(field, uri)
99-
if vm.isVisible(source, field) then
100+
local rawKey = guide.getKeyName(field)
101+
if rawKey and rawKey ~= key then
102+
ignored[rawKey] = true
103+
map[rawKey] = nil
104+
end
105+
if not ignored[key]
106+
and vm.isVisible(source, field) then
100107
if key and not map[key] then
101108
map[key] = true
102-
keys[#keys+1] = key
103109
end
104110
end
105111
end
112+
for key in pairs(map) do
113+
keys[#keys+1] = key
114+
end
106115
table.sort(keys, function (a, b)
107116
if a == b then
108117
return false

script/vm/infer.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,17 @@ function vm.viewKey(source, uri)
542542
end
543543
end
544544
if source.type == 'tableindex' then
545-
local name = vm.getKeyName(source)
545+
local index = source.index
546+
local name = vm.getKeyName(index)
546547
if not name then
547548
return nil
548549
end
549-
local key = util.viewLiteral(name)
550+
local key
551+
if index.type == 'string' then
552+
key = util.viewString(name, index[2])
553+
else
554+
key = util.viewLiteral(name)
555+
end
550556
return ('[%s]'):format(key), name
551557
end
552558
if source.type == 'tableexp' then

test/hover/init.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ local <?t?> = {
17141714
local t: {
17151715
x: string = "e",
17161716
y: string = "f",
1717-
["z"]: string = "g",
1717+
['z']: string = "g",
17181718
[10]: string = "d",
17191719
[1]: string = "a",
17201720
[2]: string = "b",
@@ -2415,3 +2415,18 @@ local t: { [string]: string }[] {
24152415
foo: unknown,
24162416
}
24172417
]]
2418+
2419+
TEST [[
2420+
local t = {
2421+
['x'] = 1,
2422+
['y'] = 2,
2423+
}
2424+
2425+
print(t.x, <?t?>.y)
2426+
]]
2427+
[[
2428+
local t: {
2429+
['x']: integer = 1,
2430+
['y']: integer = 2,
2431+
}
2432+
]]

0 commit comments

Comments
 (0)