From a01ab28d27c8f4a61569d3058981b4d3cd43f7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 3 Jan 2023 17:14:20 +0800 Subject: fix renaming --- script/core/rename.lua | 22 +++++++++++++--------- script/parser/guide.lua | 3 ++- test/rename/init.lua | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/script/core/rename.lua b/script/core/rename.lua index 98895826..507def20 100644 --- a/script/core/rename.lua +++ b/script/core/rename.lua @@ -239,7 +239,8 @@ local function ofDocTypeName(source, newname, callback) end local refs = vm.getRefs(source) for _, doc in ipairs(refs) do - if doc.type == 'doc.type.name' then + if doc.type == 'doc.type.name' + or doc.type == 'doc.extends.name' then callback(doc, doc.start, doc.finish, newname) end end @@ -283,7 +284,8 @@ local function rename(source, newname, callback) elseif source.type == 'doc.class.name' or source.type == 'doc.type.name' or source.type == 'doc.alias.name' - or source.type == 'doc.enum.name' then + or source.type == 'doc.enum.name' + or source.type == 'doc.extends.name' then return ofDocTypeName(source, newname, callback) elseif source.type == 'doc.param.name' then return ofDocParamName(source, newname, callback) @@ -321,7 +323,8 @@ local function prepareRename(source) or source.type == 'doc.alias.name' or source.type == 'doc.enum.name' or source.type == 'doc.param.name' - or source.type == 'doc.field.name' then + or source.type == 'doc.field.name' + or source.type == 'doc.extends.name' then return source, source[1] elseif source.type == 'string' or source.type == 'number' @@ -357,12 +360,13 @@ local accept = { ['number'] = true, ['integer'] = true, - ['doc.class.name'] = true, - ['doc.type.name'] = true, - ['doc.alias.name'] = true, - ['doc.param.name'] = true, - ['doc.enum.name'] = true, - ['doc.field.name'] = true, + ['doc.class.name'] = true, + ['doc.type.name'] = true, + ['doc.alias.name'] = true, + ['doc.param.name'] = true, + ['doc.enum.name'] = true, + ['doc.field.name'] = true, + ['doc.extends.name'] = true, } local m = {} diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 96142be5..24709104 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1013,7 +1013,8 @@ function m.getKeyName(obj) or tp == 'doc.type.name' or tp == 'doc.class.name' or tp == 'doc.alias.name' - or tp == 'doc.enum.name' then + or tp == 'doc.enum.name' + or tp == 'doc.extends.name' then return obj[1] elseif tp == 'doc.type.field' then return m.getKeyName(obj.name) diff --git a/test/rename/init.lua b/test/rename/init.lua index 3dfc19e6..dcb5f9e5 100644 --- a/test/rename/init.lua +++ b/test/rename/init.lua @@ -230,3 +230,19 @@ local t print(t.field2) ]] + +TEST ('A', 'C') [[ +---@class A + +---@class B: A +]] [[ +---@class C + +---@class B: C +]] + +TEST ('A', 'C') [[ +---@class B: A +]] [[ +---@class B: C +]] -- cgit v1.2.3