<commit_before>'use strict';

import {
    Disposable,
    ExtensionContext,
    Range,
    TextDocumentWillSaveEvent,
    TextEdit,
    window,
    workspace,
    WorkspaceConfiguration
} from 'vscode';

export function activate(context: ExtensionContext) {
    const config = workspace.getConfiguration('files');
    const handler = new EnsureSingleFinalNewlineHandler(config);
    context.subscriptions.push(handler);
}

class EnsureSingleFinalNewlineHandler {
    private _disposable: Disposable;
    private _config: WorkspaceConfiguration;

    constructor(config) {
        const subscriptions: Disposable[] = [];

        this._config = config;

        workspace.onWillSaveTextDocument(this._onWillSaveTextDocument, this, subscriptions);
        workspace.onDidChangeConfiguration(this._onDidChangeConfiguration, this, subscriptions);

        this._disposable = Disposable.from(...subscriptions);
    }

    dispose(){
        this._disposable.dispose();
    }

    private _onWillSaveTextDocument(event: TextDocumentWillSaveEvent) {
        if (this._config.get('insertFinalNewline', false)) {
            const doc = event.document;
            const edits = [];

            for (let index = doc.lineCount - 1; index > 0; index--) {
                const prevLine = doc.lineAt(index - 1);
                const currentLine = doc.lineAt(index);
                if (currentLine.isEmptyOrWhitespace){
                    if (prevLine.isEmptyOrWhitespace) {
                        edits.push(TextEdit.delete(new Range(index - 1, 0, index, 0)));
                    } else {
                        break;
                    }
                }
            }

            event.waitUntil(Promise.resolve(edits));
        }
    }

    private _onDidChangeConfiguration() {
        this._config = workspace.getConfiguration('files');
    }
}
<commit_msg>Stop finding empty line if final line is not empty<commit_after>'use strict';

import {
    Disposable,
    ExtensionContext,
    Range,
    TextDocumentWillSaveEvent,
    TextEdit,
    window,
    workspace,
    WorkspaceConfiguration
} from 'vscode';

export function activate(context: ExtensionContext) {
    const config = workspace.getConfiguration('files');
    const handler = new EnsureSingleFinalNewlineHandler(config);
    context.subscriptions.push(handler);
}

class EnsureSingleFinalNewlineHandler {
    private _disposable: Disposable;
    private _config: WorkspaceConfiguration;

    constructor(config) {
        const subscriptions: Disposable[] = [];

        this._config = config;

        workspace.onWillSaveTextDocument(this._onWillSaveTextDocument, this, subscriptions);
        workspace.onDidChangeConfiguration(this._onDidChangeConfiguration, this, subscriptions);

        this._disposable = Disposable.from(...subscriptions);
    }

    dispose(){
        this._disposable.dispose();
    }

    private _onWillSaveTextDocument(event: TextDocumentWillSaveEvent) {
        if (this._config.get('insertFinalNewline', false)) {
            const doc = event.document;
            const edits = [];

            for (let index = doc.lineCount - 1; index > 0; index--) {
                const prevLine = doc.lineAt(index - 1);
                const currentLine = doc.lineAt(index);
                if (currentLine.isEmptyOrWhitespace){
                    if (prevLine.isEmptyOrWhitespace) {
                        edits.push(TextEdit.delete(new Range(index - 1, 0, index, 0)));
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }

            event.waitUntil(Promise.resolve(edits));
        }
    }

    private _onDidChangeConfiguration() {
        this._config = workspace.getConfiguration('files');
    }
}

{'fraction_non_alphanumeric': 0.0962496721741411, 'fraction_numerical': 0.003147128245476003, 'mean_word_length': 2.2322033898305085, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2708614', 'n_tokens_mistral': 1029, 'n_tokens_neox': 976, 'n_words': 195}