@@ -3,42 +3,59 @@ local vm = require 'vm'
33local util = require ' utility'
44local findSource = require ' core.find-source'
55local guide = require ' parser.guide'
6+ local config = require ' config'
67
78local Forcing
89
10+ --- @param str string
11+ --- @return string
912local function trim (str )
1013 return str :match ' ^%s*(%S+)%s*$'
1114end
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
1829end
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
3044end
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 )))
4259end
4360
4461local function isFunctionGlobalName (source )
@@ -54,15 +71,15 @@ local function isFunctionGlobalName(source)
5471end
5572
5673local 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 )
6279end
6380
6481local 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)
108125end
109126
110127local 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