diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/core/hover/label.lua | 10 | ||||
-rw-r--r-- | script/vm/infer.lua | 11 | ||||
-rw-r--r-- | test/completion/common.lua | 43 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 13 |
5 files changed, 72 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md index 2b570ab5..cf7fad9a 100644 --- a/changelog.md +++ b/changelog.md @@ -5,11 +5,13 @@ * `FIX` [#2042] * `FIX` [#2062] * `FIX` [#2083] +* `FIX` [#2088] [#2038]: https://github.com/LuaLS/lua-language-server/issues/2038 [#2042]: https://github.com/LuaLS/lua-language-server/issues/2042 [#2062]: https://github.com/LuaLS/lua-language-server/issues/2062 [#2083]: https://github.com/LuaLS/lua-language-server/issues/2083 +[#2088]: https://github.com/LuaLS/lua-language-server/issues/2088 ## 3.6.21 `2023-5-24` diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index 6ce4dde9..62e51927 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -134,7 +134,7 @@ local function asField(source) end local function asDocFieldName(source) - local name = source.field[1] + local name = vm.viewKey(source, guide.getUri(source)) or '?' local class for _, doc in ipairs(source.bindGroup) do if doc.type == 'doc.class' then @@ -143,10 +143,12 @@ local function asDocFieldName(source) end end local view = vm.getInfer(source.extends):view(guide.getUri(source)) - if not class then - return ('(field) ?.%s: %s'):format(name, view) + local className = class and class.class[1] or '?' + if name:match(guide.namePatternFull) then + return ('(field) %s.%s: %s'):format(className, name, view) + else + return ('(field) %s%s: %s'):format(className, name, view) end - return ('(field) %s.%s: %s'):format(class.class[1], name, view) end local function asString(source) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 94fdfd88..3bc0b3f7 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -565,11 +565,12 @@ function vm.viewKey(source, uri) return vm.viewKey(source.types[1], uri) else local key = vm.getInfer(source):view(uri) - return '[' .. key .. ']' + return '[' .. key .. ']', key end end if source.type == 'tableindex' - or source.type == 'setindex' then + or source.type == 'setindex' + or source.type == 'getindex' then local index = source.index local name = vm.getInfer(index):viewLiterals() if not name then @@ -587,7 +588,11 @@ function vm.viewKey(source, uri) return vm.viewKey(source.name, uri) end if source.type == 'doc.type.name' then - return '[' .. source[1] .. ']' + return '[' .. source[1] .. ']', source[1] + end + if source.type == 'doc.type.string' then + local name = util.viewString(source[1], source[2]) + return ('[%s]'):format(name), name end local key = vm.getKeyName(source) if key == nil then diff --git a/test/completion/common.lua b/test/completion/common.lua index 8d53b89a..d38f2912 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -4184,3 +4184,46 @@ end } }, } + +Cared['description'] = true +TEST [[ +---@class Foo +---@field ['with quotes'] integer +---@field without_quotes integer + +---@type Foo +local bar = {} + +bar.<??> +]] +{ + { + label = "'with quotes'", + kind = define.CompletionItemKind.Field, + textEdit = { + start = 70004, + finish = 70004, + newText = "['with quotes']" + }, + additionalTextEdits = { + { + start = 70003, + finish = 70004, + newText = '', + } + }, + description = [[ +```lua +(field) Foo['with quotes']: integer +```]] + }, + { + label = 'without_quotes', + kind = define.CompletionItemKind.Field, + description = [[ +```lua +(field) Foo.without_quotes: integer +```]] + }, +} +Cared['description'] = false diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index d013af98..aee9ea0a 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -1795,3 +1795,16 @@ local x: integer = 1 comment1]] } + +TEST { {path = 'a.lua', content = [[ +local t = {} + +print(<?t?>['a b']) +]]}, +hover = [[ +```lua +local t: { + ['a b']: unknown, +} +```]] +} |