Skip to content

Commit 4d592ee

Browse files
author
Andy Hanson
committed
More review
1 parent 590faf0 commit 4d592ee

File tree

11 files changed

+56
-48
lines changed

11 files changed

+56
-48
lines changed

Diff for: src/harness/fourslash.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ Actual: ${stringify(fullActual)}`);
29242924

29252925
public verifyApplicableRefactorAvailableAtMarker(negative: boolean, markerName: string) {
29262926
const marker = this.getMarkerByName(markerName);
2927-
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, marker.position);
2927+
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, marker.position, ts.defaultOptions);
29282928
const isAvailable = applicableRefactors && applicableRefactors.length > 0;
29292929
if (negative && isAvailable) {
29302930
this.raiseError(`verifyApplicableRefactorAvailableAtMarker failed - expected no refactor at marker ${markerName} but found some.`);
@@ -2944,7 +2944,7 @@ Actual: ${stringify(fullActual)}`);
29442944
public verifyRefactorAvailable(negative: boolean, name: string, actionName?: string) {
29452945
const selection = this.getSelection();
29462946

2947-
let refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, selection) || [];
2947+
let refactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, selection, ts.defaultOptions) || [];
29482948
refactors = refactors.filter(r => r.name === name && (actionName === undefined || r.actions.some(a => a.name === actionName)));
29492949
const isAvailable = refactors.length > 0;
29502950

@@ -2966,7 +2966,7 @@ Actual: ${stringify(fullActual)}`);
29662966
public verifyRefactor({ name, actionName, refactors }: FourSlashInterface.VerifyRefactorOptions) {
29672967
const selection = this.getSelection();
29682968

2969-
const actualRefactors = (this.languageService.getApplicableRefactors(this.activeFile.fileName, selection) || ts.emptyArray)
2969+
const actualRefactors = (this.languageService.getApplicableRefactors(this.activeFile.fileName, selection, ts.defaultOptions) || ts.emptyArray)
29702970
.filter(r => r.name === name && r.actions.some(a => a.name === actionName));
29712971
this.assertObjectsEqual(actualRefactors, refactors);
29722972
}
@@ -2977,7 +2977,7 @@ Actual: ${stringify(fullActual)}`);
29772977
throw new Error("Exactly one refactor range is allowed per test.");
29782978
}
29792979

2980-
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, { pos: ranges[0].pos, end: ranges[0].end });
2980+
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, ts.first(ranges), ts.defaultOptions);
29812981
const isAvailable = applicableRefactors && applicableRefactors.length > 0;
29822982
if (negative && isAvailable) {
29832983
this.raiseError(`verifyApplicableRefactorAvailableForRange failed - expected no refactor but found some.`);
@@ -2989,7 +2989,7 @@ Actual: ${stringify(fullActual)}`);
29892989

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

3006-
const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, this.formatCodeSettings, range, refactorName, actionName);
3006+
const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, this.formatCodeSettings, range, refactorName, actionName, ts.defaultOptions);
30073007
for (const edit of editInfo.edits) {
30083008
this.applyEdits(edit.fileName, edit.textChanges, /*isFormattingEdit*/ false);
30093009
}
@@ -3048,14 +3048,14 @@ Actual: ${stringify(fullActual)}`);
30483048
formattingOptions = formattingOptions || this.formatCodeSettings;
30493049
const markerPos = this.getMarkerByName(markerName).position;
30503050

3051-
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, markerPos);
3051+
const applicableRefactors = this.languageService.getApplicableRefactors(this.activeFile.fileName, markerPos, ts.defaultOptions);
30523052
const applicableRefactorToApply = ts.find(applicableRefactors, refactor => refactor.name === refactorNameToApply);
30533053

30543054
if (!applicableRefactorToApply) {
30553055
this.raiseError(`The expected refactor: ${refactorNameToApply} is not available at the marker location.`);
30563056
}
30573057

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

30603060
for (const edit of editInfo.edits) {
30613061
this.applyEdits(edit.fileName, edit.textChanges, /*isFormattingEdit*/ false);

Diff for: src/harness/unittests/extractTestHelpers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ namespace ts {
127127
endPosition: selectionRange.end,
128128
host: notImplementedHost,
129129
formatContext: formatting.getFormatContext(testFormatOptions),
130+
options: defaultOptions,
130131
};
131132
const rangeToExtract = refactor.extractSymbol.getRangeToExtract(sourceFile, createTextSpanFromRange(selectionRange));
132133
assert.equal(rangeToExtract.errors, undefined, rangeToExtract.errors && "Range error: " + rangeToExtract.errors[0].messageText);
@@ -190,6 +191,7 @@ namespace ts {
190191
endPosition: selectionRange.end,
191192
host: notImplementedHost,
192193
formatContext: formatting.getFormatContext(testFormatOptions),
194+
options: defaultOptions,
193195
};
194196
const rangeToExtract = refactor.extractSymbol.getRangeToExtract(sourceFile, createTextSpanFromRange(selectionRange));
195197
assert.isUndefined(rangeToExtract.errors, rangeToExtract.errors && "Range error: " + rangeToExtract.errors[0].messageText);

Diff for: 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);
196+
const changes = languageService.organizeImports({ type: "file", fileName: testFile.path }, testFormatOptions, defaultOptions);
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);
406+
const changes = languageService.organizeImports({ type: "file", fileName: testPath }, testFormatOptions, defaultOptions);
407407
assert.equal(changes.length, 1);
408408
assert.equal(changes[0].fileName, testPath);
409409

Diff for: src/server/protocol.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2589,17 +2589,17 @@ namespace ts.server.protocol {
25892589
}
25902590

25912591
export interface Options {
2592-
quote: "double" | "single";
2592+
quote?: "double" | "single";
25932593
/**
25942594
* If enabled, TypeScript will search through all external modules' exports and add them to the completions list.
25952595
* This affects lone identifier completions but not completions on the right hand side of `obj.`.
25962596
*/
2597-
includeExternalModuleExports: boolean;
2597+
includeExternalModuleExports?: boolean;
25982598
/**
25992599
* If enabled, the completion list will include completions with invalid identifier names.
26002600
* For those entries, The `insertText` and `replacementSpan` properties will be set to change from `.x` property access to `["x"]`.
26012601
*/
2602-
includeInsertTextCompletions: boolean;
2602+
includeInsertTextCompletions?: boolean;
26032603
}
26042604

26052605
export interface CompilerOptions {

Diff for: src/server/session.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ namespace ts.server {
12391239
const position = this.getPosition(args, scriptInfo);
12401240

12411241
const completions = project.getLanguageService().getCompletionsAtPosition(file, position, {
1242-
...this.getServicesOptions(file),
1242+
...this.getOptions(file),
12431243
includeExternalModuleExports: args.includeExternalModuleExports,
12441244
includeInsertTextCompletions: args.includeInsertTextCompletions
12451245
});
@@ -1564,7 +1564,7 @@ namespace ts.server {
15641564
const { file, project } = this.getFileAndProject(args);
15651565
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
15661566
const { position, textRange } = this.extractPositionAndRange(args, scriptInfo);
1567-
return project.getLanguageService().getApplicableRefactors(file, position || textRange);
1567+
return project.getLanguageService().getApplicableRefactors(file, position || textRange, this.getOptions(file));
15681568
}
15691569

15701570
private getEditsForRefactor(args: protocol.GetEditsForRefactorRequestArgs, simplifiedResult: boolean): RefactorEditInfo | protocol.RefactorEditInfo {
@@ -1577,7 +1577,8 @@ namespace ts.server {
15771577
this.getFormatOptions(file),
15781578
position || textRange,
15791579
args.refactor,
1580-
args.action
1580+
args.action,
1581+
this.getOptions(file),
15811582
);
15821583

15831584
if (result === undefined) {
@@ -1603,8 +1604,7 @@ namespace ts.server {
16031604
private organizeImports({ scope }: protocol.OrganizeImportsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileCodeEdits> | ReadonlyArray<FileTextChanges> {
16041605
Debug.assert(scope.type === "file");
16051606
const { file, project } = this.getFileAndProject(scope.args);
1606-
const formatOptions = this.getFormatOptions(file);
1607-
const changes = project.getLanguageService().organizeImports({ type: "file", fileName: file }, formatOptions);
1607+
const changes = project.getLanguageService().organizeImports({ type: "file", fileName: file }, this.getFormatOptions(file), this.getOptions(file));
16081608
if (simplifiedResult) {
16091609
return this.mapTextChangesToCodeEdits(project, changes);
16101610
}
@@ -1622,7 +1622,7 @@ namespace ts.server {
16221622
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
16231623
const { startPosition, endPosition } = this.getStartAndEndPosition(args, scriptInfo);
16241624

1625-
const codeActions = project.getLanguageService().getCodeFixesAtPosition(file, startPosition, endPosition, args.errorCodes, this.getFormatOptions(file), this.getServicesOptions(file));
1625+
const codeActions = project.getLanguageService().getCodeFixesAtPosition(file, startPosition, endPosition, args.errorCodes, this.getFormatOptions(file), this.getOptions(file));
16261626
if (!codeActions) {
16271627
return undefined;
16281628
}
@@ -1637,7 +1637,7 @@ namespace ts.server {
16371637
private getCombinedCodeFix({ scope, fixId }: protocol.GetCombinedCodeFixRequestArgs, simplifiedResult: boolean): protocol.CombinedCodeActions | CombinedCodeActions {
16381638
Debug.assert(scope.type === "file");
16391639
const { file, project } = this.getFileAndProject(scope.args);
1640-
const res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file }, fixId, this.getFormatOptions(file), this.getServicesOptions(file));
1640+
const res = project.getLanguageService().getCombinedCodeFix({ type: "file", fileName: file }, fixId, this.getFormatOptions(file), this.getOptions(file));
16411641
if (simplifiedResult) {
16421642
return { changes: this.mapTextChangesToCodeEdits(project, res.changes), commands: res.commands };
16431643
}
@@ -2157,7 +2157,7 @@ namespace ts.server {
21572157
return this.projectService.getFormatCodeOptions(file);
21582158
}
21592159

2160-
private getServicesOptions(file: NormalizedPath): Options {
2160+
private getOptions(file: NormalizedPath): Options {
21612161
return this.projectService.getOptions(file);
21622162
}
21632163
}

Diff for: src/services/organizeImports.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ namespace ts.OrganizeImports {
1111
sourceFile: SourceFile,
1212
formatContext: formatting.FormatContext,
1313
host: LanguageServiceHost,
14-
program: Program) {
14+
program: Program,
15+
_options: Options,
16+
) {
1517

1618
const changeTracker = textChanges.ChangeTracker.fromContext({ host, formatContext });
1719

Diff for: src/services/refactorProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace ts {
1414
endPosition?: number;
1515
program: Program;
1616
cancellationToken?: CancellationToken;
17+
options: Options;
1718
}
1819

1920
export namespace refactor {

Diff for: src/services/services.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -1835,13 +1835,13 @@ namespace ts {
18351835
return codefix.getAllFixes({ fixId, sourceFile, program, host, cancellationToken, formatContext, options });
18361836
}
18371837

1838-
function organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings): ReadonlyArray<FileTextChanges> {
1838+
function organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, options: Options): ReadonlyArray<FileTextChanges> {
18391839
synchronizeHostData();
18401840
Debug.assert(scope.type === "file");
18411841
const sourceFile = getValidSourceFile(scope.fileName);
18421842
const formatContext = formatting.getFormatContext(formatOptions);
18431843

1844-
return OrganizeImports.organizeImports(sourceFile, formatContext, host, program);
1844+
return OrganizeImports.organizeImports(sourceFile, formatContext, host, program, options);
18451845
}
18461846

18471847
function applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
@@ -2065,7 +2065,7 @@ namespace ts {
20652065
return Rename.getRenameInfo(program.getTypeChecker(), defaultLibFileName, getCanonicalFileName, getValidSourceFile(fileName), position);
20662066
}
20672067

2068-
function getRefactorContext(file: SourceFile, positionOrRange: number | TextRange, formatOptions?: FormatCodeSettings): RefactorContext {
2068+
function getRefactorContext(file: SourceFile, positionOrRange: number | TextRange, options: Options, formatOptions?: FormatCodeSettings): RefactorContext {
20692069
const [startPosition, endPosition] = typeof positionOrRange === "number" ? [positionOrRange, undefined] : [positionOrRange.pos, positionOrRange.end];
20702070
return {
20712071
file,
@@ -2075,25 +2075,28 @@ namespace ts {
20752075
host,
20762076
formatContext: formatting.getFormatContext(formatOptions),
20772077
cancellationToken,
2078+
options,
20782079
};
20792080
}
20802081

2081-
function getApplicableRefactors(fileName: string, positionOrRange: number | TextRange): ApplicableRefactorInfo[] {
2082+
function getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, options: Options): ApplicableRefactorInfo[] {
20822083
synchronizeHostData();
20832084
const file = getValidSourceFile(fileName);
2084-
return refactor.getApplicableRefactors(getRefactorContext(file, positionOrRange));
2085+
return refactor.getApplicableRefactors(getRefactorContext(file, positionOrRange, options));
20852086
}
20862087

20872088
function getEditsForRefactor(
20882089
fileName: string,
20892090
formatOptions: FormatCodeSettings,
20902091
positionOrRange: number | TextRange,
20912092
refactorName: string,
2092-
actionName: string): RefactorEditInfo {
2093+
actionName: string,
2094+
options: Options,
2095+
): RefactorEditInfo {
20932096

20942097
synchronizeHostData();
20952098
const file = getValidSourceFile(fileName);
2096-
return refactor.getEditsForRefactor(getRefactorContext(file, positionOrRange, formatOptions), refactorName, actionName);
2099+
return refactor.getEditsForRefactor(getRefactorContext(file, positionOrRange, options, formatOptions), refactorName, actionName);
20972100
}
20982101

20992102
return {

Diff for: src/services/types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ namespace ts {
303303

304304
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
305305

306-
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings, servicesOptions: Options): ReadonlyArray<CodeFixAction>;
307-
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, servicesOptions: Options): CombinedCodeActions;
306+
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings, options: Options): ReadonlyArray<CodeFixAction>;
307+
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, options: Options): CombinedCodeActions;
308308
applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
309309
applyCodeActionCommand(action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
310310
applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
@@ -314,9 +314,9 @@ namespace ts {
314314
applyCodeActionCommand(fileName: string, action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
315315
/** @deprecated `fileName` will be ignored */
316316
applyCodeActionCommand(fileName: string, action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
317-
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange): ApplicableRefactorInfo[];
318-
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string): RefactorEditInfo | undefined;
319-
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings): ReadonlyArray<FileTextChanges>;
317+
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange, options: Options): ApplicableRefactorInfo[];
318+
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, options: Options): RefactorEditInfo | undefined;
319+
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, options: Options): ReadonlyArray<FileTextChanges>;
320320

321321
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput;
322322

0 commit comments

Comments
 (0)