diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-24 15:08:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-24 15:08:02 +0800 |
commit | 4b085b8aea5f33ec114baa31d2b9d72341383c32 (patch) | |
tree | fe35a326408e762711a31d3e803464f0c1a8468d /script/core/rename.lua | |
parent | 0c8c6bbf23082d0b858646846a47a3001f718ae2 (diff) | |
parent | 35ce57976db3b4c42193279dd55972ea013fecad (diff) | |
download | lua-language-server-4b085b8aea5f33ec114baa31d2b9d72341383c32.zip |
Merge branch 'newparser'
Diffstat (limited to 'script/core/rename.lua')
-rw-r--r-- | script/core/rename.lua | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/script/core/rename.lua b/script/core/rename.lua index 0ab7a055..0c48dbc4 100644 --- a/script/core/rename.lua +++ b/script/core/rename.lua @@ -36,12 +36,12 @@ local function isValidFunctionName(str) if isValidGlobal(str) then return true end - local pos = str:find(':', 1, true) - if not pos then + local offset = str:find(':', 1, true) + if not offset then return false end - return isValidGlobal(trim(str:sub(1, pos-1))) - and isValidName(trim(str:sub(pos+1))) + return isValidGlobal(trim(str:sub(1, offset-1))) + and isValidName(trim(str:sub(offset+1))) end local function isFunctionGlobalName(source) @@ -81,21 +81,26 @@ local function renameField(source, newname, callback) elseif parent.type == 'getmethod' then callback(source, source.start, source.finish, newname) elseif parent.type == 'setmethod' then - local uri = guide.getUri(source) - local text = files.getText(uri) + local uri = guide.getUri(source) + local text = files.getText(uri) + local state = files.getState(uri) local func = parent.value -- function mt:name () end --> mt['newname'] = function (self) end + local startOffset = guide.positionToOffset(state, parent.start) + 1 + local finishOffset = guide.positionToOffset(state, parent.node.finish) local newstr = string.format('%s[%s] = function ' - , text:sub(parent.start, parent.node.finish) + , text:sub(startOffset, finishOffset) , util.viewString(newname) ) callback(source, func.start, parent.finish, newstr) - local pl = text:find('(', parent.finish, true) + local finishOffset = guide.positionToOffset(state, parent.finish) + local pl = text:find('(', finishOffset, true) if pl then + local insertPos = guide.offsetToPosition(state, pl) if text:find('^%s*%)', pl + 1) then - callback(source, pl + 1, pl, 'self') + callback(source, insertPos, insertPos, 'self') else - callback(source, pl + 1, pl, 'self, ') + callback(source, insertPos, insertPos, 'self, ') end end end |