@@ -3,42 +3,59 @@ local vm = require 'vm'
3
3
local util = require ' utility'
4
4
local findSource = require ' core.find-source'
5
5
local guide = require ' parser.guide'
6
+ local config = require ' config'
6
7
7
8
local Forcing
8
9
10
+ --- @param str string
11
+ --- @return string
9
12
local function trim (str )
10
13
return str :match ' ^%s*(%S+)%s*$'
11
14
end
12
15
13
- local function isValidName (str )
16
+ --- @param uri uri
17
+ --- @param str string
18
+ --- @return boolean
19
+ local function isValidName (uri , str )
14
20
if not str then
15
21
return false
16
22
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
18
29
end
19
30
20
- local function isValidGlobal (str )
31
+ --- @param uri uri
32
+ --- @param str string
33
+ --- @return boolean
34
+ local function isValidGlobal (uri , str )
21
35
if not str then
22
36
return false
23
37
end
24
38
for s in str :gmatch ' [^%.]*' do
25
- if not isValidName (trim (s )) then
39
+ if not isValidName (uri , trim (s )) then
26
40
return false
27
41
end
28
42
end
29
43
return true
30
44
end
31
45
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
34
51
return true
35
52
end
36
53
local offset = str :find (' :' , 1 , true )
37
54
if not offset then
38
55
return false
39
56
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 )))
42
59
end
43
60
44
61
local function isFunctionGlobalName (source )
@@ -54,15 +71,15 @@ local function isFunctionGlobalName(source)
54
71
end
55
72
56
73
local function renameLocal (source , newname , callback )
57
- if isValidName (newname ) then
74
+ if isValidName (guide . getUri ( source ), newname ) then
58
75
callback (source , source .start , source .finish , newname )
59
76
return
60
77
end
61
78
callback (source , source .start , source .finish , newname )
62
79
end
63
80
64
81
local function renameField (source , newname , callback )
65
- if isValidName (newname ) then
82
+ if isValidName (guide . getUri ( source ), newname ) then
66
83
callback (source , source .start , source .finish , newname )
67
84
return true
68
85
end
@@ -108,11 +125,11 @@ local function renameField(source, newname, callback)
108
125
end
109
126
110
127
local function renameGlobal (source , newname , callback )
111
- if isValidGlobal (newname ) then
128
+ if isValidGlobal (guide . getUri ( source ), newname ) then
112
129
callback (source , source .start , source .finish , newname )
113
130
return true
114
131
end
115
- if isValidFunctionName (newname ) then
132
+ if isValidFunctionName (guide . getUri ( source ), newname ) then
116
133
callback (source , source .start , source .finish , newname )
117
134
return true
118
135
end
0 commit comments