Skip to content

Commit

Permalink
fix #1061
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Apr 16, 2022
1 parent fa518d4 commit 12b0877
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions script/core/hover/description.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions script/parser/luadoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -571,6 +573,7 @@ local function parseString(parent)
finish = getFinish(),
parent = parent,
[1] = content,
[2] = mark,
}
return str
end
Expand Down
3 changes: 3 additions & 0 deletions script/vm/infer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/crossfile/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
```]]}

Expand Down
8 changes: 4 additions & 4 deletions test/hover/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ TEST [[
local <?t?>
]]
[[
local t: string|"enum1"|"enum2"
local t: string|'enum1'|'enum2'
]]

TEST [[
Expand All @@ -1406,7 +1406,7 @@ TEST [[
---@type <?A?>
]]
[[
(alias) A 展开为 string|"enum1"|"enum2"
(alias) A 展开为 string|'enum1'|'enum2'
]]

TEST [[
Expand All @@ -1416,7 +1416,7 @@ TEST [[
local <?t?>
]]
[[
local t: string|"enum1"|"enum2"
local t: string|'enum1'|'enum2'
]]

TEST [[
Expand All @@ -1426,7 +1426,7 @@ TEST [[
local <?t?>
]]
[[
local t: string|"enum1"|"enum2"
local t: string|'enum1'|'enum2'
]]

TEST [[
Expand Down
18 changes: 9 additions & 9 deletions test/type_inference/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?>
]]

Expand All @@ -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
Expand Down Expand Up @@ -544,7 +544,7 @@ local t = {}
print(t.<?a?>)
]]

TEST '"aaa"|"bbb"' [[
TEST [['aaa'|'bbb']] [[
---@type table<string, 'aaa'|'bbb'>
local t = {}
Expand Down Expand Up @@ -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?>
]]
Expand Down

0 comments on commit 12b0877

Please sign in to comment.