Skip to content

Commit

Permalink
added a delay for recently renamed files
Browse files Browse the repository at this point in the history
to ensure refactor cache doesn't see partial changes / duplicate types
  • Loading branch information
AlexHaxe committed Dec 22, 2024
1 parent 5eda093 commit 6eb906b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions haxe_libraries/rename.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxe-rename#d069790b47a68b1adf27fa55e9475ca0f0cb02f0" into rename/2.3.1/github/d069790b47a68b1adf27fa55e9475ca0f0cb02f0
-cp ${HAXE_LIBCACHE}/rename/2.3.1/github/d069790b47a68b1adf27fa55e9475ca0f0cb02f0/src
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxe-rename#32b556bf0fe311543ec2f92c7f5acbb28f9c846b" into rename/2.3.1/github/32b556bf0fe311543ec2f92c7f5acbb28f9c846b
-cp ${HAXE_LIBCACHE}/rename/2.3.1/github/32b556bf0fe311543ec2f92c7f5acbb28f9c846b/src
-D rename=2.3.1
1 change: 1 addition & 0 deletions src/haxeLanguageServer/Context.hx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ class Context {
if (isUriSupported(uri)) {
publishDiagnostics(uri);
invalidated.remove(uri.toString());
refactorCache.invalidateFile(uri.toFsPath().toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import refactor.refactor.CanRefactorContext;
import refactor.refactor.RefactorContext;
import refactor.rename.CanRenameContext;
import refactor.rename.RenameContext;
import sys.FileSystem;
import tokentree.TokenTree;

using haxeLanguageServer.helper.PathHelper;
Expand Down Expand Up @@ -160,7 +161,25 @@ class RefactorCache {

cache.invalidateFile(uri, nameMap, typeList);
fileList.removeFile(uri);
updateSingleFileCache(uri);

if (fileList.wasRecentlyRenamed(uri)) {
// delay for (potentially) recently renamed files, because vscode sends us
// a notifcation of edits in that file but not when it gets renamed.
// so in case of a type rename we don't want to end up having the renamed type twice:
// once for `pack.NewtypeName` and once for `pack.OldTypeName.NewTypeName`
// (helps solve renaming FlxSprite -> FlxCola -> FlxSprite)
haxe.Timer.delay(() -> {
if (FileSystem.exists(uri)) {
updateSingleFileCache(uri);
}
}, 250);
onResolve();
return;
}

if (FileSystem.exists(uri)) {
updateSingleFileCache(uri);
}
onResolve();
}

Expand Down

0 comments on commit 6eb906b

Please sign in to comment.