Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lua-language-server-srb2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LJ Sonic
lua-language-server-srb2
Commits
6020a4f7
Commit
6020a4f7
authored
Jan 5, 2024
by
最萌小汐
Browse files
Options
Downloads
Patches
Plain Diff
`FIX` rename to unicode with `Lua.runtime.unicodeName = true`
parent
f836d90e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.md
+3
-0
3 additions, 0 deletions
changelog.md
script/core/rename.lua
+29
-12
29 additions, 12 deletions
script/core/rename.lua
with
32 additions
and
12 deletions
changelog.md
+
3
−
0
View file @
6020a4f7
# changelog
## 3.7.4
*
`FIX`
rename to unicode with
`Lua.runtime.unicodeName = true`
## 3.7.3
`2023-11-14`
*
`FIX`
can not infer arg type in some cases.
...
...
This diff is collapsed.
Click to expand it.
script/core/rename.lua
+
29
−
12
View file @
6020a4f7
...
...
@@ -3,42 +3,59 @@ local vm = require 'vm'
local
util
=
require
'utility'
local
findSource
=
require
'core.find-source'
local
guide
=
require
'parser.guide'
local
config
=
require
'config'
local
Forcing
---@param str string
---@return string
local
function
trim
(
str
)
return
str
:
match
'^%s*(%S+)%s*$'
end
local
function
isValidName
(
str
)
---@param uri uri
---@param str string
---@return boolean
local
function
isValidName
(
uri
,
str
)
if
not
str
then
return
false
end
local
allowUnicode
=
config
.
get
(
uri
,
'Lua.runtime.unicodeName'
)
if
allowUnicode
then
return
str
:
match
'^[%a_\x80-\xff][%w_\x80-\xff]*$'
else
return
str
:
match
'^[%a_][%w_]*$'
end
end
local
function
isValidGlobal
(
str
)
---@param uri uri
---@param str string
---@return boolean
local
function
isValidGlobal
(
uri
,
str
)
if
not
str
then
return
false
end
for
s
in
str
:
gmatch
'[^%.]*'
do
if
not
isValidName
(
trim
(
s
))
then
if
not
isValidName
(
uri
,
trim
(
s
))
then
return
false
end
end
return
true
end
local
function
isValidFunctionName
(
str
)
if
isValidGlobal
(
str
)
then
---@param uri uri
---@param str string
---@return boolean
local
function
isValidFunctionName
(
uri
,
str
)
if
isValidGlobal
(
uri
,
str
)
then
return
true
end
local
offset
=
str
:
find
(
':'
,
1
,
true
)
if
not
offset
then
return
false
end
return
isValidGlobal
(
trim
(
str
:
sub
(
1
,
offset
-
1
)))
and
isValidName
(
trim
(
str
:
sub
(
offset
+
1
)))
return
isValidGlobal
(
uri
,
trim
(
str
:
sub
(
1
,
offset
-
1
)))
and
isValidName
(
uri
,
trim
(
str
:
sub
(
offset
+
1
)))
end
local
function
isFunctionGlobalName
(
source
)
...
...
@@ -54,7 +71,7 @@ local function isFunctionGlobalName(source)
end
local
function
renameLocal
(
source
,
newname
,
callback
)
if
isValidName
(
newname
)
then
if
isValidName
(
guide
.
getUri
(
source
),
newname
)
then
callback
(
source
,
source
.
start
,
source
.
finish
,
newname
)
return
end
...
...
@@ -62,7 +79,7 @@ local function renameLocal(source, newname, callback)
end
local
function
renameField
(
source
,
newname
,
callback
)
if
isValidName
(
newname
)
then
if
isValidName
(
guide
.
getUri
(
source
),
newname
)
then
callback
(
source
,
source
.
start
,
source
.
finish
,
newname
)
return
true
end
...
...
@@ -108,11 +125,11 @@ local function renameField(source, newname, callback)
end
local
function
renameGlobal
(
source
,
newname
,
callback
)
if
isValidGlobal
(
newname
)
then
if
isValidGlobal
(
guide
.
getUri
(
source
),
newname
)
then
callback
(
source
,
source
.
start
,
source
.
finish
,
newname
)
return
true
end
if
isValidFunctionName
(
newname
)
then
if
isValidFunctionName
(
guide
.
getUri
(
source
),
newname
)
then
callback
(
source
,
source
.
start
,
source
.
finish
,
newname
)
return
true
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment