<commit_before>'use strict';

import * as vscode from 'vscode';
import * as fs from 'fs';

var hexdump = require('hexy');
var sprintf = require('sprintf-js').sprintf;
var encoding = require('encoding');

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
    var config = vscode.workspace.getConfiguration('hexdump');
    var littleEndian = config['littleEndian'];
    var firstLine: number = config['showOffset'] ? 1 : 0;
    var hexLineLength: number = config['width'] * 2;
    var firstByteOffset: number = config['showAddress'] ? 10 : 0;
    var lastByteOffset: number = firstByteOffset + hexLineLength + hexLineLength / config['nibbles'] - 1;
    var firstAsciiOffset: number = lastByteOffset + (config['nibbles'] == 2 ? 4 : 2);
    var lastAsciiOffset: number = firstAsciiOffset + config['width'];
    var charPerLine: number = lastAsciiOffset + 1;
    var sizeWarning: number = config ['sizeWarning'];
    var maxLineCount: number = config['maxLineCount'];
    var charEncoding: string = config['charEncoding'];
    var btnEnabled: string = config['btnEnabled'];

    var statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);

    // create a decorator type that we use to mark modified bytes
    const modifiedDecorationType = vscode.window.createTextEditorDecorationType({
        backgroundColor: 'rgba(255,0,0,1)'
    });

    var smallDecorationType = vscode.window.createTextEditorDecorationType({
        borderWidth: '1px',
        borderStyle: 'solid',
        overviewRulerColor: 'blue',
        overviewRulerLane: vscode.OverviewRulerLane.Right,
        light: {
            // this color will be used in light color themes
            borderColor: 'darkblue'
        },
        dark: {
            // this color will be used in dark color themes
            borderColor: 'lightblue'
        }
    });    

    function updateStatusBar() {
        statusBarItem.text = littleEndian ? 'hex' : 'HEX';
        statusBarItem.tooltip = littleEndian ? 'Little Endian' : 'Big Endian';

        let e = vscode.window.activeTextEditor;
        // check if hexdump document
        if (e && e.document.uri.scheme === 'hexdump') {
            if (getEntry(e.document.uri).isDirty) {
                statusBarItem.text += ' (modified)';
            }
        }
    }

    function updateButton() {
        vscode.commands.executeCommand('setContext', 'hexdump:btnEnabled', btnEnabled);
    }

    function updateConfiguration() {
        config = vscode.workspace.getConfiguration('hexdump');
        littleEndian = config['littleEndian'];
        firstLine = config['showOffset'] ? 1 : 0;
        hexLineLength = config['width'] * 2;
        firstByteOffset = config['showAddress'] ? 10 : 0;
        lastByteOffset = firstByteOffset + hexLineLength + hexLineLength / config['nibbles'] - 1;
        firstAsciiOffset = lastByteOffset + (config['nibbles'] == 2 ? 4 : 2);
        lastAsciiOffset = firstAsciiOffset + config['width'];
        charPerLine = lastAsciiOffset + 1;
        sizeWarning = config ['sizeWarning'];
        maxLineCount = config['maxLineCount'];
        charEncoding = config['charEncoding'];
        btnEnabled = config['btnEnabled'];

        updateButton();
        updateStatusBar();

        for (let d of vscode.workspace.textDocuments) {
            if (d.languageId === 'hexdump') {
                provider.update(d.uri);
            }
        }
    }
    vscode.workspace.onDidChangeConfiguration(updateConfiguration);
    updateConfiguration();

    vscode.window.onDidChangeActiveTextEditor((e) => {
        if (e.document.languageId === 'hexdump') {
            statusBarItem.show();
        } else {
            statusBarItem.hide();
        }
    });

    vscode.window.onDidChangeTextEditorSelection((e) => {
        if(e.textEditor.document.languageId === 'hexdump') {
            let numLine = e.textEditor.document.lineCount
            if (e.selections[0].start.line + 1 == numLine ||
                e.selections[0].end.line + 1 == numLine) {
                e.textEditor.setDecorations(smallDecorationType, []);
                return;
            }
            let startOffset = getOffset(e.selections[0].start);
            let endOffset = getOffset(e.selections[0].end);
            if (typeof startOffset == 'undefined' ||
                typeof endOffset == 'undefined') {
                e.textEditor.setDecorations(smallDecorationType, []);
                return;
            }
            
            var ranges = getRanges(startOffset, endOffset, false);
            if (config['showAscii']) {
                ranges = ranges.concat( getRanges(startOffset, endOffset, true) );
            }
            e.textEditor.setDecorations(smallDecorationType, ranges);
        }
    });

    function getRanges(startOffset: number, endOffset: number, ascii: boolean): vscode.Range[] {
        var startPos = getPosition(startOffset, ascii);
        var endPos = getPosition(endOffset, ascii);
        endPos = new vscode.Position(endPos.line, endPos.character + (ascii ? 1 : 2));
<commit_msg>:zap: validate callback parameters<commit_after>'use strict';

import * as vscode from 'vscode';
import * as fs from 'fs';

var hexdump = require('hexy');
var sprintf = require('sprintf-js').sprintf;
var encoding = require('encoding');

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
    var config = vscode.workspace.getConfiguration('hexdump');
    var littleEndian = config['littleEndian'];
    var firstLine: number = config['showOffset'] ? 1 : 0;
    var hexLineLength: number = config['width'] * 2;
    var firstByteOffset: number = config['showAddress'] ? 10 : 0;
    var lastByteOffset: number = firstByteOffset + hexLineLength + hexLineLength / config['nibbles'] - 1;
    var firstAsciiOffset: number = lastByteOffset + (config['nibbles'] == 2 ? 4 : 2);
    var lastAsciiOffset: number = firstAsciiOffset + config['width'];
    var charPerLine: number = lastAsciiOffset + 1;
    var sizeWarning: number = config ['sizeWarning'];
    var maxLineCount: number = config['maxLineCount'];
    var charEncoding: string = config['charEncoding'];
    var btnEnabled: string = config['btnEnabled'];

    var statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);

    // create a decorator type that we use to mark modified bytes
    const modifiedDecorationType = vscode.window.createTextEditorDecorationType({
        backgroundColor: 'rgba(255,0,0,1)'
    });

    var smallDecorationType = vscode.window.createTextEditorDecorationType({
        borderWidth: '1px',
        borderStyle: 'solid',
        overviewRulerColor: 'blue',
        overviewRulerLane: vscode.OverviewRulerLane.Right,
        light: {
            // this color will be used in light color themes
            borderColor: 'darkblue'
        },
        dark: {
            // this color will be used in dark color themes
            borderColor: 'lightblue'
        }
    });    

    function updateStatusBar() {
        statusBarItem.text = littleEndian ? 'hex' : 'HEX';
        statusBarItem.tooltip = littleEndian ? 'Little Endian' : 'Big Endian';

        let e = vscode.window.activeTextEditor;
        // check if hexdump document
        if (e && e.document.uri.scheme === 'hexdump') {
            if (getEntry(e.document.uri).isDirty) {
                statusBarItem.text += ' (modified)';
            }
        }
    }

    function updateButton() {
        vscode.commands.executeCommand('setContext', 'hexdump:btnEnabled', btnEnabled);
    }

    function updateConfiguration() {
        config = vscode.workspace.getConfiguration('hexdump');
        littleEndian = config['littleEndian'];
        firstLine = config['showOffset'] ? 1 : 0;
        hexLineLength = config['width'] * 2;
        firstByteOffset = config['showAddress'] ? 10 : 0;
        lastByteOffset = firstByteOffset + hexLineLength + hexLineLength / config['nibbles'] - 1;
        firstAsciiOffset = lastByteOffset + (config['nibbles'] == 2 ? 4 : 2);
        lastAsciiOffset = firstAsciiOffset + config['width'];
        charPerLine = lastAsciiOffset + 1;
        sizeWarning = config ['sizeWarning'];
        maxLineCount = config['maxLineCount'];
        charEncoding = config['charEncoding'];
        btnEnabled = config['btnEnabled'];

        updateButton();
        updateStatusBar();

        for (let d of vscode.workspace.textDocuments) {
            if (d.languageId === 'hexdump') {
                provider.update(d.uri);
            }
        }
    }
    vscode.workspace.onDidChangeConfiguration(updateConfiguration);
    updateConfiguration();

    vscode.window.onDidChangeActiveTextEditor((e) => {
        if (e && e.document.languageId === 'hexdump') {
            statusBarItem.show();
        } else {
            statusBarItem.hide();
        }
    });

    vscode.window.onDidChangeTextEditorSelection((e) => {
        if(e && e.textEditor.document.languageId === 'hexdump') {
            let numLine = e.textEditor.document.lineCount
            if (e.selections[0].start.line + 1 == numLine ||
                e.selections[0].end.line + 1 == numLine) {
                e.textEditor.setDecorations(smallDecorationType, []);
                return;
            }
            let startOffset = getOffset(e.selections[0].start);
            let endOffset = getOffset(e.selections[0].end);
            if (typeof startOffset == 'undefined' ||
                typeof endOffset == 'undefined') {
                e.textEditor.setDecorations(smallDecorationType, []);
                return;
            }
            
            var ranges = getRanges(startOffset, endOffset, false);
            if (config['showAscii']) {
                ranges = ranges.concat( getRanges(startOffset, endOffset, true) );
            }
            e.textEditor.setDecorations(smallDecorationType, ranges);
        }
    });

    function getRanges(startOffset: number, endOffset: number, ascii: boolean): vscode.Range[] {
        var startPos = getPosition(startOffset, ascii);
        var endPos = getPosition(endOffset, ascii);
        endPos = new vscode.Position(endPos.line, endPos.character + (ascii ? 1 : 2));

{'fraction_non_alphanumeric': 0.11829909221213569, 'fraction_numerical': 0.007071189679885332, 'mean_word_length': 2.6064782908339077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2436033', 'n_tokens_mistral': 3036, 'n_tokens_neox': 2891, 'n_words': 663}