Skip to content

Commit 6020a4f

Browse files
committed
FIX rename to unicode with Lua.runtime.unicodeName = true
1 parent f836d90 commit 6020a4f

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# changelog
22

3+
## 3.7.4
4+
* `FIX` rename to unicode with `Lua.runtime.unicodeName = true`
5+
36
## 3.7.3
47
`2023-11-14`
58
* `FIX` can not infer arg type in some cases.

script/core/rename.lua

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,59 @@ local vm = require 'vm'
33
local util = require 'utility'
44
local findSource = require 'core.find-source'
55
local guide = require 'parser.guide'
6+
local config = require 'config'
67

78
local Forcing
89

10+
---@param str string
11+
---@return string
912
local function trim(str)
1013
return str:match '^%s*(%S+)%s*$'
1114
end
1215

13-
local function isValidName(str)
16+
---@param uri uri
17+
---@param str string
18+
---@return boolean
19+
local function isValidName(uri, str)
1420
if not str then
1521
return false
1622
end
17-
return str:match '^[%a_][%w_]*$'
23+
local allowUnicode = config.get(uri, 'Lua.runtime.unicodeName')
24+
if allowUnicode then
25+
return str:match '^[%a_\x80-\xff][%w_\x80-\xff]*$'
26+
else
27+
return str:match '^[%a_][%w_]*$'
28+
end
1829
end
1930

20-
local function isValidGlobal(str)
31+
---@param uri uri
32+
---@param str string
33+
---@return boolean
34+
local function isValidGlobal(uri, str)
2135
if not str then
2236
return false
2337
end
2438
for s in str:gmatch '[^%.]*' do
25-
if not isValidName(trim(s)) then
39+
if not isValidName(uri, trim(s)) then
2640
return false
2741
end
2842
end
2943
return true
3044
end
3145

32-
local function isValidFunctionName(str)
33-
if isValidGlobal(str) then
46+
---@param uri uri
47+
---@param str string
48+
---@return boolean
49+
local function isValidFunctionName(uri, str)
50+
if isValidGlobal(uri, str) then
3451
return true
3552
end
3653
local offset = str:find(':', 1, true)
3754
if not offset then
3855
return false
3956
end
40-
return isValidGlobal(trim(str:sub(1, offset-1)))
41-
and isValidName(trim(str:sub(offset+1)))
57+
return isValidGlobal(uri, trim(str:sub(1, offset-1)))
58+
and isValidName(uri, trim(str:sub(offset+1)))
4259
end
4360

4461
local function isFunctionGlobalName(source)
@@ -54,15 +71,15 @@ local function isFunctionGlobalName(source)
5471
end
5572

5673
local function renameLocal(source, newname, callback)
57-
if isValidName(newname) then
74+
if isValidName(guide.getUri(source), newname) then
5875
callback(source, source.start, source.finish, newname)
5976
return
6077
end
6178
callback(source, source.start, source.finish, newname)
6279
end
6380

6481
local function renameField(source, newname, callback)
65-
if isValidName(newname) then
82+
if isValidName(guide.getUri(source), newname) then
6683
callback(source, source.start, source.finish, newname)
6784
return true
6885
end
@@ -108,11 +125,11 @@ local function renameField(source, newname, callback)
108125
end
109126

110127
local function renameGlobal(source, newname, callback)
111-
if isValidGlobal(newname) then
128+
if isValidGlobal(guide.getUri(source), newname) then
112129
callback(source, source.start, source.finish, newname)
113130
return true
114131
end
115-
if isValidFunctionName(newname) then
132+
if isValidFunctionName(guide.getUri(source), newname) then
116133
callback(source, source.start, source.finish, newname)
117134
return true
118135
end

0 commit comments

Comments
 (0)