From 627cffc8ede038e91eba8bd2a5a106170e9725d6 Mon Sep 17 00:00:00 2001 From: Stephen Melvin Date: Wed, 13 Sep 2023 17:23:21 -0400 Subject: [PATCH] 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 --- .../languageFeatures/updatePathsOnRename.ts | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/extensions/typescript-language-features/src/languageFeatures/updatePathsOnRename.ts b/extensions/typescript-language-features/src/languageFeatures/updatePathsOnRename.ts index 0d4da5b39a5..91ca9612e70 100644 --- a/extensions/typescript-language-features/src/languageFeatures/updatePathsOnRename.ts +++ b/extensions/typescript-language-features/src/languageFeatures/updatePathsOnRename.ts @@ -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(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(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()); - }); })); }