<commit_before>import * as CodeMirror from "codemirror";
import * as utils from "../../../common/utils";
import {server} from "../../../socket/socketClient";
import * as types from "../../../common/types";

const gutterId = "CodeMirror-git-status";
const addedClass = "git-added";
const removedClass = "git-removed";
const modifiedClass = "git-modified";

require('./gitStatus.css');
export function setupOptions(options: any, filePath: string) {
    options.gutters.unshift(gutterId);
}

enum GitDiffStatus  {
    Added,
    Removed,
    Modified
}

export function setupCM(cm: CodeMirror.EditorFromTextArea): { dispose: () => void } {
    const filePath = cm.filePath;
    let interval = null;

    // The key Git diff logic
    const gitDiffStatusMap: {
        [line: number]: GitDiffStatus
    } = Object.create(null);
    const refreshGitStatus = utils.debounce(() => {
        server.gitDiff({filePath}).then(()=>{

        });
    }, 2000);


    const handleFocus = () => {
        interval = setInterval(refreshGitStatus, 2000);
    }
    const handleBlur = () => {
        if (interval) clearInterval(interval);
        interval = null;
    }
    cm.on('focus', handleFocus);
    cm.on('blur', handleBlur);
    // Add a few other things to call refreshGitStatus so we don't call it if user is doing stuff
    cm.on('change', refreshGitStatus);
    cm.on('cursorActivity', refreshGitStatus);
    return {
        dispose: () => {
            cm.off('focus', handleFocus);<commit_msg>WIP git status. I want to go and watch a movie so parking for the night :)<commit_after>/**
 * The git status plugin
 *
 * The best demo to understand this is the marker demo:
 * https://codemirror.net/demo/marker.html
 */
import * as CodeMirror from "codemirror";
import * as utils from "../../../common/utils";
import {server} from "../../../socket/socketClient";
import * as types from "../../../common/types";

const gutterId = "CodeMirror-git-status";
const addedClass = "git-added";
const removedClass = "git-removed";
const modifiedClass = "git-modified";

require('./gitStatus.css');
export function setupOptions(options: any, filePath: string) {
    options.gutters.unshift(gutterId);
}

enum GitDiffStatus  {
    Added,
    Removed,
    Modified
}

export function setupCM(cm: CodeMirror.EditorFromTextArea): { dispose: () => void } {
    if (cm) return { dispose: () => null }; // DEBUG : while the feature isn't complete used to disable it

    const filePath = cm.filePath;
    let interval = null;

    function makeMarker(className: string) {
        var marker = document.createElement("div");
        marker.className = className;
        marker.innerHTML = "●";
        return marker;
    }

    // The key Git diff logic
    let gitDiffStatusMap: {
        [line: number]: GitDiffStatus
    } = Object.create(null);
    const refreshGitStatus = utils.debounce(() => {
        server.gitDiff({filePath}).then((res)=>{
            // Clear all old
            // TODO: don't delete if its in the new one as well and is same type
            Object.keys(gitDiffStatusMap).forEach(line => {
                cm.setGutterMarker(line, gutterId, null);
            });
            gitDiffStatusMap = Object.create(null);
            // Add new
            res.added.forEach(added => {
                for (let line = added.from; line <= added.to; line++) {
                    if (!gitDiffStatusMap[line]) {
                        cm.setGutterMarker(line, gutterId, makeMarker(addedClass));
                        gitDiffStatusMap[line] = GitDiffStatus.Added;
                    }
                }
            });
        });
    }, 2000);


    const handleFocus = () => {
        interval = setInterval(refreshGitStatus, 2000);
    }
    const handleBlur = () => {
        if (interval) clearInterval(interval);
        interval = null;
    }
    cm.on('focus', handleFocus);
    cm.on('blur', handleBlur);
    // Add a few other things to call refreshGitStatus so we don't call it if user is doing stuff
    cm.on('change', refreshGitStatus);
    cm.on('cursorActivity', refreshGitStatus);
    return {
        dispose: () => {
            cm.off('focus', handleFocus);
{'fraction_non_alphanumeric': 0.1382775119617225, 'fraction_numerical': 0.003827751196172249, 'mean_word_length': 2.50755033557047, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 18, 'https://': 1, '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': '7543155', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1177, 'n_words': 327}