diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 7 | ||||
-rw-r--r-- | script/core/hover/description.lua | 4 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 3 | ||||
-rw-r--r-- | script/vm/infer.lua | 3 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 6 | ||||
-rw-r--r-- | test/hover/init.lua | 8 | ||||
-rw-r--r-- | test/type_inference/init.lua | 18 |
8 files changed, 29 insertions, 21 deletions
diff --git a/changelog.md b/changelog.md index 772be9e4..97575790 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ * `CHG` hover: added parentheses to some words, such as `global` / `field` / `class`. * `FIX` definition of `table<k, v>` * `FIX` [#1057](https://github.com/sumneko/lua-language-server/issues/1057) +* `FIX` [#1061](https://github.com/sumneko/lua-language-server/issues/1061) * `FIX` runtime errors reported by telemetry, see [#1058](https://github.com/sumneko/lua-language-server/issues/1058) ## 3.0.2 diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index c257643d..beff594c 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1121,9 +1121,10 @@ local function checkTypingEnum(state, position, defs, str, results) local enums = {} for _, def in ipairs(defs) do if def.type == 'doc.type.string' - or def.type == 'doc.type.integer' then + or def.type == 'doc.type.integer' + or def.type == 'doc.type.boolean' then enums[#enums+1] = { - label = util.viewLiteral(def[1]), + label = infer.viewObject(def), description = def.comment and def.comment.text, kind = define.CompletionItemKind.EnumMember, } @@ -1412,7 +1413,7 @@ local function tryCallArg(state, position, results) or src.type == 'doc.type.integer' or src.type == 'doc.type.boolean' then enums[#enums+1] = { - label = util.viewLiteral(src[1]), + label = infer.viewObject(src), description = src.comment, kind = define.CompletionItemKind.EnumMember, } diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 5d350cf7..03f6128a 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -171,11 +171,11 @@ local function buildEnumChunk(docType, name) end lines[#lines+1] = ('%s:'):format(name) for _, enum in ipairs(enums) do - local enumDes = (' %s %q'):format( + local enumDes = (' %s %s'):format( (enum.default and '->') or (enum.additional and '+>') or ' |', - enum[1] + infer.viewObject(enum) ) if enum.comment then local first = true diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index b46c81d9..5a2e1d09 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -558,10 +558,12 @@ local function parseString(parent) end nextToken() + local mark = getMark() -- compatibility if content:sub(1, 1) == '"' or content:sub(1, 1) == "'" then if content:sub(1, 1) == content:sub(-1, -1) then + mark = content:sub(1, 1) content = content:sub(2, -2) end end @@ -571,6 +573,7 @@ local function parseString(parent) finish = getFinish(), parent = parent, [1] = content, + [2] = mark, } return str end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index a47783f7..2a64ed52 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -128,6 +128,9 @@ local viewNodeSwitch = util.switch() infer._hasTable = true end) : case 'doc.type.string' + : call(function (source, infer) + return util.viewString(source[1], source[2]) + end) : case 'doc.type.integer' : case 'doc.type.boolean' : call(function (source, infer) diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index b0b66253..09eceb43 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -976,16 +976,16 @@ end }, hover = [[ ```lua -function f(p: "a"|"b") +function f(p: 'a'|'b') ``` --- ```lua p: - | "a" -- comment 1 + | 'a' -- comment 1 -- comment 2 - | "b" -- comment 3 + | 'b' -- comment 3 -- comment 4 ```]]} diff --git a/test/hover/init.lua b/test/hover/init.lua index f347cd99..ee66ef2b 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1397,7 +1397,7 @@ TEST [[ local <?t?> ]] [[ -local t: string|"enum1"|"enum2" +local t: string|'enum1'|'enum2' ]] TEST [[ @@ -1406,7 +1406,7 @@ TEST [[ ---@type <?A?> ]] [[ -(alias) A 展开为 string|"enum1"|"enum2" +(alias) A 展开为 string|'enum1'|'enum2' ]] TEST [[ @@ -1416,7 +1416,7 @@ TEST [[ local <?t?> ]] [[ -local t: string|"enum1"|"enum2" +local t: string|'enum1'|'enum2' ]] TEST [[ @@ -1426,7 +1426,7 @@ TEST [[ local <?t?> ]] [[ -local t: string|"enum1"|"enum2" +local t: string|'enum1'|'enum2' ]] TEST [[ diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index df45dd9d..9ead2861 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -418,13 +418,13 @@ TEST 'string|table' [[ local <?x?> ]] -TEST '"enum1"|"enum2"' [[ +TEST [['enum1'|'enum2']] [[ ---@type 'enum1' | 'enum2' local <?x?> ]] -TEST '"enum1"|"enum2"' [[ ----@type 'enum1' | 'enum2' +TEST [["enum1"|"enum2"]] [[ +---@type "enum1" | "enum2" local <?x?> ]] @@ -450,21 +450,21 @@ TEST 'A' [[ local <?x?> ]] config.set(nil, 'Lua.hover.expandAlias', true) -TEST '"enum1"|"enum2"' [[ +TEST [['enum1'|'enum2']] [[ ---@alias A 'enum1' | 'enum2' ---@type A local <?x?> ]] -TEST '"enum1"|"enum2"' [[ +TEST [['enum1'|'enum2']] [[ ---@alias A 'enum1' | 'enum2' | A ---@type A local <?x?> ]] -TEST '"enum1"|"enum2"|B' [[ +TEST [['enum1'|'enum2'|B]] [[ ---@alias A 'enum1' | 'enum2' | B ---@type A @@ -544,7 +544,7 @@ local t = {} print(t.<?a?>) ]] -TEST '"aaa"|"bbb"' [[ +TEST [['aaa'|'bbb']] [[ ---@type table<string, 'aaa'|'bbb'> local t = {} @@ -992,13 +992,13 @@ string.gsub():gsub():<?gsub?>() ]] config.set(nil, 'Lua.hover.enumsLimit', 5) -TEST '"a"|"b"|"c"|"d"|"e"...(+5)' [[ +TEST [['a'|'b'|'c'|'d'|'e'...(+5)]] [[ ---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j' local <?t?> ]] config.set(nil, 'Lua.hover.enumsLimit', 1) -TEST '"a"...(+9)' [[ +TEST [['a'...(+9)]] [[ ---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j' local <?t?> ]] |