<commit_before>import * as vscode from 'vscode';
var process = require("process");
var request = require("request");
var querystring = require("querystring");

export function activate(context: vscode.ExtensionContext) {
    var guides = new Guides();
    context.subscriptions.push(new GuidesController(guides));
    context.subscriptions.push(guides);
}

class GuidesController {
    private guides: Guides;
    private disposable: vscode.Disposable;
    private lastSelection: vscode.Selection;

    constructor(guides: Guides){
        this.guides = guides;
        this.guides.reset();

        let subscriptions: vscode.Disposable[] = [];
        vscode.window.onDidChangeTextEditorSelection(
            this.updateSelection, this, subscriptions
        );
        vscode.window.onDidChangeActiveTextEditor(
            this.updateActiveEditor, this, subscriptions
        );
        vscode.window.onDidChangeTextEditorOptions(
            this.updateEditorSettings, this, subscriptions
        );
        vscode.workspace.onDidChangeConfiguration(
            this.updateEditors, this, subscriptions
        );

        this.disposable = vscode.Disposable.from(...subscriptions);
    }

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

    private updateSelection(event: vscode.TextEditorSelectionChangeEvent){
        var shouldUpdate = true;
        if(event.selections.length === 1){
            var selection = event.selections[0];
            if(
                this.lastSelection &&
                selection.active.line === this.lastSelection.active.line &&
                event.textEditor.document.lineAt(
                    selection.active.line
                ).firstNonWhitespaceCharacterIndex < selection.active.character - 1
            ){
                shouldUpdate = false;
            }
            this.lastSelection = selection;
        }
        if(shouldUpdate){
            this.guides.setNeedsUpdateEditor(event.textEditor);
        }
    }

    private updateEditorSettings(event: vscode.TextEditorOptionsChangeEvent){
        this.guides.setNeedsUpdateEditor(event.textEditor);
    }

    private updateActiveEditor(editor: vscode.TextEditor){
        this.guides.setNeedsUpdateEditor(editor);
    }

    private updateEditors(){
        this.guides.reset();
    }
}
<commit_msg>Add more selection logic to reduce even more event fires<commit_after>import * as vscode from 'vscode';
var process = require("process");
var request = require("request");
var querystring = require("querystring");

export function activate(context: vscode.ExtensionContext) {
    var guides = new Guides();
    context.subscriptions.push(new GuidesController(guides));
    context.subscriptions.push(guides);
}

class GuidesController {
    private guides: Guides;
    private disposable: vscode.Disposable;
    private lastSelection: vscode.Selection;

    constructor(guides: Guides){
        this.guides = guides;
        this.guides.reset();

        let subscriptions: vscode.Disposable[] = [];
        vscode.window.onDidChangeTextEditorSelection(
            this.updateSelection, this, subscriptions
        );
        vscode.window.onDidChangeActiveTextEditor(
            this.updateActiveEditor, this, subscriptions
        );
        vscode.window.onDidChangeTextEditorOptions(
            this.updateEditorSettings, this, subscriptions
        );
        vscode.workspace.onDidChangeConfiguration(
            this.updateEditors, this, subscriptions
        );

        this.disposable = vscode.Disposable.from(...subscriptions);
    }

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

    private updateSelection(event: vscode.TextEditorSelectionChangeEvent){
        var shouldUpdate = true;
        if(event.selections.length === 1){
            var selection = event.selections[0];
            if(
                this.lastSelection &&
                ((
                    // If the cursor is on the same line and placed after the
                    //   first non-whitespace character
                    selection.active.line === this.lastSelection.active.line &&
                    event.textEditor.document.lineAt(
                        selection.active.line
                    ).firstNonWhitespaceCharacterIndex <
                    selection.active.character - 1
                ) || (
                    // If the cursor just move to the line above/below and the
                    //   first non-whitespace character position of the both
                    //   lines are the same
                    Math.abs(
                        selection.active.line - this.lastSelection.active.line
                    ) === 1 &&
                    event.textEditor.document.lineAt(
                        selection.active.line
                    ).firstNonWhitespaceCharacterIndex ===
                    event.textEditor.document.lineAt(
                        this.lastSelection.active.line
                    ).firstNonWhitespaceCharacterIndex
                ))
            ){
                shouldUpdate = false;
            }
            this.lastSelection = selection;
        }
        if(shouldUpdate){
            this.guides.setNeedsUpdateEditor(event.textEditor);
        }
    }

    private updateEditorSettings(event: vscode.TextEditorOptionsChangeEvent){
        this.guides.setNeedsUpdateEditor(event.textEditor);
    }

    private updateActiveEditor(editor: vscode.TextEditor){
        this.guides.setNeedsUpdateEditor(editor);
    }

    private updateEditors(){
        this.guides.reset();
    }
}

{'fraction_non_alphanumeric': 0.09110434938249508, 'fraction_numerical': 0.0012529085376767495, 'mean_word_length': 2.0552214324767633, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4071580', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1399, 'n_words': 258}