<commit_before>/* @internal */
namespace ts.codefix {
    registerCodeFix({
        errorCodes: [Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements.code],
        getCodeActions: (context: CodeFixContext) => {
            const sourceFile = context.sourceFile;
            const start = context.span.start;
            const token = getTokenAtPosition(sourceFile, start);

            if (!(token.kind === SyntaxKind.Identifier && token.parent.parent.parent.kind === SyntaxKind.ClassDeclaration)) {
                return undefined;
            }

            const extendsNode = (token.parent.parent as HeritageClause).getChildren()[0];

            const result = [{
                description: getLocaleSpecificMessage(Diagnostics.Change_extends_to_implements),
                changes: [{
                    fileName: sourceFile.fileName,
                    textChanges: [{ newText: " implements", span: { start: extendsNode.pos, length: extendsNode.end - extendsNode.pos } }]
                }]
            }];

            // We check if the implements keyword is present and replace it with a comma if so.
            const classDeclChildren = (token.parent.parent.parent as ClassDeclaration).getChildren();
            if (classDeclChildren.length < 3) {
                return result;
            }

            let classSyntaxListChildren: Node[];
            if (classDeclChildren[2].kind !== SyntaxKind.SyntaxList || (classSyntaxListChildren = classDeclChildren[2].getChildren()).length < 2) {
                return result;
            }

            let implementsTokenChildren: Node[];
            if ((classSyntaxListChildren[1] as HeritageClause).token !== SyntaxKind.ImplementsKeyword || (implementsTokenChildren = classSyntaxListChildren[1].getChildren()).length === 0) {
                return result;
            }

            const implementsNode = implementsTokenChildren[0];
            result[0].changes[0].textChanges.push({ newText: ",", span: { start: implementsNode.pos, length: implementsNode.end - implementsNode.pos } });

            return result;
        }
    });
}<commit_msg>Get Ancestor instead of manual walk<commit_after>/* @internal */
namespace ts.codefix {
    registerCodeFix({
        errorCodes: [Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements.code],
        getCodeActions: (context: CodeFixContext) => {
            const sourceFile = context.sourceFile;
            const start = context.span.start;
            const token = getTokenAtPosition(sourceFile, start);

            if (!(token.kind === SyntaxKind.Identifier && token.parent.parent.parent.kind === SyntaxKind.ClassDeclaration)) {
                return undefined;
            }

            const extendsNode = (token.parent.parent as HeritageClause).getChildren()[0];

            const result = [{
                description: getLocaleSpecificMessage(Diagnostics.Change_extends_to_implements),
                changes: [{
                    fileName: sourceFile.fileName,
                    textChanges: [{ newText: " implements", span: { start: extendsNode.pos, length: extendsNode.end - extendsNode.pos } }]
                }]
            }];

            // We check if the implements keyword is present and replace it with a comma if so.
            const classDeclNode = getAncestor(token, SyntaxKind.ClassDeclaration);
            if (!classDeclNode) {
                return result;
            }
            const classDeclChildren = classDeclNode.getChildren();
            if (classDeclChildren.length < 3) {
                return result;
            }

            let classSyntaxListChildren: Node[];
            if (classDeclChildren[2].kind !== SyntaxKind.SyntaxList || (classSyntaxListChildren = classDeclChildren[2].getChildren()).length < 2) {
                return result;
            }

            let implementsTokenChildren: Node[];
            if ((classSyntaxListChildren[1] as HeritageClause).token !== SyntaxKind.ImplementsKeyword || (implementsTokenChildren = classSyntaxListChildren[1].getChildren()).length === 0) {
                return result;
            }

            const implementsNode = implementsTokenChildren[0];
            result[0].changes[0].textChanges.push({ newText: ",", span: { start: implementsNode.pos, length: implementsNode.end - implementsNode.pos } });

            return result;
        }
    });
}
{'fraction_non_alphanumeric': 0.1040580367263659, 'fraction_numerical': 0.005440943096803446, 'mean_word_length': 2.2275054864667156, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4440454', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1063, 'n_words': 233}