Skip to content

Commit 12b0877

Browse files
committed
fix #1061
1 parent fa518d4 commit 12b0877

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* `CHG` hover: added parentheses to some words, such as `global` / `field` / `class`.
77
* `FIX` definition of `table<k, v>`
88
* `FIX` [#1057](https://github.com/sumneko/lua-language-server/issues/1057)
9+
* `FIX` [#1061](https://github.com/sumneko/lua-language-server/issues/1061)
910
* `FIX` runtime errors reported by telemetry, see [#1058](https://github.com/sumneko/lua-language-server/issues/1058)
1011

1112
## 3.0.2

script/core/completion/completion.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,10 @@ local function checkTypingEnum(state, position, defs, str, results)
11211121
local enums = {}
11221122
for _, def in ipairs(defs) do
11231123
if def.type == 'doc.type.string'
1124-
or def.type == 'doc.type.integer' then
1124+
or def.type == 'doc.type.integer'
1125+
or def.type == 'doc.type.boolean' then
11251126
enums[#enums+1] = {
1126-
label = util.viewLiteral(def[1]),
1127+
label = infer.viewObject(def),
11271128
description = def.comment and def.comment.text,
11281129
kind = define.CompletionItemKind.EnumMember,
11291130
}
@@ -1412,7 +1413,7 @@ local function tryCallArg(state, position, results)
14121413
or src.type == 'doc.type.integer'
14131414
or src.type == 'doc.type.boolean' then
14141415
enums[#enums+1] = {
1415-
label = util.viewLiteral(src[1]),
1416+
label = infer.viewObject(src),
14161417
description = src.comment,
14171418
kind = define.CompletionItemKind.EnumMember,
14181419
}

script/core/hover/description.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ local function buildEnumChunk(docType, name)
171171
end
172172
lines[#lines+1] = ('%s:'):format(name)
173173
for _, enum in ipairs(enums) do
174-
local enumDes = (' %s %q'):format(
174+
local enumDes = (' %s %s'):format(
175175
(enum.default and '->')
176176
or (enum.additional and '+>')
177177
or ' |',
178-
enum[1]
178+
infer.viewObject(enum)
179179
)
180180
if enum.comment then
181181
local first = true

script/parser/luadoc.lua

+3
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,12 @@ local function parseString(parent)
558558
end
559559

560560
nextToken()
561+
local mark = getMark()
561562
-- compatibility
562563
if content:sub(1, 1) == '"'
563564
or content:sub(1, 1) == "'" then
564565
if content:sub(1, 1) == content:sub(-1, -1) then
566+
mark = content:sub(1, 1)
565567
content = content:sub(2, -2)
566568
end
567569
end
@@ -571,6 +573,7 @@ local function parseString(parent)
571573
finish = getFinish(),
572574
parent = parent,
573575
[1] = content,
576+
[2] = mark,
574577
}
575578
return str
576579
end

script/vm/infer.lua

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ local viewNodeSwitch = util.switch()
128128
infer._hasTable = true
129129
end)
130130
: case 'doc.type.string'
131+
: call(function (source, infer)
132+
return util.viewString(source[1], source[2])
133+
end)
131134
: case 'doc.type.integer'
132135
: case 'doc.type.boolean'
133136
: call(function (source, infer)

test/crossfile/hover.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -976,16 +976,16 @@ end
976976
},
977977
hover = [[
978978
```lua
979-
function f(p: "a"|"b")
979+
function f(p: 'a'|'b')
980980
```
981981
982982
---
983983
984984
```lua
985985
p:
986-
| "a" -- comment 1
986+
| 'a' -- comment 1
987987
-- comment 2
988-
| "b" -- comment 3
988+
| 'b' -- comment 3
989989
-- comment 4
990990
```]]}
991991

test/hover/init.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ TEST [[
13971397
local <?t?>
13981398
]]
13991399
[[
1400-
local t: string|"enum1"|"enum2"
1400+
local t: string|'enum1'|'enum2'
14011401
]]
14021402

14031403
TEST [[
@@ -1406,7 +1406,7 @@ TEST [[
14061406
---@type <?A?>
14071407
]]
14081408
[[
1409-
(alias) A 展开为 string|"enum1"|"enum2"
1409+
(alias) A 展开为 string|'enum1'|'enum2'
14101410
]]
14111411

14121412
TEST [[
@@ -1416,7 +1416,7 @@ TEST [[
14161416
local <?t?>
14171417
]]
14181418
[[
1419-
local t: string|"enum1"|"enum2"
1419+
local t: string|'enum1'|'enum2'
14201420
]]
14211421

14221422
TEST [[
@@ -1426,7 +1426,7 @@ TEST [[
14261426
local <?t?>
14271427
]]
14281428
[[
1429-
local t: string|"enum1"|"enum2"
1429+
local t: string|'enum1'|'enum2'
14301430
]]
14311431

14321432
TEST [[

test/type_inference/init.lua

+9-9
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,13 @@ TEST 'string|table' [[
418418
local <?x?>
419419
]]
420420

421-
TEST '"enum1"|"enum2"' [[
421+
TEST [['enum1'|'enum2']] [[
422422
---@type 'enum1' | 'enum2'
423423
local <?x?>
424424
]]
425425

426-
TEST '"enum1"|"enum2"' [[
427-
---@type 'enum1' | 'enum2'
426+
TEST [["enum1"|"enum2"]] [[
427+
---@type "enum1" | "enum2"
428428
local <?x?>
429429
]]
430430

@@ -450,21 +450,21 @@ TEST 'A' [[
450450
local <?x?>
451451
]]
452452
config.set(nil, 'Lua.hover.expandAlias', true)
453-
TEST '"enum1"|"enum2"' [[
453+
TEST [['enum1'|'enum2']] [[
454454
---@alias A 'enum1' | 'enum2'
455455
456456
---@type A
457457
local <?x?>
458458
]]
459459

460-
TEST '"enum1"|"enum2"' [[
460+
TEST [['enum1'|'enum2']] [[
461461
---@alias A 'enum1' | 'enum2' | A
462462
463463
---@type A
464464
local <?x?>
465465
]]
466466

467-
TEST '"enum1"|"enum2"|B' [[
467+
TEST [['enum1'|'enum2'|B]] [[
468468
---@alias A 'enum1' | 'enum2' | B
469469
470470
---@type A
@@ -544,7 +544,7 @@ local t = {}
544544
print(t.<?a?>)
545545
]]
546546

547-
TEST '"aaa"|"bbb"' [[
547+
TEST [['aaa'|'bbb']] [[
548548
---@type table<string, 'aaa'|'bbb'>
549549
local t = {}
550550
@@ -992,13 +992,13 @@ string.gsub():gsub():<?gsub?>()
992992
]]
993993

994994
config.set(nil, 'Lua.hover.enumsLimit', 5)
995-
TEST '"a"|"b"|"c"|"d"|"e"...(+5)' [[
995+
TEST [['a'|'b'|'c'|'d'|'e'...(+5)]] [[
996996
---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'
997997
local <?t?>
998998
]]
999999

10001000
config.set(nil, 'Lua.hover.enumsLimit', 1)
1001-
TEST '"a"...(+9)' [[
1001+
TEST [['a'...(+9)]] [[
10021002
---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'
10031003
local <?t?>
10041004
]]

0 commit comments

Comments
 (0)