<commit_before>var vscode = require('vscode');
var sorter = require('./sort-json-utils');
var JSON5 = require('json5');

function getConfig() {
    return vscode.workspace.getConfiguration('sortJSON');
}

function getSelection(textEditor, startLine, startPos, endLine, endPos) {
    var selectedLines = [];
    var commentLines = [];
    for (var i = startLine; i <= endLine; ++i) {
        var text = textEditor.document.lineAt(i).text;

        // Slice end first so we don't mess up start position
        if (i === endLine) {
            text = text.slice(0, endPos);
        }
        if (i === startLine) {
            text = text.slice(startPos);
        }

        // Check for commented lines (and don't include them in sortable JSON)
        if ((/^\s+\/\/.*$/.test(text))) {
            // RichS: We don't do anything with these for now.
            commentLines.push(text);
            console.log("Removing comment line from sortable JSON: " + text);
        } else {
            selectedLines.push(text);
        }
    }

    return selectedLines.join('\n');
};

function findIndent(textEditor) {
    var indent;
    for (var i = 0; !indent && i < textEditor.document.lineCount; ++i) {
        var line = textEditor.document.lineAt(i).text;<commit_msg>fix jsonc comment handling (#19)<commit_after>var vscode = require('vscode');
var sorter = require('./sort-json-utils');
var JSON5 = require('json5');
var _ = require('lodash');

function getConfig() {
    return vscode.workspace.getConfiguration('sortJSON');
}

function getSelection(textEditor, startLine, startPos, endLine, endPos) {
    var selectedLines = [];
    var commentLines = [];
    for (var i = startLine; i <= endLine; ++i) {
        var text = textEditor.document.lineAt(i).text;

        // Slice end first so we don't mess up start position
        if (i === endLine) {
            text = text.slice(0, endPos);
        }
        if (i === startLine) {
            text = text.slice(startPos);
        }
        
        // Check for commented lines (and don't include them in sortable JSON)
        //JSON strings can contain anything including // so pull them out before
        //checking for endof line comments.
        var t = text.replace(/"[^"]+"/g,"\"\"");
        var a = t.match(/(\s*\/\/.*)$/);
        
        if(a != null){
            var comment, commentRegExp;
            //The match we just got is almost right but will missing anything that was in double quotes.
            //Build a unique regExp from this that can be used safely on the original text.
            commentRegexp = _.escapeRegExp(a[a.length - 1]).replace("\"\"","\"[^\"]*\"");
            
            a = text.match(commentRegexp+"$");
            comment = a[a.length - 1];
            console.log("Removing comment from sortable JSON: " + text);

            text = text.replace(comment, "");//strip the comment out
            // RichS: We don't do anything with these for now.
            commentLines.push(comment);
        }

        if(text)
            selectedLines.push(text);
    }

    return selectedLines.join('\n');
};

function findIndent(textEditor) {
    var indent;
    for (var i = 0; !indent && i < textEditor.document.lineCount; ++i) {
        var line = textEditor.document.lineAt(i).text;
{'fraction_non_alphanumeric': 0.14120511259890445, 'fraction_numerical': 0.0036518563603164943, 'mean_word_length': 2.225711481844946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2707902', 'n_tokens_mistral': 970, 'n_tokens_neox': 948, 'n_words': 281}