Skip to content

Commit 484f993

Browse files
committed
completion for quoted fields
fix #2088
1 parent 2b5257d commit 484f993

File tree

5 files changed

+72
-7
lines changed

5 files changed

+72
-7
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* `FIX` [#2042]
66
* `FIX` [#2062]
77
* `FIX` [#2083]
8+
* `FIX` [#2088]
89

910
[#2038]: https://github.com/LuaLS/lua-language-server/issues/2038
1011
[#2042]: https://github.com/LuaLS/lua-language-server/issues/2042
1112
[#2062]: https://github.com/LuaLS/lua-language-server/issues/2062
1213
[#2083]: https://github.com/LuaLS/lua-language-server/issues/2083
14+
[#2088]: https://github.com/LuaLS/lua-language-server/issues/2088
1315

1416
## 3.6.21
1517
`2023-5-24`

script/core/hover/label.lua

+6-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ local function asField(source)
134134
end
135135

136136
local function asDocFieldName(source)
137-
local name = source.field[1]
137+
local name = vm.viewKey(source, guide.getUri(source)) or '?'
138138
local class
139139
for _, doc in ipairs(source.bindGroup) do
140140
if doc.type == 'doc.class' then
@@ -143,10 +143,12 @@ local function asDocFieldName(source)
143143
end
144144
end
145145
local view = vm.getInfer(source.extends):view(guide.getUri(source))
146-
if not class then
147-
return ('(field) ?.%s: %s'):format(name, view)
146+
local className = class and class.class[1] or '?'
147+
if name:match(guide.namePatternFull) then
148+
return ('(field) %s.%s: %s'):format(className, name, view)
149+
else
150+
return ('(field) %s%s: %s'):format(className, name, view)
148151
end
149-
return ('(field) %s.%s: %s'):format(class.class[1], name, view)
150152
end
151153

152154
local function asString(source)

script/vm/infer.lua

+8-3
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,12 @@ function vm.viewKey(source, uri)
565565
return vm.viewKey(source.types[1], uri)
566566
else
567567
local key = vm.getInfer(source):view(uri)
568-
return '[' .. key .. ']'
568+
return '[' .. key .. ']', key
569569
end
570570
end
571571
if source.type == 'tableindex'
572-
or source.type == 'setindex' then
572+
or source.type == 'setindex'
573+
or source.type == 'getindex' then
573574
local index = source.index
574575
local name = vm.getInfer(index):viewLiterals()
575576
if not name then
@@ -587,7 +588,11 @@ function vm.viewKey(source, uri)
587588
return vm.viewKey(source.name, uri)
588589
end
589590
if source.type == 'doc.type.name' then
590-
return '[' .. source[1] .. ']'
591+
return '[' .. source[1] .. ']', source[1]
592+
end
593+
if source.type == 'doc.type.string' then
594+
local name = util.viewString(source[1], source[2])
595+
return ('[%s]'):format(name), name
591596
end
592597
local key = vm.getKeyName(source)
593598
if key == nil then

test/completion/common.lua

+43
Original file line numberDiff line numberDiff line change
@@ -4184,3 +4184,46 @@ end
41844184
}
41854185
},
41864186
}
4187+
4188+
Cared['description'] = true
4189+
TEST [[
4190+
---@class Foo
4191+
---@field ['with quotes'] integer
4192+
---@field without_quotes integer
4193+
4194+
---@type Foo
4195+
local bar = {}
4196+
4197+
bar.<??>
4198+
]]
4199+
{
4200+
{
4201+
label = "'with quotes'",
4202+
kind = define.CompletionItemKind.Field,
4203+
textEdit = {
4204+
start = 70004,
4205+
finish = 70004,
4206+
newText = "['with quotes']"
4207+
},
4208+
additionalTextEdits = {
4209+
{
4210+
start = 70003,
4211+
finish = 70004,
4212+
newText = '',
4213+
}
4214+
},
4215+
description = [[
4216+
```lua
4217+
(field) Foo['with quotes']: integer
4218+
```]]
4219+
},
4220+
{
4221+
label = 'without_quotes',
4222+
kind = define.CompletionItemKind.Field,
4223+
description = [[
4224+
```lua
4225+
(field) Foo.without_quotes: integer
4226+
```]]
4227+
},
4228+
}
4229+
Cared['description'] = false

test/crossfile/hover.lua

+13
Original file line numberDiff line numberDiff line change
@@ -1795,3 +1795,16 @@ local x: integer = 1
17951795
17961796
comment1]]
17971797
}
1798+
1799+
TEST { {path = 'a.lua', content = [[
1800+
local t = {}
1801+
1802+
print(<?t?>['a b'])
1803+
]]},
1804+
hover = [[
1805+
```lua
1806+
local t: {
1807+
['a b']: unknown,
1808+
}
1809+
```]]
1810+
}

0 commit comments

Comments
 (0)