Skip to content

Commit ef7a8ed

Browse files
author
Andy Hanson
committed
Support code-fix-all for importFixes
1 parent 662ca71 commit ef7a8ed

12 files changed

+376
-273
lines changed

src/compiler/core.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ namespace ts {
531531
return result;
532532
}
533533

534-
export function flatMapIterator<T, U>(iter: Iterator<T>, mapfn: (x: T) => U[] | Iterator<U> | undefined): Iterator<U> {
534+
export function flatMapIterator<T, U>(iter: Iterator<T>, mapfn: (x: T) => ReadonlyArray<U> | Iterator<U> | undefined): Iterator<U> {
535535
const first = iter.next();
536536
if (first.done) {
537537
return emptyIterator;
@@ -1435,7 +1435,9 @@ namespace ts {
14351435
return typeof text === "string";
14361436
}
14371437

1438-
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
1438+
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined;
1439+
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined;
1440+
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined {
14391441
return value !== undefined && test(value) ? value : undefined;
14401442
}
14411443

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,5 +4418,9 @@
44184418
"Remove braces from arrow function": {
44194419
"category": "Message",
44204420
"code": 95060
4421+
},
4422+
"Fix all missing imports": {
4423+
"category": "Message",
4424+
"code": 95061
44214425
}
44224426
}

src/compiler/utilities.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4298,8 +4298,8 @@ namespace ts {
42984298
return !!forEachAncestorDirectory(directory, d => callback(d) ? true : undefined);
42994299
}
43004300

4301-
export function isUMDExportSymbol(symbol: Symbol | undefined) {
4302-
return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
4301+
export function isUMDExportSymbol(symbol: Symbol | undefined): boolean {
4302+
return !!symbol && !!symbol.declarations && !!symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
43034303
}
43044304

43054305
export function showModuleSpecifier({ moduleSpecifier }: ImportDeclaration): string {
@@ -8094,4 +8094,6 @@ namespace ts {
80948094

80958095
return findBestPatternMatch(patterns, _ => _, candidate);
80968096
}
8097+
8098+
export type Mutable<T extends object> = { -readonly [K in keyof T]: T[K] };
80978099
}

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ Actual: ${stringify(fullActual)}`);
26492649
}
26502650
const range = ts.firstOrUndefined(ranges);
26512651

2652-
const codeFixes = this.getCodeFixes(fileName, errorCode, preferences).filter(f => f.fixId === undefined); // TODO: GH#20315 filter out those that use the import fix ID;
2652+
const codeFixes = this.getCodeFixes(fileName, errorCode, preferences).filter(f => f.fixId === ts.codefix.importFixId);
26532653

26542654
if (codeFixes.length === 0) {
26552655
if (expectedTextArray.length !== 0) {

src/services/codeFixProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* @internal */
22
namespace ts {
33
export interface CodeFixRegistration {
4-
errorCodes: number[];
4+
errorCodes: ReadonlyArray<number>;
55
getCodeActions(context: CodeFixContext): CodeFixAction[] | undefined;
6-
fixIds?: string[];
6+
fixIds?: ReadonlyArray<string>;
77
getAllCodeActions?(context: CodeFixAllContext): CombinedCodeActions;
88
}
99

@@ -27,7 +27,7 @@ namespace ts {
2727
const errorCodeToFixes = createMultiMap<CodeFixRegistration>();
2828
const fixIdToRegistration = createMap<CodeFixRegistration>();
2929

30-
type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
30+
export type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
3131
function diagnosticToString(diag: DiagnosticAndArguments): string {
3232
return isArray(diag)
3333
? formatStringFromArgs(getLocaleSpecificMessage(diag[0]), diag.slice(1) as ReadonlyArray<string>)
@@ -71,7 +71,7 @@ namespace ts {
7171
return fixIdToRegistration.get(cast(context.fixId, isString))!.getAllCodeActions!(context);
7272
}
7373

74-
function createCombinedCodeActions(changes: FileTextChanges[], commands?: CodeActionCommand[]): CombinedCodeActions {
74+
export function createCombinedCodeActions(changes: FileTextChanges[], commands?: CodeActionCommand[]): CombinedCodeActions {
7575
return { changes, commands };
7676
}
7777

@@ -86,7 +86,7 @@ namespace ts {
8686
return createCombinedCodeActions(changes, commands.length === 0 ? undefined : commands);
8787
}
8888

89-
function eachDiagnostic({ program, sourceFile, cancellationToken }: CodeFixAllContext, errorCodes: number[], cb: (diag: DiagnosticWithLocation) => void): void {
89+
export function eachDiagnostic({ program, sourceFile, cancellationToken }: CodeFixAllContext, errorCodes: ReadonlyArray<number>, cb: (diag: DiagnosticWithLocation) => void): void {
9090
for (const diag of program.getSemanticDiagnostics(sourceFile, cancellationToken).concat(computeSuggestionDiagnostics(sourceFile, program, cancellationToken))) {
9191
if (contains(errorCodes, diag.code)) {
9292
cb(diag as DiagnosticWithLocation);

0 commit comments

Comments
 (0)