diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-17 23:27:29 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-17 23:27:29 +0800 |
commit | 0805814ac575b0f610c4831548cb7f74b39ee37c (patch) | |
tree | f50705e74d6154ae13846b7a741be73cb29f817d /server-beta/src/core/rename.lua | |
parent | 5e91ce2128ed7b44044a701b4a8d17c6df831a56 (diff) | |
download | lua-language-server-0805814ac575b0f610c4831548cb7f74b39ee37c.zip |
支持 prepareRename
Diffstat (limited to 'server-beta/src/core/rename.lua')
-rw-r--r-- | server-beta/src/core/rename.lua | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/server-beta/src/core/rename.lua b/server-beta/src/core/rename.lua index dbeb56b7..0d932a4f 100644 --- a/server-beta/src/core/rename.lua +++ b/server-beta/src/core/rename.lua @@ -198,8 +198,7 @@ local function rename(source, newname, callback) searcher.eachRef(source, function (info) callback(info.source, info.source.start, info.source.finish, newname) end) - end - if source.type == 'local' then + elseif source.type == 'local' then return ofLocal(source, newname, callback) elseif source.type == 'setlocal' or source.type == 'getlocal' then @@ -215,7 +214,36 @@ local function rename(source, newname, callback) return true end -return function (uri, pos, newname) +local function prepareRename(source) + if source.type == 'label' + or source.type == 'goto' + or source.type == 'local' + or source.type == 'setlocal' + or source.type == 'getlocal' + or source.type == 'field' + or source.type == 'method' + or source.type == 'tablefield' + or source.type == 'setglobal' + or source.type == 'getglobal' then + return source, source[1] + elseif source.type == 'string' then + local parent = source.parent + if not parent then + return nil + end + if parent.type == 'setindex' + or parent.type == 'getindex' + or parent.type == 'tableindex' then + return source, source[1] + end + return nil + end + return nil +end + +local m = {} + +function m.rename(uri, pos, newname) local ast = files.getAst(uri) if not ast then return nil @@ -243,3 +271,26 @@ return function (uri, pos, newname) end return results end + +function m.prepareRename(uri, pos) + local ast = files.getAst(uri) + if not ast then + return nil + end + + local result + guide.eachSourceContain(ast.ast, pos, function(source) + local res, text = prepareRename(source) + if res then + result = { + start = source.start, + finish = source.finish, + text = text, + } + end + end) + + return result +end + +return m |