summaryrefslogtreecommitdiff
path: root/test/rename/init.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-24 15:08:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-24 15:08:02 +0800
commit4b085b8aea5f33ec114baa31d2b9d72341383c32 (patch)
treefe35a326408e762711a31d3e803464f0c1a8468d /test/rename/init.lua
parent0c8c6bbf23082d0b858646846a47a3001f718ae2 (diff)
parent35ce57976db3b4c42193279dd55972ea013fecad (diff)
downloadlua-language-server-4b085b8aea5f33ec114baa31d2b9d72341383c32.zip
Merge branch 'newparser'
Diffstat (limited to 'test/rename/init.lua')
-rw-r--r--test/rename/init.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/test/rename/init.lua b/test/rename/init.lua
index 4b10756e..b20c0279 100644
--- a/test/rename/init.lua
+++ b/test/rename/init.lua
@@ -1,16 +1,21 @@
local core = require 'core.rename'
local files = require 'files'
+local catch = require 'catch'
+local guide = require 'parser.guide'
local function replace(text, positions)
+ local state = files.getState('')
local buf = {}
table.sort(positions, function (a, b)
return a.start < b.start
end)
local lastPos = 1
for _, info in ipairs(positions) do
- buf[#buf+1] = text:sub(lastPos, info.start - 1)
+ local start = guide.positionToOffset(state, info.start)
+ local finish = guide.positionToOffset(state, info.finish)
+ buf[#buf+1] = text:sub(lastPos, start)
buf[#buf+1] = info.text
- lastPos = info.finish + 1
+ lastPos = finish + 1
end
buf[#buf+1] = text:sub(lastPos)
return table.concat(buf)
@@ -21,10 +26,12 @@ function TEST(oldName, newName)
return function (expectScript)
files.removeAll()
files.setText('', oldScript)
- local pos = oldScript:find('[^%w_]'..oldName..'[^%w_]')
- assert(pos)
+ local state = files.getState('')
+ local offset = oldScript:find('[^%w_]'..oldName..'[^%w_]')
+ assert(offset)
+ local position = guide.offsetToPosition(state, offset)
- local positions = core.rename('', pos+1, newName)
+ local positions = core.rename('', position, newName)
local script = oldScript
if positions then
script = replace(script, positions)