mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Merge pull request #24328 from Microsoft/getEditsForFileRename_oldFileStillPresent
getEditsForFileRename: Handle old file still being present
This commit is contained in:
commit
dd6dc5e27a
@ -63,6 +63,7 @@
|
||||
"../services/documentRegistry.ts",
|
||||
"../services/importTracker.ts",
|
||||
"../services/findAllReferences.ts",
|
||||
"../services/getEditsForFileRename.ts",
|
||||
"../services/goToDefinition.ts",
|
||||
"../services/jsDoc.ts",
|
||||
"../services/semver.ts",
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
"../services/documentRegistry.ts",
|
||||
"../services/importTracker.ts",
|
||||
"../services/findAllReferences.ts",
|
||||
"../services/getEditsForFileRename.ts",
|
||||
"../services/goToDefinition.ts",
|
||||
"../services/jsDoc.ts",
|
||||
"../services/semver.ts",
|
||||
|
||||
@ -65,6 +65,7 @@
|
||||
"../services/documentRegistry.ts",
|
||||
"../services/importTracker.ts",
|
||||
"../services/findAllReferences.ts",
|
||||
"../services/getEditsForFileRename.ts",
|
||||
"../services/goToDefinition.ts",
|
||||
"../services/jsDoc.ts",
|
||||
"../services/semver.ts",
|
||||
|
||||
@ -32,23 +32,20 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getImportsToUpdate(program: Program, oldFilePath: string, host: LanguageServiceHost): ReadonlyArray<ToUpdate> {
|
||||
const checker = program.getTypeChecker();
|
||||
const result: ToUpdate[] = [];
|
||||
for (const sourceFile of program.getSourceFiles()) {
|
||||
for (const ref of sourceFile.referencedFiles) {
|
||||
if (!program.getSourceFileFromReference(sourceFile, ref) && resolveTripleslashReference(ref.fileName, sourceFile.fileName) === oldFilePath) {
|
||||
if (resolveTripleslashReference(ref.fileName, sourceFile.fileName) === oldFilePath) {
|
||||
result.push({ sourceFile, toUpdate: ref });
|
||||
}
|
||||
}
|
||||
|
||||
for (const importStringLiteral of sourceFile.imports) {
|
||||
// If it resolved to something already, ignore.
|
||||
if (checker.getSymbolAtLocation(importStringLiteral)) continue;
|
||||
|
||||
const resolved = host.resolveModuleNames
|
||||
? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importStringLiteral.text, sourceFile.fileName)
|
||||
: program.getResolvedModuleWithFailedLookupLocationsFromCache(importStringLiteral.text, sourceFile.fileName);
|
||||
if (resolved && contains(resolved.failedLookupLocations, oldFilePath)) {
|
||||
// We may or may not have picked up on the file being renamed, so maybe successfully resolved to oldFilePath, or maybe that's in failedLookupLocations
|
||||
if (resolved && contains(resolved.resolvedModule ? [resolved.resolvedModule.resolvedFileName] : resolved.failedLookupLocations, oldFilePath)) {
|
||||
result.push({ sourceFile, toUpdate: importStringLiteral });
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
"documentRegistry.ts",
|
||||
"importTracker.ts",
|
||||
"findAllReferences.ts",
|
||||
"getEditsForFileRename.ts",
|
||||
"goToDefinition.ts",
|
||||
"jsDoc.ts",
|
||||
"semver.ts",
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// See also `getEditsForFileRename_oldFileStillPresent.ts`
|
||||
|
||||
// @Filename: /a.ts
|
||||
/////// <reference path="./src/old.ts" />
|
||||
////import old from "./src/old";
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// Same test as `getEditsForFileRename.ts`, but with the old file not yet renamed.
|
||||
|
||||
// @Filename: /src/old.ts
|
||||
////stuff
|
||||
|
||||
// @Filename: /a.ts
|
||||
/////// <reference path="./src/old.ts" />
|
||||
////import old from "./src/old";
|
||||
|
||||
// @Filename: /src/a.ts
|
||||
/////// <reference path="./old.ts" />
|
||||
////import old from "./old";
|
||||
|
||||
// @Filename: /src/foo/a.ts
|
||||
/////// <reference path="../old.ts" />
|
||||
////import old from "../old";
|
||||
|
||||
// @Filename: /tsconfig.json
|
||||
////{ "files": ["/a.ts", "/src/a.ts", "/src/foo/a.ts", "/src/old.ts"] }
|
||||
|
||||
verify.getEditsForFileRename({
|
||||
oldPath: "/src/old.ts",
|
||||
newPath: "/src/new.ts",
|
||||
newFileContents: {
|
||||
"/a.ts": '/// <reference path="./src/new.ts" />\nimport old from "./src/new";',
|
||||
"/src/a.ts": '/// <reference path="./new.ts" />\nimport old from "./new";',
|
||||
"/src/foo/a.ts": '/// <reference path="../new.ts" />\nimport old from "../new";',
|
||||
"/tsconfig.json": '{ "files": ["/a.ts", "/src/a.ts", "/src/foo/a.ts", "/src/new.ts"] }',
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user