Skip to content

Support code-fix-all for importFixes #25137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
4 commits merged into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ namespace ts {
return result;
}

export function flatMapIterator<T, U>(iter: Iterator<T>, mapfn: (x: T) => U[] | Iterator<U> | undefined): Iterator<U> {
export function flatMapIterator<T, U>(iter: Iterator<T>, mapfn: (x: T) => ReadonlyArray<U> | Iterator<U> | undefined): Iterator<U> {
const first = iter.next();
if (first.done) {
return emptyIterator;
Expand Down Expand Up @@ -1418,7 +1418,9 @@ namespace ts {
return typeof text === "string";
}

export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined;
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined;
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined {
return value !== undefined && test(value) ? value : undefined;
}

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4470,5 +4470,9 @@
"Add missing enum member '{0}'": {
"category": "Message",
"code": 95063
},
"Add all missing imports": {
"category": "Message",
"code": 95064
}
}
6 changes: 4 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4312,8 +4312,8 @@ namespace ts {
return !!forEachAncestorDirectory(directory, d => callback(d) ? true : undefined);
}

export function isUMDExportSymbol(symbol: Symbol | undefined) {
return symbol && symbol.declarations && symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
export function isUMDExportSymbol(symbol: Symbol | undefined): boolean {
return !!symbol && !!symbol.declarations && !!symbol.declarations[0] && isNamespaceExportDeclaration(symbol.declarations[0]);
}

export function showModuleSpecifier({ moduleSpecifier }: ImportDeclaration): string {
Expand Down Expand Up @@ -8105,4 +8105,6 @@ namespace ts {

return findBestPatternMatch(patterns, _ => _, candidate);
}

export type Mutable<T extends object> = { -readonly [K in keyof T]: T[K] };
}
2 changes: 1 addition & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2631,7 +2631,7 @@ Actual: ${stringify(fullActual)}`);
}
const range = ts.firstOrUndefined(ranges);

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

if (codeFixes.length === 0) {
if (expectedTextArray.length !== 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/services/codeFixProvider.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* @internal */
namespace ts {
export interface CodeFixRegistration {
errorCodes: number[];
errorCodes: ReadonlyArray<number>;
getCodeActions(context: CodeFixContext): CodeFixAction[] | undefined;
fixIds?: string[];
fixIds?: ReadonlyArray<string>;
getAllCodeActions?(context: CodeFixAllContext): CombinedCodeActions;
}

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

type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
export type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
function diagnosticToString(diag: DiagnosticAndArguments): string {
return isArray(diag)
? formatStringFromArgs(getLocaleSpecificMessage(diag[0]), diag.slice(1) as ReadonlyArray<string>)
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace ts {
return createCombinedCodeActions(changes, commands.length === 0 ? undefined : commands);
}

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