diff options
Diffstat (limited to 'script/core/rename.lua')
-rw-r--r-- | script/core/rename.lua | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/script/core/rename.lua b/script/core/rename.lua index 7599fad6..90e66224 100644 --- a/script/core/rename.lua +++ b/script/core/rename.lua @@ -81,6 +81,9 @@ local function renameField(source, newname, callback) local uri = guide.getUri(source) local text = files.getText(uri) local state = files.getState(uri) + if not state or not text then + return false + end local func = parent.value -- function mt:name () end --> mt['newname'] = function (self) end local startOffset = guide.positionToOffset(state, parent.start) + 1 @@ -183,13 +186,16 @@ local function ofField(source, newname, callback) local key = guide.getKeyName(source) local refs = vm.getRefs(source) for _, ref in ipairs(refs) do - ofFieldThen(key, ref, newname, callback) + ofFieldThen(key, ref, newname, callback) end end ---@async local function ofGlobal(source, newname, callback) local key = guide.getKeyName(source) + if not key then + return + end local global = vm.getGlobal('variable', key) if not global then return @@ -225,6 +231,9 @@ local function ofDocTypeName(source, newname, callback) if doc.type == 'doc.alias' then callback(doc, doc.alias.start, doc.alias.finish, newname) end + if doc.type == 'doc.enum' then + callback(doc, doc.enum.start, doc.enum.finish, newname) + end end for _, doc in ipairs(global:getGets(uri)) do if doc.type == 'doc.type.name' then @@ -236,16 +245,15 @@ end local function ofDocParamName(source, newname, callback) callback(source, source.start, source.finish, newname) local doc = source.parent - if doc.bindSources then - for _, src in ipairs(doc.bindSources) do - if src.type == 'local' - and src.parent.type == 'funcargs' - and src[1] == source[1] then - renameLocal(src, newname, callback) - if src.ref then - for _, ref in ipairs(src.ref) do - renameLocal(ref, newname, callback) - end + local src = doc.bindSource + if src then + if src.type == 'local' + and src.parent.type == 'funcargs' + and src[1] == source[1] then + renameLocal(src, newname, callback) + if src.ref then + for _, ref in ipairs(src.ref) do + renameLocal(ref, newname, callback) end end end @@ -271,7 +279,8 @@ local function rename(source, newname, callback) return ofGlobal(source, newname, callback) elseif source.type == 'doc.class.name' or source.type == 'doc.type.name' - or source.type == 'doc.alias.name' then + or source.type == 'doc.alias.name' + or source.type == 'doc.enum.name' then return ofDocTypeName(source, newname, callback) elseif source.type == 'doc.param.name' then return ofDocParamName(source, newname, callback) @@ -305,6 +314,7 @@ local function prepareRename(source) or source.type == 'doc.class.name' or source.type == 'doc.type.name' or source.type == 'doc.alias.name' + or source.type == 'doc.enum.name' or source.type == 'doc.param.name' then return source, source[1] elseif source.type == 'string' @@ -345,6 +355,7 @@ local accept = { ['doc.type.name'] = true, ['doc.alias.name'] = true, ['doc.param.name'] = true, + ['doc.enum.name'] = true, } local m = {} |