fix54492: allow editor to check for original file extension for rename (#56680)

This commit is contained in:
Isabel Duan
2023-12-08 09:32:52 -08:00
committed by GitHub
parent e3d234cfc8
commit 8dfbfcb058
9 changed files with 236 additions and 9 deletions

View File

@@ -185,17 +185,17 @@ function getRenameInfoForModule(node: StringLiteralLike, sourceFile: SourceFile,
const moduleSourceFile = moduleSymbol.declarations && find(moduleSymbol.declarations, isSourceFile);
if (!moduleSourceFile) return undefined;
const withoutIndex = endsWith(node.text, "/index") || endsWith(node.text, "/index.js") ? undefined : tryRemoveSuffix(removeFileExtension(moduleSourceFile.fileName), "/index");
const name = withoutIndex === undefined ? moduleSourceFile.fileName : withoutIndex;
const fileName = withoutIndex === undefined ? moduleSourceFile.fileName : withoutIndex;
const kind = withoutIndex === undefined ? ScriptElementKind.moduleElement : ScriptElementKind.directory;
const indexAfterLastSlash = node.text.lastIndexOf("/") + 1;
// Span should only be the last component of the path. + 1 to account for the quote character.
const triggerSpan = createTextSpan(node.getStart(sourceFile) + 1 + indexAfterLastSlash, node.text.length - indexAfterLastSlash);
return {
canRename: true,
fileToRename: name,
fileToRename: fileName,
kind,
displayName: name,
fullDisplayName: name,
displayName: fileName,
fullDisplayName: node.text,
kindModifiers: ScriptElementKindModifier.none,
triggerSpan,
};

View File

@@ -1291,6 +1291,10 @@ export interface RenameInfoSuccess {
*/
fileToRename?: string;
displayName: string;
/**
* Full display name of item to be renamed.
* If item to be renamed is a file, then this is the original text of the module specifer
*/
fullDisplayName: string;
kind: ScriptElementKind;
kindModifiers: string;