Fixed import paths not being updated when multiple files are moved (#191403)

* Modified updatePathsOnRename.ts to fix issue where import paths were not being updated when multiple files were moved.

* Removed errant console log

* Changed return statements to continue in for-of loop

---------

Co-authored-by: Stephen Melvin <steve.melvin@dtn.com>
This commit is contained in:
Stephen Melvin 2023-09-13 17:23:21 -04:00 committed by GitHub
parent cd8ec25951
commit 627cffc8ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,38 +56,39 @@ class UpdateImportsOnFileRenameHandler extends Disposable {
super();
this._register(vscode.workspace.onDidRenameFiles(async (e) => {
const [{ newUri, oldUri }] = e.files;
const newFilePath = this.client.toTsFilePath(newUri);
if (!newFilePath) {
return;
for (const { newUri, oldUri } of e.files) {
const newFilePath = this.client.toTsFilePath(newUri);
if (!newFilePath) {
continue;
}
const oldFilePath = this.client.toTsFilePath(oldUri);
if (!oldFilePath) {
continue;
}
const config = this.getConfiguration(newUri);
const setting = config.get<UpdateImportsOnFileMoveSetting>(updateImportsOnFileMoveName);
if (setting === UpdateImportsOnFileMoveSetting.Never) {
continue;
}
// Try to get a js/ts file that is being moved
// For directory moves, this returns a js/ts file under the directory.
const jsTsFileThatIsBeingMoved = await this.getJsTsFileBeingMoved(newUri);
if (!jsTsFileThatIsBeingMoved || !this.client.toTsFilePath(jsTsFileThatIsBeingMoved)) {
continue;
}
this._pendingRenames.add({ oldUri, newUri, newFilePath, oldFilePath, jsTsFileThatIsBeingMoved });
this._delayer.trigger(() => {
vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: vscode.l10n.t("Checking for update of JS/TS imports")
}, () => this.flushRenames());
});
}
const oldFilePath = this.client.toTsFilePath(oldUri);
if (!oldFilePath) {
return;
}
const config = this.getConfiguration(newUri);
const setting = config.get<UpdateImportsOnFileMoveSetting>(updateImportsOnFileMoveName);
if (setting === UpdateImportsOnFileMoveSetting.Never) {
return;
}
// Try to get a js/ts file that is being moved
// For directory moves, this returns a js/ts file under the directory.
const jsTsFileThatIsBeingMoved = await this.getJsTsFileBeingMoved(newUri);
if (!jsTsFileThatIsBeingMoved || !this.client.toTsFilePath(jsTsFileThatIsBeingMoved)) {
return;
}
this._pendingRenames.add({ oldUri, newUri, newFilePath, oldFilePath, jsTsFileThatIsBeingMoved });
this._delayer.trigger(() => {
vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: vscode.l10n.t("Checking for update of JS/TS imports")
}, () => this.flushRenames());
});
}));
}