summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/hover/description.lua7
-rw-r--r--script/vm/global.lua4
-rw-r--r--script/vm/operator.lua18
-rw-r--r--test/crossfile/hover.lua28
-rw-r--r--test/hover/init.lua7
5 files changed, 55 insertions, 9 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 2097e0a3..e11dd6c8 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -437,6 +437,13 @@ local function tryDocEnum(source)
or field.value.type == 'string' then
md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1]))
end
+ if field.value.type == 'binary'
+ or field.value.type == 'unary' then
+ local number = vm.getNumber(field.value)
+ if number then
+ md:add('lua', (' %s: %s = %s,'):format(key, math.tointeger(number) and 'integer' or 'number', number))
+ end
+ end
::CONTINUE::
end
end
diff --git a/script/vm/global.lua b/script/vm/global.lua
index c9bb4cc7..22235681 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -350,6 +350,10 @@ local compilerGlobalSwitch = util.switch()
or field.value.type == 'string' then
source._enums[#source._enums+1] = field.value[1]
end
+ if field.value.type == 'binary'
+ or field.value.type == 'unary' then
+ source._enums[#source._enums+1] = vm.getNumber(field.value)
+ end
::CONTINUE::
end
end
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index de2c3243..9dea01c1 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -231,11 +231,11 @@ vm.binarySwitch = util.switch()
local b = vm.getInteger(source[2])
local op = source.op.type
if a and b then
- local result = op.type == '<<' and a << b
- or op.type == '>>' and a >> b
- or op.type == '&' and a & b
- or op.type == '|' and a | b
- or op.type == '~' and a ~ b
+ local result = op == '<<' and a << b
+ or op == '>>' and a >> b
+ or op == '&' and a & b
+ or op == '|' and a | b
+ or op == '~' and a ~ b
vm.setNode(source, {
type = 'integer',
start = source.start,
@@ -351,10 +351,10 @@ vm.binarySwitch = util.switch()
local b = vm.getNumber(source[2])
if a and b then
local op = source.op.type
- local result = op.type == '>' and a > b
- or op.type == '<' and a < b
- or op.type == '>=' and a >= b
- or op.type == '<=' and a <= b
+ local result = op == '>' and a > b
+ or op == '<' and a < b
+ or op == '>=' and a >= b
+ or op == '<=' and a <= b
vm.setNode(source, {
type = 'boolean',
start = source.start,
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index e8a718d4..e6517aa9 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -1554,3 +1554,31 @@ TEST {
}
```]]
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+ ---@enum <?A?>
+ local t = {
+ x = 1 << 0,
+ y = 1 << 1,
+ z = 1 << 2,
+ }
+ ]]
+ },
+ hover = [[
+```lua
+(enum) A
+```
+
+---
+
+```lua
+{
+ x: integer = 1,
+ y: integer = 2,
+ z: integer = 4,
+}
+```]]
+}
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 95764923..40474bf5 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -2130,3 +2130,10 @@ local m = {
[[
(enum) A
]]
+
+TEST [[
+local <?x?> = 1 << 2
+]]
+[[
+local x: integer = 4
+]]