mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 13:45:34 -05:00
fix54492: allow editor to check for original file extension for rename (#56680)
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user