mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Consistently use '...args' for diagnostic args (#53193)
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
createMultiMap,
|
||||
Debug,
|
||||
Diagnostic,
|
||||
DiagnosticAndArguments,
|
||||
DiagnosticOrDiagnosticAndArguments,
|
||||
diagnosticToString,
|
||||
DiagnosticWithLocation,
|
||||
FileTextChanges,
|
||||
@@ -28,17 +28,17 @@ const errorCodeToFixes = createMultiMap<string, CodeFixRegistration>();
|
||||
const fixIdToRegistration = new Map<string, CodeFixRegistration>();
|
||||
|
||||
/** @internal */
|
||||
export function createCodeFixActionWithoutFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments) {
|
||||
export function createCodeFixActionWithoutFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticOrDiagnosticAndArguments) {
|
||||
return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, /*fixId*/ undefined, /*fixAllDescription*/ undefined);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function createCodeFixAction(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments, fixId: {}, fixAllDescription: DiagnosticAndArguments, command?: CodeActionCommand): CodeFixAction {
|
||||
export function createCodeFixAction(fixName: string, changes: FileTextChanges[], description: DiagnosticOrDiagnosticAndArguments, fixId: {}, fixAllDescription: DiagnosticOrDiagnosticAndArguments, command?: CodeActionCommand): CodeFixAction {
|
||||
return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, fixId, diagnosticToString(fixAllDescription), command);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function createCodeFixActionMaybeFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments, fixId?: {}, fixAllDescription?: DiagnosticAndArguments, command?: CodeActionCommand) {
|
||||
export function createCodeFixActionMaybeFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticOrDiagnosticAndArguments, fixId?: {}, fixAllDescription?: DiagnosticOrDiagnosticAndArguments, command?: CodeActionCommand) {
|
||||
return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, fixId, fixAllDescription && diagnosticToString(fixAllDescription), command);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
ANONYMOUS,
|
||||
Debug,
|
||||
DiagnosticAndArguments,
|
||||
DiagnosticOrDiagnosticAndArguments,
|
||||
Diagnostics,
|
||||
emptyArray,
|
||||
factory,
|
||||
@@ -30,7 +30,7 @@ registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: function getCodeActionsToFixImplicitThis(context) {
|
||||
const { sourceFile, program, span } = context;
|
||||
let diagnostic: DiagnosticAndArguments | undefined;
|
||||
let diagnostic: DiagnosticOrDiagnosticAndArguments | undefined;
|
||||
const changes = textChanges.ChangeTracker.with(context, t => {
|
||||
diagnostic = doChange(t, sourceFile, span.start, program.getTypeChecker());
|
||||
});
|
||||
@@ -42,7 +42,7 @@ registerCodeFix({
|
||||
}),
|
||||
});
|
||||
|
||||
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number, checker: TypeChecker): DiagnosticAndArguments | undefined {
|
||||
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number, checker: TypeChecker): DiagnosticOrDiagnosticAndArguments | undefined {
|
||||
const token = getTokenAtPosition(sourceFile, pos);
|
||||
if (!isThis(token)) return undefined;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import {
|
||||
CodeFixAction,
|
||||
CodeFixContext,
|
||||
Debug,
|
||||
DiagnosticAndArguments,
|
||||
DiagnosticMessage,
|
||||
DiagnosticOrDiagnosticAndArguments,
|
||||
Diagnostics,
|
||||
factory,
|
||||
FileTextChanges,
|
||||
@@ -220,7 +220,7 @@ function changeInferToUnknown(changes: textChanges.ChangeTracker, sourceFile: So
|
||||
changes.replaceNode(sourceFile, token.parent, factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword));
|
||||
}
|
||||
|
||||
function createDeleteFix(changes: FileTextChanges[], diag: DiagnosticAndArguments): CodeFixAction {
|
||||
function createDeleteFix(changes: FileTextChanges[], diag: DiagnosticOrDiagnosticAndArguments): CodeFixAction {
|
||||
return createCodeFixAction(fixName, changes, diag, fixIdDelete, Diagnostics.Delete_all_unused_declarations);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
createMultiMap,
|
||||
createPackageJsonImportFilter,
|
||||
Debug,
|
||||
DiagnosticAndArguments,
|
||||
DiagnosticOrDiagnosticAndArguments,
|
||||
Diagnostics,
|
||||
DiagnosticWithLocation,
|
||||
emptyArray,
|
||||
@@ -1212,13 +1212,13 @@ function getExportEqualsImportKind(importingFile: SourceFile, compilerOptions: C
|
||||
}
|
||||
|
||||
function codeActionForFix(context: textChanges.TextChangesContext, sourceFile: SourceFile, symbolName: string, fix: ImportFix, includeSymbolNameInDescription: boolean, compilerOptions: CompilerOptions, preferences: UserPreferences): CodeFixAction {
|
||||
let diag!: DiagnosticAndArguments;
|
||||
let diag!: DiagnosticOrDiagnosticAndArguments;
|
||||
const changes = textChanges.ChangeTracker.with(context, tracker => {
|
||||
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, includeSymbolNameInDescription, compilerOptions, preferences);
|
||||
});
|
||||
return createCodeFixAction(importFixName, changes, diag, importFixId, Diagnostics.Add_all_missing_imports);
|
||||
}
|
||||
function codeActionForFixWorker(changes: textChanges.ChangeTracker, sourceFile: SourceFile, symbolName: string, fix: ImportFix, includeSymbolNameInDescription: boolean, compilerOptions: CompilerOptions, preferences: UserPreferences): DiagnosticAndArguments {
|
||||
function codeActionForFixWorker(changes: textChanges.ChangeTracker, sourceFile: SourceFile, symbolName: string, fix: ImportFix, includeSymbolNameInDescription: boolean, compilerOptions: CompilerOptions, preferences: UserPreferences): DiagnosticOrDiagnosticAndArguments {
|
||||
const quotePreference = getQuotePreference(sourceFile, preferences);
|
||||
switch (fix.kind) {
|
||||
case ImportFixKind.UseNamespace:
|
||||
|
||||
@@ -42,6 +42,8 @@ import {
|
||||
defaultMaximumTruncationLength,
|
||||
DeleteExpression,
|
||||
Diagnostic,
|
||||
DiagnosticAndArguments,
|
||||
DiagnosticArguments,
|
||||
DiagnosticMessage,
|
||||
DiagnosticWithLocation,
|
||||
directoryProbablyExists,
|
||||
@@ -2180,11 +2182,6 @@ export function isStringAndEmptyAnonymousObjectIntersection(type: Type) {
|
||||
(areIntersectedTypesAvoidingStringReduction(checker, types[0], types[1]) || areIntersectedTypesAvoidingStringReduction(checker, types[1], types[0]));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isPunctuation(kind: SyntaxKind): boolean {
|
||||
return SyntaxKind.FirstPunctuation <= kind && kind <= SyntaxKind.LastPunctuation;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isInsideTemplateLiteral(node: TemplateLiteralToken, position: number, sourceFile: SourceFile): boolean {
|
||||
return isTemplateLiteralKind(node.kind)
|
||||
@@ -4058,11 +4055,11 @@ export function getNewLineKind(newLineCharacter: string): NewLineKind {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export type DiagnosticAndArguments = DiagnosticMessage | [DiagnosticMessage, string] | [DiagnosticMessage, string, string];
|
||||
export type DiagnosticOrDiagnosticAndArguments = DiagnosticMessage | DiagnosticAndArguments;
|
||||
/** @internal */
|
||||
export function diagnosticToString(diag: DiagnosticAndArguments): string {
|
||||
export function diagnosticToString(diag: DiagnosticOrDiagnosticAndArguments): string {
|
||||
return isArray(diag)
|
||||
? formatStringFromArgs(getLocaleSpecificMessage(diag[0]), diag.slice(1) as readonly string[])
|
||||
? formatStringFromArgs(getLocaleSpecificMessage(diag[0]), diag.slice(1) as DiagnosticArguments)
|
||||
: getLocaleSpecificMessage(diag);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user