summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-14 17:06:51 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-14 17:06:51 +0800
commit45fb8f5578e6d11d845d0676d97a392ace627cb7 (patch)
tree77120b0a0e48d275dbb87ba28d5d4eb6ddf6c5df
parent83611b3112bd6c4bf0fe51df585549aa32e9ff51 (diff)
downloadlua-language-server-45fb8f5578e6d11d845d0676d97a392ace627cb7.zip
rename field
-rw-r--r--script-beta/core/rename.lua18
-rw-r--r--script-beta/vm/eachField.lua3
-rw-r--r--script-beta/vm/eachRef.lua2
3 files changed, 20 insertions, 3 deletions
diff --git a/script-beta/core/rename.lua b/script-beta/core/rename.lua
index d8a39ea2..581fd19a 100644
--- a/script-beta/core/rename.lua
+++ b/script-beta/core/rename.lua
@@ -227,7 +227,18 @@ local function ofLocal(source, newname, callback)
end
local function ofField(source, newname, callback)
- return vm.eachRef(source, function (info)
+ local key = guide.getKeyName(source)
+ local tbl
+ if source.type == 'tablefield'
+ or source.type == 'tableindex' then
+ tbl = source.parent
+ else
+ tbl = source.node
+ end
+ return vm.eachField(tbl, function (info)
+ if info.key ~= key then
+ return
+ end
local src = info.source
if src.type == 'tablefield'
or src.type == 'getfield'
@@ -278,8 +289,9 @@ local function rename(source, newname, callback)
return ofLocal(source.node, newname, callback)
elseif source.type == 'field'
or source.type == 'method'
- or source.type == 'tablefield'
- or source.type == 'string'
+ or source.type == 'string' then
+ return ofField(source.parent, newname, callback)
+ elseif source.type == 'tablefield'
or source.type == 'setglobal'
or source.type == 'getglobal' then
return ofField(source, newname, callback)
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index b60a882a..79793389 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -145,6 +145,9 @@ local function eachField(source, callback)
or src.type == 'getmethod'
or src.type == 'getindex' then
ofVar(src, callback)
+ elseif src.type == 'field'
+ or src.type == 'method' then
+ ofVar(src.parent, callback)
elseif src.type == 'table' then
ofTabel(src, callback)
end
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 4289d90f..81dedcbe 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -383,6 +383,7 @@ local function ofField(source, callback)
source = info.source,
mode = info.mode,
}
+ vm.eachRef(info.source, callback)
if info.value then
vm.eachRef(info.value, callback)
end
@@ -396,6 +397,7 @@ local function ofField(source, callback)
source = info.source,
mode = info.mode,
}
+ vm.eachRef(info.source, callback)
if info.value then
vm.eachRef(info.value, callback)
end