Skip to content

Commit f0d972c

Browse files
author
Andy Hanson
committed
options -> preferences
1 parent b06b0d8 commit f0d972c

29 files changed

+228
-228
lines changed

src/harness/fourslash.ts

+27-27
Original file line numberDiff line numberDiff line change
@@ -1227,8 +1227,8 @@ Actual: ${stringify(fullActual)}`);
12271227
return this.languageService.getCompletionsAtPosition(this.activeFile.fileName, this.currentCaretPosition, options);
12281228
}
12291229

1230-
private getCompletionEntryDetails(entryName: string, source?: string, options?: ts.Options): ts.CompletionEntryDetails {
1231-
return this.languageService.getCompletionEntryDetails(this.activeFile.fileName, this.currentCaretPosition, entryName, this.formatCodeSettings, source, options);
1230+
private getCompletionEntryDetails(entryName: string, source?: string, preferences?: ts.UserPreferences): ts.CompletionEntryDetails {
1231+
return this.languageService.getCompletionEntryDetails(this.activeFile.fileName, this.currentCaretPosition, entryName, this.formatCodeSettings, source, preferences);
12321232
}
12331233

12341234
private getReferencesAtCaret() {
@@ -1727,8 +1727,8 @@ Actual: ${stringify(fullActual)}`);
17271727
Harness.IO.log(stringify(sigHelp));
17281728
}
17291729

1730-
public printCompletionListMembers(options: ts.Options | undefined) {
1731-
const completions = this.getCompletionListAtCaret(options);
1730+
public printCompletionListMembers(preferences: ts.UserPreferences | undefined) {
1731+
const completions = this.getCompletionListAtCaret(preferences);
17321732
this.printMembersOrCompletions(completions);
17331733
}
17341734

@@ -1826,7 +1826,7 @@ Actual: ${stringify(fullActual)}`);
18261826
}
18271827
else if (prevChar === " " && /A-Za-z_/.test(ch)) {
18281828
/* Completions */
1829-
this.languageService.getCompletionsAtPosition(this.activeFile.fileName, offset, ts.defaultOptions);
1829+
this.languageService.getCompletionsAtPosition(this.activeFile.fileName, offset, ts.defaultPreferences);
18301830
}
18311831

18321832
if (i % checkCadence === 0) {
@@ -2401,14 +2401,14 @@ Actual: ${stringify(fullActual)}`);
24012401
public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) {
24022402
this.goToMarker(markerName);
24032403

2404-
const actualCompletion = this.getCompletionListAtCaret({ ...ts.defaultOptions, includeCompletionsForModuleExports: true }).entries.find(e =>
2404+
const actualCompletion = this.getCompletionListAtCaret({ ...ts.defaultPreferences, includeCompletionsForModuleExports: true }).entries.find(e =>
24052405
e.name === options.name && e.source === options.source);
24062406

24072407
if (!actualCompletion.hasAction) {
24082408
this.raiseError(`Completion for ${options.name} does not have an associated action.`);
24092409
}
24102410

2411-
const details = this.getCompletionEntryDetails(options.name, actualCompletion.source, options.options);
2411+
const details = this.getCompletionEntryDetails(options.name, actualCompletion.source, options.preferences);
24122412
if (details.codeActions.length !== 1) {
24132413
this.raiseError(`Expected one code action, got ${details.codeActions.length}`);
24142414
}
@@ -2453,7 +2453,7 @@ Actual: ${stringify(fullActual)}`);
24532453
const { fixId, newFileContent } = options;
24542454
const fixIds = ts.mapDefined(this.getCodeFixes(this.activeFile.fileName), a => a.fixId);
24552455
ts.Debug.assert(ts.contains(fixIds, fixId), "No available code fix has that group id.", () => `Expected '${fixId}'. Available action ids: ${fixIds}`);
2456-
const { changes, commands } = this.languageService.getCombinedCodeFix({ type: "file", fileName: this.activeFile.fileName }, fixId, this.formatCodeSettings, ts.defaultOptions);
2456+
const { changes, commands } = this.languageService.getCombinedCodeFix({ type: "file", fileName: this.activeFile.fileName }, fixId, this.formatCodeSettings, ts.defaultPreferences);
24572457
assert.deepEqual(commands, options.commands);
24582458
assert(changes.every(c => c.fileName === this.activeFile.fileName), "TODO: support testing codefixes that touch multiple files");
24592459
this.applyChanges(changes);
@@ -2482,7 +2482,7 @@ Actual: ${stringify(fullActual)}`);
24822482

24832483
public verifyCodeFix(options: FourSlashInterface.VerifyCodeFixOptions) {
24842484
const fileName = this.activeFile.fileName;
2485-
const actions = this.getCodeFixes(fileName, options.errorCode, options.options);
2485+
const actions = this.getCodeFixes(fileName, options.errorCode, options.preferences);
24862486
let index = options.index;
24872487
if (index === undefined) {
24882488
if (!(actions && actions.length === 1)) {
@@ -2521,7 +2521,7 @@ Actual: ${stringify(fullActual)}`);
25212521
* Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
25222522
* @param fileName Path to file where error should be retrieved from.
25232523
*/
2524-
private getCodeFixes(fileName: string, errorCode?: number, options: ts.Options = ts.defaultOptions): ts.CodeFixAction[] {
2524+
private getCodeFixes(fileName: string, errorCode?: number, preferences: ts.UserPreferences = ts.defaultPreferences): ts.CodeFixAction[] {
25252525
const diagnosticsForCodeFix = this.getDiagnostics(fileName, /*includeSuggestions*/ true).map(diagnostic => ({
25262526
start: diagnostic.start,
25272527
length: diagnostic.length,
@@ -2533,7 +2533,7 @@ Actual: ${stringify(fullActual)}`);
25332533
return;
25342534
}
25352535

2536-
return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.start + diagnostic.length, [diagnostic.code], this.formatCodeSettings, options);
2536+
return this.languageService.getCodeFixesAtPosition(fileName, diagnostic.start, diagnostic.start + diagnostic.length, [diagnostic.code], this.formatCodeSettings, preferences);
25372537
});
25382538
}
25392539

@@ -2559,15 +2559,15 @@ Actual: ${stringify(fullActual)}`);
25592559
}
25602560
}
25612561

2562-
public verifyImportFixAtPosition(expectedTextArray: string[], errorCode: number | undefined, options: ts.Options | undefined) {
2562+
public verifyImportFixAtPosition(expectedTextArray: string[], errorCode: number | undefined, preferences: ts.UserPreferences | undefined) {
25632563
const { fileName } = this.activeFile;
25642564
const ranges = this.getRanges().filter(r => r.fileName === fileName);
25652565
if (ranges.length !== 1) {
25662566
this.raiseError("Exactly one range should be specified in the testfile.");
25672567
}
25682568
const range = ts.first(ranges);
25692569

2570-
const codeFixes = this.getCodeFixes(fileName, errorCode, options);
2570+
const codeFixes = this.getCodeFixes(fileName, errorCode, preferences);
25712571

25722572
if (codeFixes.length === 0) {
25732573
if (expectedTextArray.length !== 0) {
@@ -2937,7 +2937,7 @@ Actual: ${stringify(fullActual)}`);
29372937

29382938
public verifyApplicableRefactorAvailableAtMarker(negative: boolean, markerName: string) {
29392939
const marker = this.getMarkerByName(markerName);
2940-
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, marker.position, ts.defaultOptions);
2940+
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, marker.position, ts.defaultPreferences);
29412941
const isAvailable = applicableRefactors && applicableRefactors.length > 0;
29422942
if (negative && isAvailable) {
29432943
this.raiseError(`verifyApplicableRefactorAvailableAtMarker failed - expected no refactor at marker ${markerName} but found some.`);
@@ -2957,7 +2957,7 @@ Actual: ${stringify(fullActual)}`);
29572957
public verifyRefactorAvailable(negative: boolean, name: string, actionName?: string) {
29582958
const selection = this.getSelection();
29592959

2960-
let refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, selection, ts.defaultOptions) || [];
2960+
let refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, selection, ts.defaultPreferences) || [];
29612961
refactors = refactors.filter(r => r.name === name && (actionName === undefined || r.actions.some(a => a.name === actionName)));
29622962
const isAvailable = refactors.length > 0;
29632963

@@ -2979,7 +2979,7 @@ Actual: ${stringify(fullActual)}`);
29792979
public verifyRefactor({ name, actionName, refactors }: FourSlashInterface.VerifyRefactorOptions) {
29802980
const selection = this.getSelection();
29812981

2982-
const actualRefactors = (this.languageService.getApplicableRefactors(this.activeFile.fileName, selection, ts.defaultOptions) || ts.emptyArray)
2982+
const actualRefactors = (this.languageService.getApplicableRefactors(this.activeFile.fileName, selection, ts.defaultPreferences) || ts.emptyArray)
29832983
.filter(r => r.name === name && r.actions.some(a => a.name === actionName));
29842984
this.assertObjectsEqual(actualRefactors, refactors);
29852985
}
@@ -2990,7 +2990,7 @@ Actual: ${stringify(fullActual)}`);
29902990
throw new Error("Exactly one refactor range is allowed per test.");
29912991
}
29922992

2993-
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, ts.first(ranges), ts.defaultOptions);
2993+
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, ts.first(ranges), ts.defaultPreferences);
29942994
const isAvailable = applicableRefactors && applicableRefactors.length > 0;
29952995
if (negative && isAvailable) {
29962996
this.raiseError(`verifyApplicableRefactorAvailableForRange failed - expected no refactor but found some.`);
@@ -3002,7 +3002,7 @@ Actual: ${stringify(fullActual)}`);
30023002

30033003
public applyRefactor({ refactorName, actionName, actionDescription, newContent: newContentWithRenameMarker }: FourSlashInterface.ApplyRefactorOptions) {
30043004
const range = this.getSelection();
3005-
const refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, range, ts.defaultOptions);
3005+
const refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, range, ts.defaultPreferences);
30063006
const refactorsWithName = refactors.filter(r => r.name === refactorName);
30073007
if (refactorsWithName.length === 0) {
30083008
this.raiseError(`The expected refactor: ${refactorName} is not available at the marker location.\nAvailable refactors: ${refactors.map(r => r.name)}`);
@@ -3016,7 +3016,7 @@ Actual: ${stringify(fullActual)}`);
30163016
this.raiseError(`Expected action description to be ${JSON.stringify(actionDescription)}, got: ${JSON.stringify(action.description)}`);
30173017
}
30183018

3019-
const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, this.formatCodeSettings, range, refactorName, actionName, ts.defaultOptions);
3019+
const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, this.formatCodeSettings, range, refactorName, actionName, ts.defaultPreferences);
30203020
for (const edit of editInfo.edits) {
30213021
this.applyEdits(edit.fileName, edit.textChanges, /*isFormattingEdit*/ false);
30223022
}
@@ -3061,14 +3061,14 @@ Actual: ${stringify(fullActual)}`);
30613061
formattingOptions = formattingOptions || this.formatCodeSettings;
30623062
const markerPos = this.getMarkerByName(markerName).position;
30633063

3064-
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, markerPos, ts.defaultOptions);
3064+
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, markerPos, ts.defaultPreferences);
30653065
const applicableRefactorToApply = ts.find(applicableRefactors, refactor => refactor.name === refactorNameToApply);
30663066

30673067
if (!applicableRefactorToApply) {
30683068
this.raiseError(`The expected refactor: ${refactorNameToApply} is not available at the marker location.`);
30693069
}
30703070

3071-
const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply, actionName, ts.defaultOptions);
3071+
const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply, actionName, ts.defaultPreferences);
30723072

30733073
for (const edit of editInfo.edits) {
30743074
this.applyEdits(edit.fileName, edit.textChanges, /*isFormattingEdit*/ false);
@@ -4233,7 +4233,7 @@ namespace FourSlashInterface {
42334233
this.state.applyCodeActionFromCompletion(markerName, options);
42344234
}
42354235

4236-
public importFixAtPosition(expectedTextArray: string[], errorCode?: number, options?: ts.Options): void {
4236+
public importFixAtPosition(expectedTextArray: string[], errorCode?: number, options?: ts.UserPreferences): void {
42374237
this.state.verifyImportFixAtPosition(expectedTextArray, errorCode, options);
42384238
}
42394239

@@ -4440,7 +4440,7 @@ namespace FourSlashInterface {
44404440
this.state.printCurrentSignatureHelp();
44414441
}
44424442

4443-
public printCompletionListMembers(options: ts.Options | undefined) {
4443+
public printCompletionListMembers(options: ts.UserPreferences | undefined) {
44444444
this.state.printCompletionListMembers(options);
44454445
}
44464446

@@ -4637,11 +4637,11 @@ namespace FourSlashInterface {
46374637
}
46384638

46394639
export type ExpectedCompletionEntry = string | { name: string, insertText?: string, replacementSpan?: FourSlash.Range };
4640-
export interface CompletionsAtOptions extends Partial<ts.Options> {
4640+
export interface CompletionsAtOptions extends Partial<ts.UserPreferences> {
46414641
isNewIdentifierLocation?: boolean;
46424642
}
46434643

4644-
export interface VerifyCompletionListContainsOptions extends ts.Options {
4644+
export interface VerifyCompletionListContainsOptions extends ts.UserPreferences {
46454645
sourceDisplay: string;
46464646
isRecommended?: true;
46474647
insertText?: string;
@@ -4662,7 +4662,7 @@ namespace FourSlashInterface {
46624662
description: string;
46634663
errorCode?: number;
46644664
index?: number;
4665-
options?: ts.Options;
4665+
preferences?: ts.UserPreferences;
46664666
}
46674667

46684668
export interface VerifyCodeFixAvailableOptions {
@@ -4686,7 +4686,7 @@ namespace FourSlashInterface {
46864686
name: string;
46874687
source?: string;
46884688
description: string;
4689-
options?: ts.Options;
4689+
preferences?: ts.UserPreferences;
46904690
}
46914691

46924692
export interface Diagnostic {

src/harness/harnessLanguageService.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ namespace Harness.LanguageService {
420420
getEncodedSemanticClassifications(fileName: string, span: ts.TextSpan): ts.Classifications {
421421
return unwrapJSONCallResult(this.shim.getEncodedSemanticClassifications(fileName, span.start, span.length));
422422
}
423-
getCompletionsAtPosition(fileName: string, position: number, options: ts.Options | undefined): ts.CompletionInfo {
424-
return unwrapJSONCallResult(this.shim.getCompletionsAtPosition(fileName, position, options));
423+
getCompletionsAtPosition(fileName: string, position: number, preferences: ts.UserPreferences | undefined): ts.CompletionInfo {
424+
return unwrapJSONCallResult(this.shim.getCompletionsAtPosition(fileName, position, preferences));
425425
}
426-
getCompletionEntryDetails(fileName: string, position: number, entryName: string, formatOptions: ts.FormatCodeOptions | undefined, source: string | undefined, options: ts.Options | undefined): ts.CompletionEntryDetails {
427-
return unwrapJSONCallResult(this.shim.getCompletionEntryDetails(fileName, position, entryName, JSON.stringify(formatOptions), source, options));
426+
getCompletionEntryDetails(fileName: string, position: number, entryName: string, formatOptions: ts.FormatCodeOptions | undefined, source: string | undefined, preferences: ts.UserPreferences | undefined): ts.CompletionEntryDetails {
427+
return unwrapJSONCallResult(this.shim.getCompletionEntryDetails(fileName, position, entryName, JSON.stringify(formatOptions), source, preferences));
428428
}
429429
getCompletionEntrySymbol(): ts.Symbol {
430430
throw new Error("getCompletionEntrySymbol not implemented across the shim layer.");

src/harness/unittests/extractTestHelpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace ts {
127127
endPosition: selectionRange.end,
128128
host: notImplementedHost,
129129
formatContext: formatting.getFormatContext(testFormatOptions),
130-
options: defaultOptions,
130+
preferences: defaultPreferences,
131131
};
132132
const rangeToExtract = refactor.extractSymbol.getRangeToExtract(sourceFile, createTextSpanFromRange(selectionRange));
133133
assert.equal(rangeToExtract.errors, undefined, rangeToExtract.errors && "Range error: " + rangeToExtract.errors[0].messageText);
@@ -191,7 +191,7 @@ namespace ts {
191191
endPosition: selectionRange.end,
192192
host: notImplementedHost,
193193
formatContext: formatting.getFormatContext(testFormatOptions),
194-
options: defaultOptions,
194+
preferences: defaultPreferences,
195195
};
196196
const rangeToExtract = refactor.extractSymbol.getRangeToExtract(sourceFile, createTextSpanFromRange(selectionRange));
197197
assert.isUndefined(rangeToExtract.errors, rangeToExtract.errors && "Range error: " + rangeToExtract.errors[0].messageText);

src/harness/unittests/organizeImports.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export const Other = 1;
193193
content: "function F() { }",
194194
};
195195
const languageService = makeLanguageService(testFile);
196-
const changes = languageService.organizeImports({ type: "file", fileName: testFile.path }, testFormatOptions, defaultOptions);
196+
const changes = languageService.organizeImports({ type: "file", fileName: testFile.path }, testFormatOptions, defaultPreferences);
197197
assert.isEmpty(changes);
198198
});
199199

@@ -403,7 +403,7 @@ import { React, Other } from "react";
403403
function runBaseline(baselinePath: string, testFile: TestFSWithWatch.FileOrFolder, ...otherFiles: TestFSWithWatch.FileOrFolder[]) {
404404
const { path: testPath, content: testContent } = testFile;
405405
const languageService = makeLanguageService(testFile, ...otherFiles);
406-
const changes = languageService.organizeImports({ type: "file", fileName: testPath }, testFormatOptions, defaultOptions);
406+
const changes = languageService.organizeImports({ type: "file", fileName: testPath }, testFormatOptions, defaultPreferences);
407407
assert.equal(changes.length, 1);
408408
assert.equal(changes[0].fileName, testPath);
409409

0 commit comments

Comments
 (0)