Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typescript/54492: check if file rename changes extension #200220

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TypeScriptRenameProvider implements vscode.RenameProvider {
}

if (renameInfo.fileToRename) {
const edits = await this.renameFile(renameInfo.fileToRename, newName, token);
const edits = await this.renameFile(renameInfo.fileToRename, renameInfo.fullDisplayName, newName, token);
if (edits) {
return edits;
} else {
Expand Down Expand Up @@ -170,13 +170,17 @@ class TypeScriptRenameProvider implements vscode.RenameProvider {

private async renameFile(
fileToRename: string,
fullDisplayName: string,
newName: string,
token: vscode.CancellationToken,
): Promise<vscode.WorkspaceEdit | undefined> {
// Make sure we preserve file extension if none provided
// Make sure we preserve file extension if extension is unchanged or none provided
if (!path.extname(newName)) {
newName += path.extname(fileToRename);
}
else if (path.extname(newName) === path.extname(fullDisplayName)) {
newName = newName.slice(0, newName.length - path.extname(newName).length) + path.extname(fileToRename);
}

const dirname = path.dirname(fileToRename);
const newFilePath = path.join(dirname, newName);
Expand Down