Skip to content

Commit d92c26d

Browse files
author
Andy
authored
Add test that getEditsForFileRename respects UserPreferences (#25745)
* Add test that getEditsForFileRename respects UserPreferences * Test quotePreference
1 parent 854462d commit d92c26d

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/harness/fourslash.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,9 +3365,9 @@ Actual: ${stringify(fullActual)}`);
33653365
this.cancellationToken.resetCancelled();
33663366
}
33673367

3368-
public getEditsForFileRename({ oldPath, newPath, newFileContents }: FourSlashInterface.GetEditsForFileRenameOptions): void {
3368+
public getEditsForFileRename({ oldPath, newPath, newFileContents, preferences }: FourSlashInterface.GetEditsForFileRenameOptions): void {
33693369
const test = (fileContents: { readonly [fileName: string]: string }, description: string): void => {
3370-
const changes = this.languageService.getEditsForFileRename(oldPath, newPath, this.formatCodeSettings, ts.emptyOptions);
3370+
const changes = this.languageService.getEditsForFileRename(oldPath, newPath, this.formatCodeSettings, preferences);
33713371
this.testNewFileContents(changes, fileContents, description);
33723372
};
33733373

@@ -4890,6 +4890,7 @@ namespace FourSlashInterface {
48904890
readonly oldPath: string;
48914891
readonly newPath: string;
48924892
readonly newFileContents: { readonly [fileName: string]: string };
4893+
readonly preferences?: ts.UserPreferences;
48934894
}
48944895

48954896
export interface MoveToNewFileOptions {

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ declare namespace FourSlashInterface {
336336
ProjectInfo(expected: string[]): void;
337337
allRangesAppearInImplementationList(markerName: string): void;
338338
getEditsForFileRename(options: {
339-
oldPath: string;
340-
newPath: string;
341-
newFileContents: { [fileName: string]: string };
339+
readonly oldPath: string;
340+
readonly newPath: string;
341+
readonly newFileContents: { readonly [fileName: string]: string };
342+
readonly preferences?: UserPreferences;
342343
}): void;
343344
moveToNewFile(options: {
344345
readonly newFileContents: { readonly [fileName: string]: string };
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /dir/a.ts
4+
////export const a = 0;
5+
6+
// @Filename: /dir/b.ts
7+
////import {} from "dir/a";
8+
////import {} from 'dir/a';
9+
10+
// @Filename: /tsconfig.json
11+
////{ "compilerOptions": { "baseUrl": "." } }
12+
13+
verify.getEditsForFileRename({
14+
oldPath: "/dir/a.ts",
15+
newPath: "/dir/a1.ts",
16+
newFileContents: {
17+
"/dir/b.ts":
18+
`import {} from "dir/a1";
19+
import {} from 'dir/a1';`,
20+
},
21+
preferences: {
22+
importModuleSpecifierPreference: "non-relative",
23+
// No effect because we are changing existing imports, which already have quotes
24+
quotePreference: "single",
25+
},
26+
});

0 commit comments

Comments
 (0)