Skip to content

Commit 064ecd4

Browse files
author
Andy
authored
Support code-fix-all for importFixes (microsoft#25137)
* Support code-fix-all for importFixes * Change description * Update API (microsoft#25283)
1 parent 726412c commit 064ecd4

12 files changed

+374
-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;
@@ -1418,7 +1418,9 @@ namespace ts {
14181418
return typeof text === "string";
14191419
}
14201420

1421-
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
1421+
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined;
1422+
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined;
1423+
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined {
14221424
return value !== undefined && test(value) ? value : undefined;
14231425
}
14241426

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4474,5 +4474,9 @@
44744474
"Add missing enum member '{0}'": {
44754475
"category": "Message",
44764476
"code": 95063
4477+
},
4478+
"Add all missing imports": {
4479+
"category": "Message",
4480+
"code": 95064
44774481
}
44784482
}

src/compiler/utilities.ts

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

4315-
export function isUMDExportSymbol(symbol: Symbol | undefined) {
4316-
return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
4315+
export function isUMDExportSymbol(symbol: Symbol | undefined): boolean {
4316+
return !!symbol && !!symbol.declarations && !!symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
43174317
}
43184318

43194319
export function showModuleSpecifier({ moduleSpecifier }: ImportDeclaration): string {
@@ -8106,4 +8106,6 @@ namespace ts {
81068106

81078107
return findBestPatternMatch(patterns, _ => _, candidate);
81088108
}
8109+
8110+
export type Mutable<T extends object> = { -readonly [K in keyof T]: T[K] };
81098111
}

src/harness/fourslash.ts

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

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

26482648
if (codeFixes.length === 0) {
26492649
if (expectedTextArray.length !== 0) {

src/services/codeFixProvider.ts

Lines changed: 4 additions & 4 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>)
@@ -89,7 +89,7 @@ namespace ts {
8989
return createCombinedCodeActions(changes, commands.length === 0 ? undefined : commands);
9090
}
9191

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

0 commit comments

Comments
 (0)