From 32b556bf0fe311543ec2f92c7f5acbb28f9c846b Mon Sep 17 00:00:00 2001 From: AlexHaxe Date: Sun, 22 Dec 2024 13:07:34 +0100 Subject: [PATCH] added info about recently renamed filenames to help vshaxe ignore them better --- src/refactor/discover/FileList.hx | 16 ++++++++++++++++ src/refactor/discover/TypeList.hx | 2 +- src/refactor/rename/RenameHelper.hx | 14 ++------------ src/refactor/rename/RenamePackage.hx | 1 + src/refactor/rename/RenameTypeName.hx | 12 ++++++------ 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/refactor/discover/FileList.hx b/src/refactor/discover/FileList.hx index 2e0340c..80d3c0d 100644 --- a/src/refactor/discover/FileList.hx +++ b/src/refactor/discover/FileList.hx @@ -3,10 +3,25 @@ package refactor.discover; class FileList { public final files:Map = []; + var recentlyRenamed:Array = []; + public function new() {} public function addFile(file:File) { files.set(file.name, file); + recentlyRenamed.remove(file.name); + } + + public function addRecentlyRenamed(file:File) { + recentlyRenamed.push(file.name); + } + + public function wasRecentlyRenamed(fileName:String):Bool { + if (recentlyRenamed.contains(fileName)) { + recentlyRenamed.remove(fileName); + return true; + } + return false; } public function getFile(fileName:String):Null { @@ -19,5 +34,6 @@ class FileList { public function clear() { files.clear(); + recentlyRenamed = []; } } diff --git a/src/refactor/discover/TypeList.hx b/src/refactor/discover/TypeList.hx index 7eeaa09..51ea07b 100644 --- a/src/refactor/discover/TypeList.hx +++ b/src/refactor/discover/TypeList.hx @@ -28,7 +28,7 @@ class TypeList implements ITypeList { public function removeFile(fileName:String) { var fullNames:Array = []; for (key => type in types) { - if (type.name.pos.fileName == fileName) { + if (type.file.name == fileName) { fullNames.push(type.fullModuleName); } } diff --git a/src/refactor/rename/RenameHelper.hx b/src/refactor/rename/RenameHelper.hx index 8a6a82f..6fdaf59 100644 --- a/src/refactor/rename/RenameHelper.hx +++ b/src/refactor/rename/RenameHelper.hx @@ -72,13 +72,7 @@ class RenameHelper { changelist.addChange(use.pos.fileName, ReplaceText(context.what.toName, use.pos, NoFormat), use); continue; } - case StructType(fields): - continue; - case FunctionType(args, retVal): - continue; - case UnknownType(name): - continue; - case NamedType(_): + case StructType(_) | FunctionType(_, _) | UnknownType(_) | NamedType(_): continue; } } @@ -196,8 +190,6 @@ class RenameHelper { addChanges(type); case LibType("Array", _, [ClasspathType(type, _)]): addChanges(type); - case LibType(_, _): - return; case FunctionType(_, retVal): if (retVal == null) { return; @@ -209,9 +201,7 @@ class RenameHelper { addChanges(type); default: } - case StructType(_): - case UnknownType(_): - case NamedType(_): + case LibType(_, _) | StructType(_) | UnknownType(_) | NamedType(_): } }); } diff --git a/src/refactor/rename/RenamePackage.hx b/src/refactor/rename/RenamePackage.hx index ecb97fc..0daf99e 100644 --- a/src/refactor/rename/RenamePackage.hx +++ b/src/refactor/rename/RenamePackage.hx @@ -95,5 +95,6 @@ class RenamePackage { pathParts.unshift(Path.removeTrailingSlashes(rootPath)); pathParts.push('${mainTypeName}.hx'); changelist.addChange(file.name, Move(Path.join(pathParts)), null); + context.fileList.addRecentlyRenamed(file); } } diff --git a/src/refactor/rename/RenameTypeName.hx b/src/refactor/rename/RenameTypeName.hx index 126b64e..93511f7 100644 --- a/src/refactor/rename/RenameTypeName.hx +++ b/src/refactor/rename/RenameTypeName.hx @@ -16,11 +16,13 @@ class RenameTypeName { var packName:String = file.getPackage(); var mainModuleName:String = file.getMainModulName(); var path:Path = new Path(file.name); + if (mainModuleName == identifier.name) { // type and filename are identical -> move file var newFileName:String = Path.join([path.dir, context.what.toName]) + "." + path.ext; changelist.addChange(file.name, Move(newFileName), null); } + // replace self changelist.addChange(identifier.pos.fileName, ReplaceText(context.what.toName, identifier.pos, NoFormat), identifier); @@ -56,7 +58,6 @@ class RenameTypeName { } switch (use.type) { case Abstract | Class | Enum | Interface | Typedef: - changelist.addChange(use.pos.fileName, ReplaceText(context.what.toName, use.pos, NoFormat), use); continue; default: } @@ -72,11 +73,7 @@ class RenameTypeName { if (type.fullModuleName != identifier.defineType.fullModuleName) { return; } - case LibType(_) | UnknownType(_): - return; - case StructType(_) | FunctionType(_, _): - return; - case NamedType(_): + case LibType(_) | UnknownType(_) | StructType(_) | FunctionType(_, _) | NamedType(_): return; } if (use.name == identifier.name) { @@ -95,6 +92,9 @@ class RenameTypeName { } return Promise.all(changes).then(function(_) { + if (mainModuleName == identifier.name) { + context.fileList.addRecentlyRenamed(file); + } return Promise.resolve(changelist.execute()); }); }