Skip to content

Commit

Permalink
added info about recently renamed filenames to help vshaxe ignore the…
Browse files Browse the repository at this point in the history
…m better
  • Loading branch information
AlexHaxe committed Dec 22, 2024
1 parent d069790 commit 32b556b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
16 changes: 16 additions & 0 deletions src/refactor/discover/FileList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@ package refactor.discover;
class FileList {
public final files:Map<String, File> = [];

var recentlyRenamed:Array<String> = [];

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<File> {
Expand All @@ -19,5 +34,6 @@ class FileList {

public function clear() {
files.clear();
recentlyRenamed = [];
}
}
2 changes: 1 addition & 1 deletion src/refactor/discover/TypeList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TypeList implements ITypeList {
public function removeFile(fileName:String) {
var fullNames:Array<String> = [];
for (key => type in types) {
if (type.name.pos.fileName == fileName) {
if (type.file.name == fileName) {
fullNames.push(type.fullModuleName);
}
}
Expand Down
14 changes: 2 additions & 12 deletions src/refactor/rename/RenameHelper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -209,9 +201,7 @@ class RenameHelper {
addChanges(type);
default:
}
case StructType(_):
case UnknownType(_):
case NamedType(_):
case LibType(_, _) | StructType(_) | UnknownType(_) | NamedType(_):
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/refactor/rename/RenamePackage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions src/refactor/rename/RenameTypeName.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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:
}
Expand All @@ -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) {
Expand All @@ -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());
});
}
Expand Down

0 comments on commit 32b556b

Please sign in to comment.