import {
    codeFixAll,
    createCodeFixAction,
    registerCodeFix,
} from "../_namespaces/ts.codefix.js";
import {
    CodeFixAllContext,
    Diagnostics,
    factory,
    getJSDocTypeTag,
    getTokenAtPosition,
    idText,
    isCallExpression,
    isIdentifier,
    isInJSFile,
    isNewExpression,
    isParameter,
    isParenthesizedExpression,
    isParenthesizedTypeNode,
    isTypeReferenceNode,
    isUnionTypeNode,
    NewExpression,
    ParameterDeclaration,
    Program,
    skipTrivia,
    some,
    SourceFile,
    SyntaxKind,
    textChanges,
    TextSpan,
    TypeFlags,
} from "../_namespaces/ts.js";

const fixName = "addVoidToPromise";
const fixId = "addVoidToPromise";
const errorCodes = [
    Diagnostics.Expected_1_argument_but_got_0_new_Promise_needs_a_JSDoc_hint_to_produce_a_resolve_that_can_be_called_without_arguments.code,
    Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise.code,
];
registerCodeFix({
    errorCodes,
    fixIds: [fixId],
    getCodeActions(context) {
        const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span, context.program));
        if (changes.length > 0) {
            return [createCodeFixAction(fixName, changes, Diagnostics.Add_void_to_Promise_resolved_without_a_value, fixId, Diagnostics.Add_void_to_all_Promises_resolved_without_a_value)];
        }
    },
    getAllCodeActions(context: CodeFixAllContext) {
        return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag, context.program, new Set()));
