-
-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Option for hexadecimals to not be displayed as decimals on mouseover #3059
Comments
string literals can be displayed according to their defined quotesFor string literals, currently luals is capable to distinguish between different quote styles local s1 = 's1'
-- hover: local s1: string = 's1'
local s2 = "s2"
-- hover: local s2: string = "s2"
local s3 = [[s3]]
-- hover: local s3: string = [[s3]]
borrowing this idea for viewing integer?By applying the same method, I think we can:
function m.viewInteger(int, mode)
if mode == 'x' then
-- view as hex integer
return ('0x%x'):format(int)
end
return tostring(int)
end
the POC patchHere is a POC patch file you might want to try, you may work from here and PR it after testing 😄 click to expandFrom c0359b7cfb6b147c5c60e1c97c211cc3bf335ed3 Mon Sep 17 00:00:00 2001
From: Tom Lau <tomandfatboy@gmail.com>
Date: Thu, 6 Feb 2025 12:10:24 +0800
Subject: [PATCH] poc: hex integer hover
---
script/parser/compile.lua | 4 +++-
script/utility.lua | 8 ++++++++
script/vm/infer.lua | 2 ++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/script/parser/compile.lua b/script/parser/compile.lua
index 41b0da17..333bc4e0 100644
--- a/script/parser/compile.lua
+++ b/script/parser/compile.lua
@@ -1353,7 +1353,7 @@ local function parseNumber()
neg = true
offset = offset + 1
end
- local number, integer
+ local number, integer, mode
local firstChar = ssub(Lua, offset, offset)
if firstChar == '.' then
number, offset = parseNumber10(offset)
@@ -1362,6 +1362,7 @@ local function parseNumber()
local nextChar = ssub(Lua, offset + 1, offset + 1)
if CharMapN16[nextChar] then
number, offset, integer = parseNumber16(offset + 2)
+ mode = 'x'
elseif CharMapN2[nextChar] then
number, offset = parseNumber2(offset + 2)
integer = true
@@ -1384,6 +1385,7 @@ local function parseNumber()
start = startPos,
finish = getPosition(offset - 1, 'right'),
[1] = number,
+ [2] = integer and mode or nil,
}
offset = dropNumberTail(offset, integer)
fastForwardToken(offset)
diff --git a/script/utility.lua b/script/utility.lua
index 7a1fd0ff..ba33b4a5 100644
--- a/script/utility.lua
+++ b/script/utility.lua
@@ -504,6 +504,14 @@ function m.viewString(str, quo)
end
end
+function m.viewInteger(int, mode)
+ if mode == 'x' then
+ -- view as hex integer
+ return ('0x%x'):format(int)
+ end
+ return tostring(int)
+end
+
function m.viewLiteral(v)
local tp = type(v)
if tp == 'nil' then
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index 6f21a76a..200d5059 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -510,6 +510,8 @@ function mt:viewLiterals()
local literal
if n.type == 'string' then
literal = util.viewString(n[1], n[2])
+ elseif n.type == 'integer' then
+ literal = util.viewInteger(n[1], n[2])
else
literal = util.viewLiteral(n[1])
end
--
2.45.2 result: (global) WS_BORDER: integer = 0x800000 |
Currently if you have defined a number like this for example:
Hovering over
WS_BORDER
displays:Would it be possible to add an option so that numbers that are not defined as decimals are not resolved to decimals when hovering over them? I. e. :
The text was updated successfully, but these errors were encountered: