Skip to content

Commit f95cec2

Browse files
committed
fix hover of some operators
1 parent a6e7f47 commit f95cec2

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

script/core/hover/description.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ local function tryDocEnum(source)
437437
or field.value.type == 'string' then
438438
md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1]))
439439
end
440+
if field.value.type == 'binary'
441+
or field.value.type == 'unary' then
442+
local number = vm.getNumber(field.value)
443+
if number then
444+
md:add('lua', (' %s: %s = %s,'):format(key, math.tointeger(number) and 'integer' or 'number', number))
445+
end
446+
end
440447
::CONTINUE::
441448
end
442449
end

script/vm/global.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ local compilerGlobalSwitch = util.switch()
350350
or field.value.type == 'string' then
351351
source._enums[#source._enums+1] = field.value[1]
352352
end
353+
if field.value.type == 'binary'
354+
or field.value.type == 'unary' then
355+
source._enums[#source._enums+1] = vm.getNumber(field.value)
356+
end
353357
::CONTINUE::
354358
end
355359
end

script/vm/operator.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ vm.binarySwitch = util.switch()
231231
local b = vm.getInteger(source[2])
232232
local op = source.op.type
233233
if a and b then
234-
local result = op.type == '<<' and a << b
235-
or op.type == '>>' and a >> b
236-
or op.type == '&' and a & b
237-
or op.type == '|' and a | b
238-
or op.type == '~' and a ~ b
234+
local result = op == '<<' and a << b
235+
or op == '>>' and a >> b
236+
or op == '&' and a & b
237+
or op == '|' and a | b
238+
or op == '~' and a ~ b
239239
vm.setNode(source, {
240240
type = 'integer',
241241
start = source.start,
@@ -351,10 +351,10 @@ vm.binarySwitch = util.switch()
351351
local b = vm.getNumber(source[2])
352352
if a and b then
353353
local op = source.op.type
354-
local result = op.type == '>' and a > b
355-
or op.type == '<' and a < b
356-
or op.type == '>=' and a >= b
357-
or op.type == '<=' and a <= b
354+
local result = op == '>' and a > b
355+
or op == '<' and a < b
356+
or op == '>=' and a >= b
357+
or op == '<=' and a <= b
358358
vm.setNode(source, {
359359
type = 'boolean',
360360
start = source.start,

test/crossfile/hover.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,3 +1554,31 @@ TEST {
15541554
}
15551555
```]]
15561556
}
1557+
1558+
TEST {
1559+
{
1560+
path = 'a.lua',
1561+
content = [[
1562+
---@enum <?A?>
1563+
local t = {
1564+
x = 1 << 0,
1565+
y = 1 << 1,
1566+
z = 1 << 2,
1567+
}
1568+
]]
1569+
},
1570+
hover = [[
1571+
```lua
1572+
(enum) A
1573+
```
1574+
1575+
---
1576+
1577+
```lua
1578+
{
1579+
x: integer = 1,
1580+
y: integer = 2,
1581+
z: integer = 4,
1582+
}
1583+
```]]
1584+
}

test/hover/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,3 +2130,10 @@ local m = {
21302130
[[
21312131
(enum) A
21322132
]]
2133+
2134+
TEST [[
2135+
local <?x?> = 1 << 2
2136+
]]
2137+
[[
2138+
local x: integer = 4
2139+
]]

0 commit comments

Comments
 (0)